mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import io
|
|
from github import Github
|
|
from datetime import datetime, timedelta
|
|
|
|
g = Github()
|
|
|
|
one_month_ago = datetime.now() - timedelta(days=32)
|
|
|
|
def filter_date(issue):
|
|
return issue.closed_at > one_month_ago
|
|
|
|
def format_number(number):
|
|
if number > 1000:
|
|
return u"{:.1f}k".format(float(number) / 1000)
|
|
else:
|
|
return u"{}".format(number)
|
|
|
|
with io.open("templates/auto/recent-updates.html", 'w', encoding='utf8') as recent_updates:
|
|
recent_updates.truncate()
|
|
|
|
recent_updates.write(u"<ul>\n")
|
|
|
|
issues = g.search_issues("is:merged", repo="phil-opp/blog_os", type="pr", label="relnotes")[:10]
|
|
|
|
for pr in filter(filter_date, issues):
|
|
link = '<a href="' + pr.html_url + '">' + pr.title + "</a> "
|
|
iso_date = pr.closed_at.isoformat()
|
|
readable_date = pr.closed_at.strftime("%b %d")
|
|
datetime = '<time datetime="' + iso_date + '">' + readable_date + '</time>'
|
|
recent_updates.write(u" <li>" + link + datetime + "</li>\n")
|
|
|
|
recent_updates.write(u"</ul>")
|
|
|
|
repo = g.get_repo("phil-opp/blog_os")
|
|
|
|
with io.open("templates/auto/stars.html", 'w', encoding='utf8') as stars:
|
|
stars.truncate()
|
|
stars.write(format_number(repo.stargazers_count))
|
|
|
|
with io.open("templates/auto/forks.html", 'w', encoding='utf8') as forks:
|
|
forks.truncate()
|
|
forks.write(format_number(repo.forks_count))
|