Created
February 13, 2018 00:01
-
-
Save karlcow/92347ffc71e5b59ba21cb3e061a76e59 to your computer and use it in GitHub Desktop.
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 python3 | |
# encoding: utf-8 | |
""" | |
Monitor the needsdiagnosis milestones. | |
Created by Karl Dubost - 2018-02-18 | |
""" | |
import datetime | |
import json | |
import sys | |
from urllib.parse import urljoin | |
from urllib.request import Request | |
from urllib.request import urlopen | |
# Config | |
URL_REPO = 'https://api.github.com/repos/webcompat/web-bugs/' | |
NEEDSDIAGNOSIS = 'milestones/3' | |
FILEPATH = '/Users/karl/Documents/2018/milestones/needsdiagnosis.txt' | |
def get_remote_file(url): | |
"""Request URL.""" | |
req = Request(url) | |
req.add_header('User-agent', 'webcompatMonitor') | |
req.add_header('Accept', 'application/vnd.github.v3+json') | |
json_response = urlopen(req, timeout=240) | |
return json_response | |
def extract_open_issues(json_response): | |
"""Extract the number of open issues.""" | |
json_data = json.load(json_response) | |
return json_data["open_issues"] | |
def main(): | |
"""Core program.""" | |
url = urljoin(URL_REPO, NEEDSDIAGNOSIS) | |
json_response = get_remote_file(url) | |
open_issues = extract_open_issues(json_response) | |
now = datetime.datetime.now().isoformat(timespec='seconds') | |
data = '{now} {open_issues}'.format(now=now, open_issues=open_issues) | |
with open(FILEPATH, 'a') as f: | |
f.write('{data}\n'.format(data=data)) | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment