Skip to content

Instantly share code, notes, and snippets.

@vgmoose
Last active June 1, 2019 12:29
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 vgmoose/9419ce64c75460faf9d5641b540f3ee3 to your computer and use it in GitHub Desktop.
Save vgmoose/9419ce64c75460faf9d5641b540f3ee3 to your computer and use it in GitHub Desktop.
(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 https://api.github.com/authorizations --data '{"note": "Updater", "client_id": "XXX", "client_secret": "XXX"}' -u USERNAME --header "X-GitHub-OTP: 2FACODE"
ACCESS_TOKEN = "XXXX"
REPO = "https://switchbru.com/appstore/"
def github_check(url, repo_version, name):
authenticated_url = "%s?access_token=%s" % (url, ACCESS_TOKEN)
try:
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 = response.read().decode("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 "github.com" in url and not "gist" in url:
components = url.split("/")
username = components[3]
project = components[4]
api_url = "https://api.github.com/repos/%s/%s/releases" % (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("https://api.github.com/repos/vgmoose/spacenx/releases")
# fetch("https://api.github.com/user")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment