Skip to content

Instantly share code, notes, and snippets.

@darjeeling
Created October 1, 2016 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darjeeling/eaf2bd8986e6dfda416b8ca0e8f62081 to your computer and use it in GitHub Desktop.
Save darjeeling/eaf2bd8986e6dfda416b8ca0e8f62081 to your computer and use it in GitHub Desktop.
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