Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get Last update and notify to line channel
#!/usr/bin/env python
import requests
import datetime
import pickle
import github3
import humanize
import pytz
local_tz = pytz.timezone('Asia/Seoul')
auth_token = ''
# humanize.naturaltime
# get difference
def post_to_channel(message):
requests.post("https://notify-api.line.me/api/notify", data={"message": message},
headers={"Authorization": "Bearer " + auth_token})
def get_diff_human(last_update):
now = datetime.datetime.now(local_tz)
delta = now - last_update
return humanize.naturaltime(delta)
def get_repo_last_update_dt(owner, repo):
repo = github3.repository(owner, repo)
return repo.updated_at.astimezone(local_tz)
def main():
members = (
('cjh5414', 'cjh5414.github.io',),
('hyesun03', 'hyesun03.github.io',),
('guswnsxodlf', 'guswnsxodlf.github.io',),
)
reports = []
for owner, repo in members:
last_update = get_repo_last_update_dt(owner, repo)
diff_human = get_diff_human(last_update)
reports.append('%s : %s ( %s )' % (owner, diff_human, repo))
post_to_channel('\nBlog Repo Last Update\n' + '\n'.join(reports))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.