Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6feca7

Browse files
committed
update github_bot script
1 parent 7b067d2 commit c6feca7

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

script/github_bot/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
**最后**`python github_bot.py`
3333

3434
## 开发日志
35+
#### 2017-4-6
36+
1. GitHub Api 更新,event 最多获取 300 条
37+
2. 新注册帐号 521hellogithub 用于获取每天的数据
38+
3539
#### 2017-3-28
3640
增加收集项目 star 临界值
3741

script/github_bot/github_bot.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
API = {
32-
'events': 'https://api.github.com/users/{username}/received_events/public'.format(username=ACCOUNT['username'])
32+
'events': 'https://api.github.com/users/{username}/received_events'.format(username=ACCOUNT['username'])
3333
}
3434

3535
# 发送邮件,邮箱的信息
@@ -48,7 +48,7 @@
4848
DAY = 1
4949

5050
# 项目stars临界值
51-
STARS = 200
51+
STARS = 100
5252

5353
# qq邮件服务文档:http://service.mail.qq.com/cgi-bin/help?id=28
5454

@@ -59,21 +59,22 @@
5959
<th>头像</th>
6060
<th>用户名</th>
6161
<th>项目名</th>
62-
<th>starred日期</th>
63-
<th>项目star数量</th>
62+
<th>starred 日期</th>
63+
<th>项目 star 数量</th>
6464
</tr>
6565
{project_info_string}
6666
</table>
6767
"""
6868

6969

70-
def get_data(page=1, per_page=100):
70+
def get_data(page=1):
7171
"""
7272
从目标源获取数据
73+
https://developer.github.com/v3/activity/events/
74+
GitHub 规定:默认每页 30 条,最多 300 条目
7375
"""
7476

75-
args = '?page={page}&per_page={per_page}'.format(
76-
page=page, per_page=per_page)
77+
args = '?page={page}'.format(page=page)
7778

7879
response = requests.get(API['events']+args,
7980
auth=(ACCOUNT['username'], ACCOUNT['password']))
@@ -82,8 +83,22 @@ def get_data(page=1, per_page=100):
8283
resp_json = response.json()
8384
return resp_json
8485
else:
85-
logging.error('请求api失败:', status_code)
86-
return None
86+
logging.error('请求 event api 失败:', status_code)
87+
return []
88+
89+
90+
def get_all_data():
91+
"""
92+
获取全部 300 条的数据
93+
https://developer.github.com/v3/activity/events/
94+
GitHub 规定:默认每页 30 条,最多 300 条目
95+
"""
96+
all_data_list = []
97+
for i in range(10):
98+
response_json = get_data(i+1)
99+
if response_json:
100+
all_data_list.extend(response_json)
101+
return all_data_list
87102

88103

89104
def check_condition(data):
@@ -151,7 +166,7 @@ def make_content():
151166
"""
152167
生成发布邮件的内容
153168
"""
154-
json_data = get_data()
169+
json_data = get_all_data()
155170
data = analyze(json_data)
156171
content = []
157172
project_info_list = get_stars(data)
@@ -180,10 +195,10 @@ def send_email(receivers, email_content):
180195
CONTENT_FORMAT.format(project_info_string=''.join(email_content)),
181196
'html', 'utf-8'
182197
)
183-
message['From'] = Header(u'Github机器人', 'utf-8')
198+
message['From'] = Header(u'GitHub 机器人', 'utf-8')
184199
message['To'] = Header(u'削微寒', 'utf-8')
185200

186-
subject = u'今日Github热点' # 设置邮件主题
201+
subject = u'今日 GitHub 热点' # 设置邮件主题
187202
message['Subject'] = Header(subject, 'utf-8')
188203
try:
189204
smtp_obj = smtplib.SMTP_SSL() # qq邮箱要求是https连接,所以需要用SMTP_SSL

0 commit comments

Comments
 (0)