MCPcopy Create free account
hub / github.com/SnailDev/github-hot-hub / GitHub

Class GitHub

github.py:42–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42class GitHub:
43
44 def get_trending_repository(self, since: Since = Since.daily):
45 """热门仓库
46 {'href': href, 'url': url, 'description': desc, 'language': language,
47 'stars': stars, 'folks': folks, 'recent_stars': recent_stars}
48 """
49 items = []
50 resp = None
51 try:
52 with request_session() as s:
53 params = {'since': since.value}
54 resp = s.get(TRENDING_REPOSITORY_URL, params=params)
55 soup = BeautifulSoup(resp.text, features='html.parser')
56 articles = soup.select('main article.Box-row')
57 for article in articles:
58 href = article.select_one('h2.h3 > a')['href']
59 url = 'https://github.com' + href
60 logger.info('%s %s', since, href)
61
62 # 项目描述
63 description = '无'
64 desc = article.select_one('article > p')
65 if desc:
66 description = desc.text.strip()
67
68 div = article.select_one('div.f6')
69 spans = div.select('div > span')
70 # 并非每个仓库都有语言标签
71 language = '无'
72 if len(spans) == 3:
73 language = spans[0].text.strip()
74 # 最近关注数
75 recent_stars = spans[-1].text.strip()
76
77 star_folk = div.select('a')
78 stars = star_folk[0].text.strip()
79 folks = star_folk[1].text.strip()
80
81 item = {'href': href, 'url': url, 'description': description, 'language': language,
82 'stars': stars, 'folks': folks, 'recent_stars': recent_stars}
83 logger.debug('repo:%s', item)
84 items.append(item)
85 except:
86 logger.exception('get trending repository failed')
87
88 return (items, resp)
89
90 def get_trending_developer(self):
91 """热门话题
92 """
93 items = []
94 resp = None
95 try:
96 with request_session() as s:
97 resp = s.get(TRENDING_DEVELOPER_URL)
98 soup = BeautifulSoup(resp.text)
99 except:

Callers 2

runFunction · 0.90
github.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected