Created
October 1, 2016 00:24
-
-
Save darjeeling/eaf2bd8986e6dfda416b8ca0e8f62081 to your computer and use it in GitHub Desktop.
get Last update and notify to line channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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