MCPcopy Create free account
hub / github.com/datehoer/hotToday / get_github_data

Function get_github_data

githubspider/github.py:5–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3from urllib.parse import urljoin
4
5def get_github_data():
6 url = "https://github.com/trending"
7 headers = {
8 "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
9 "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
10 "cache-control": "no-cache",
11 "pragma": "no-cache",
12 "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
13 "sec-ch-ua-mobile": "?0",
14 "sec-ch-ua-platform": "\"Windows\"",
15 "sec-fetch-dest": "document",
16 "sec-fetch-mode": "navigate",
17 "sec-fetch-site": "same-origin",
18 "sec-fetch-user": "?1",
19 "upgrade-insecure-requests": "1",
20 }
21 response = requests.get(url, headers=headers, timeout=30)
22 doc = pyquery.PyQuery(response.text)
23 data = []
24
25 items = doc("div>article").items()
26 for item in items:
27 title = item.find("h2 a").text().split("/")[-1].strip()
28 link = urljoin(url, item.find("h2 a").attr("href"))
29 hotScore = item.find("h2~div>a").text().split(" ")[0].replace(',', '')
30 data.append({
31 "title": title,
32 "url": link,
33 "hotScore": hotScore
34 })
35 return {"data":data}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected