Created
August 12, 2012 04:25
-
-
Save bheesham/3329723 to your computer and use it in GitHub Desktop.
Downloads the latest version of MineCraft.
This file contains 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
""" | |
Downloads the latest snapshot of MineCraft | |
@version 1.0.0 | |
@author Bheesham Persaud <http://bheesham.com/ | |
@license Beerware <http://wikipedia.org/wiki/Beerware> | |
""" | |
import os | |
import requests | |
import re | |
from BeautifulSoup import BeautifulStoneSoup | |
def main(): | |
"First, get the version of the one that we have." | |
mc_version = get_version() | |
assets_page = "http://assets.minecraft.net/" | |
"Second, load the page, and proceed to find the latest one." | |
try: | |
listings_page = requests.get(assets_page) | |
except requests.exceptions.RequestException as e: | |
print "Could not load to that page." | |
exit(1) | |
reg_exp = re.compile("((\d+)w(\d+)a\/minecraft\.jar)") | |
xml = listings_page.content.lower() | |
versions = reg_exp.findall(xml) | |
current_version = "%dw%da" % (int(versions[-1][1]), int(versions[-1][2])) | |
if current_version != mc_version: | |
newest = requests.get(assets_page + versions[-1][0]) | |
save(newest.content) | |
save_version(current_version) | |
print "Downloading the latest version (%s)." % current_version | |
print "Got the newest version (%s)!" % current_version | |
else: | |
print "You already had the latest version." | |
exit(0) | |
def save_version(version): | |
handle = open("version", "wb") | |
handle.write(version) | |
handle.close() | |
def get_version(): | |
"If it doesn't exist, then create it." | |
if os.path.exists("version") == False: | |
handle = open("version", "wb") | |
handle.write("0") | |
handle.close() | |
handle = open("version", "rb") | |
return handle.read() | |
def save(contents): | |
"""Save contents to minecraft.jar""" | |
handle = open("minecraft.jar", "wb") | |
handle.write(contents) | |
handle.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment