MCPcopy Index your code
hub / github.com/EvanLi/Github-Ranking / get_graphql_data

Function get_graphql_data

source/common.py:62–87  ·  view source on GitHub ↗

use graphql to get data

(GQL)

Source from the content-addressed store, hash-verified

60
61
62def get_graphql_data(GQL):
63 """
64 use graphql to get data
65 """
66 access_token = get_access_token()
67 headers = {
68 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36',
69 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
70 'Accept-Language': 'zh-CN,zh;q=0.9',
71 'Authorization': 'bearer {}'.format(access_token),
72 }
73 s = requests.session()
74 s.keep_alive = False # don't keep the session
75 graphql_api = "https://api.github.com/graphql"
76 for _ in range(5):
77 time.sleep(2) # not get so fast
78 try:
79 # requests.packages.urllib3.disable_warnings() # disable InsecureRequestWarning of verify=False,
80 r = requests.post(url=graphql_api, json={"query": GQL}, headers=headers, timeout=30)
81 if r.status_code != 200:
82 print(f'Can not retrieve from {GQL}. Response status is {r.status_code}, content is {r.content}.')
83 else:
84 return r.json()
85 except Exception as e:
86 print(e)
87 time.sleep(5)

Callers 1

get_reposMethod · 0.90

Calls 1

get_access_tokenFunction · 0.85

Tested by

no test coverage detected