Skip to content

Instantly share code, notes, and snippets.

@aperson
Last active December 11, 2015 01:48
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 aperson/4525857 to your computer and use it in GitHub Desktop.
Save aperson/4525857 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from urllib.request import urlopen
import xml.etree.ElementTree as etree
import re
import json
def get_snapshot():
NS = '{http://s3.amazonaws.com/doc/2006-03-01/}'
with urlopen('http://assets.minecraft.net/') as w:
feed = etree.parse(w)
root = feed.getroot()
snapshots = []
for x in root.getiterator('{}Contents'.format(NS)):
key = x.find('{}Key'.format(NS)).text
lastmodified = x.find('{}LastModified'.format(NS)).text
snapshots.append((key, lastmodified))
snapshots.sort(key=lambda x: x[1], reverse=True)
for x, _ in snapshots:
x = x.split('/')[0]
if re.search(r'''[0-9]{1,2}w[0-9]{2}[a-z]{1}?|[0-9]{1,2}_[0-9]{1}(?:-pre[0-9]{0,2})?''', x):
return(x.replace('_', '.'))
def get_stable():
with urlopen('http://mcupdate.tumblr.com/rss') as w:
feed = etree.parse(w)
titles = [i.text for i in feed.findall('.//title')]
for i in titles:
stable = re.findall(r'''Minecraft ((?:[0-9]\.?){2,3})''', i, re.I)
if stable:
return stable[0]
def main():
output = {'Stable': get_stable(), 'Snapshot': get_snapshot()}
print(json.dumps(output))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment