-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
117 lines (91 loc) · 3.42 KB
/
Copy pathmain.py
File metadata and controls
117 lines (91 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import logging
import os
import util
from github import GitHub, Since
from util import logger
def generateArchiveMd(daily, weekly, monthly):
"""生成归档readme
"""
def li(item):
href = item['href']
url = item['url']
description = item['description']
language = item['language']
stars = item['stars']
folks = item['folks']
recent_stars = item['recent_stars']
title = href[1:].replace('/', ' / ')
return '1. [{}]({})\n - {}\n - language: **{}** stars: **{}** folks: **{}** `{}`\n'.format(title, url, description, language, stars, folks, recent_stars)
dailyMd = '暂无数据'
if daily:
dailyMd = '\n'.join([li(item) for item in daily])
weeklyMd = '暂无数据'
if weekly:
weeklyMd = '\n'.join([li(item) for item in weekly])
monthlyMd = '暂无数据'
if monthly:
monthlyMd = '\n'.join([li(item) for item in monthly])
readme = ''
file = os.path.join('template', 'archive.md')
with open(file) as f:
readme = f.read()
readme = readme.replace("{updateTime}", util.current_time())
readme = readme.replace("{dailyRepositories}", dailyMd)
readme = readme.replace("{weeklyRepositories}", weeklyMd)
readme = readme.replace("{monthlyRepositories}", monthlyMd)
return readme
def generateReadme(daily, weekly, monthly):
"""生成今日readme
"""
def li(item):
href = item['href']
url = item['url']
description = item['description']
language = item['language']
stars = item['stars']
folks = item['folks']
recent_stars = item['recent_stars']
title = href[1:].replace('/', ' / ')
return '1. [{}]({})\n - {}\n - language: **{}** stars: **{}** folks: **{}** `{}`\n'.format(title, url, description, language, stars, folks, recent_stars)
dailyMd = '暂无数据'
if daily:
dailyMd = '\n'.join([li(item) for item in daily])
weeklyMd = '暂无数据'
if weekly:
weeklyMd = '\n'.join([li(item) for item in weekly])
monthlyMd = '暂无数据'
if monthly:
monthlyMd = '\n'.join([li(item) for item in monthly])
readme = ''
file = os.path.join('template', 'README.md')
with open(file) as f:
readme = f.read()
readme = readme.replace("{updateTime}", util.current_time())
readme = readme.replace("{dailyRepositories}", dailyMd)
readme = readme.replace("{weeklyRepositories}", weeklyMd)
readme = readme.replace("{monthlyRepositories}", monthlyMd)
return readme
def handleReadme(md):
logger.debug('today md:%s', md)
util.write_text('README.md', md)
def handleArchiveMd(md):
logger.debug('archive md:%s', md)
name = '{}.md'.format(util.current_date())
file = os.path.join('archives', name)
util.write_text(file, md)
def run():
github = GitHub()
# 今日趋势
daily, resp = github.get_trending_repository(Since.daily)
# 最近一周趋势
weekly, resp = github.get_trending_repository(Since.weekly)
# 最近一个月趋势
monthly, resp = github.get_trending_repository(Since.monthly)
# 最新数据
readme = generateReadme(daily, weekly, monthly)
handleReadme(readme)
# 归档
archiveMd = generateArchiveMd(daily, weekly, monthly)
handleArchiveMd(archiveMd)
if __name__ == "__main__":
run()