Skip to content

Instantly share code, notes, and snippets.

Last active Jun 1, 2019
What would you like to do?
(python3 script)
from urllib.request import urlopen
from urllib.parse import urlencode
import json
# get a client_id and client_secret from Github -> Settings -> Developer -> Register New Oauth
# then use those and the below curl command to get an access_token
# curl -X POST --data '{"note": "Updater", "client_id": "XXX", "client_secret": "XXX"}' -u USERNAME --header "X-GitHub-OTP: 2FACODE"
REPO = ""
def github_check(url, repo_version, name):
authenticated_url = "%s?access_token=%s" % (url, ACCESS_TOKEN)
response = urlopen(authenticated_url).read()
except Exception as e:
print("ISSUE: fetching %s (%s)" % (url, e))
return False
releases = json.loads(response)
last_release = None
last_published = None
if len(releases) == 0:
# no releases made
return False
for release in releases:
current_published = release["published_at"]
if not last_published or current_published > last_published:
# current relesae's publish date is more recent
last_release = release
last_published = current_published
# get the version, strip, and compare to our cache from the repo
github_version = last_release["tag_name"].lower().strip("v")
github_version = github_version.split(" ")[0].replace(name.lower(), "").replace("switch", "").strip("-")
if github_version != repo_version.split(" ")[0].lower():
# version mismatch, something may be out of date
return github_version
# version matched
return False
if __name__ == "__main__":
# get info about the version of every package from the repo
response = urlopen("%srepo.json" % REPO)
contents ="utf-8")
packages = json.loads(contents)["packages"]
for package in packages:
if "version" in package and "url" in package and "name" in package:
repo_version = package["version"].lower().strip("v")
# get the url, if it's a github link, convert it to an api link
url = package["url"]
if "" in url and not "gist" in url:
components = url.split("/")
username = components[3]
project = components[4]
api_url = "" % (username, project)
name = package["name"]
result = github_check(api_url, repo_version, name)
if result:
print("[%s] may be out of date (ours is %s, github's is %s)" % (name, repo_version, result))
# fetch("")
# fetch("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment