Skip to content

Instantly share code, notes, and snippets.

@admiral0
Last active August 29, 2015 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save admiral0/d214334cdc6387934cff to your computer and use it in GitHub Desktop.
Save admiral0/d214334cdc6387934cff to your computer and use it in GitHub Desktop.
Scavallator 9000
#!/usr/bin/env python3
import json
import sys
import zipfile
import glob
from os import path
import os
import re
import traceback
from robobrowser import RoboBrowser
modFP = open("mod.json", "r")
modInfo = json.load(modFP)
modFP.close()
if "curseforge" not in modInfo["url"]:
print("Url is not on curseforge")
sys.exit(1)
browser = RoboBrowser(history=True)
browser.open(modInfo["url"] + "/files")
nextPage = True
while nextPage:
print("Next page!")
files = browser.select("tr.project-file-list-item")
for file in files:
nameLink = file.select(".project-file-name-container > a")[0]
downloadLink = file.select(".project-file-download-button > a")[0]
if not path.exists(nameLink.text):
print("Downloading " + nameLink.text + "...")
browser.follow_link(downloadLink)
if not browser.response.headers["Content-Type"] == "text/html":
f = open(re.sub(r"^(.+?)\.?(zip|jar)?$", r'\1.jar', nameLink.text), "wb")
f.write(browser.response.content)
else:
print("Download error.")
browser.back()
links = browser.select("li.b-pagination-item > a[rel=\"next\"]")
nextPage = len(links) > 0
if nextPage:
browser.follow_link(links[0])
modInfo['versions'] = {}
for file in glob.glob("*.jar"):
with zipfile.ZipFile(file) as mod:
try:
with mod.open("mcmod.info") as mcmod:
info = json.loads(mcmod.read().decode('utf-8'))[0]
modInfo['versions'][info['version']] = {}
modInfo['versions'][info['version']]['file'] = file
modInfo['versions'][info['version']]['minecraft'] = [info['mcversion']]
except Exception: # MEH
try:
with mod.open("cccmod.info") as mcmod:
info = json.loads(mcmod.read().decode('utf-8').replace("\n",""))[0]
modInfo['versions'][info['version']] = {}
modInfo['versions'][info['version']]['file'] = file
modInfo['versions'][info['version']]['minecraft'] = [info['mcversion']]
except Exception: # MEH
try:
with mod.open("neimod.info") as mcmod:
info = json.loads(mcmod.read().decode('utf-8').replace("\n",""))[0]
modInfo['versions'][info['version']] = {}
modInfo['versions'][info['version']]['file'] = file
modInfo['versions'][info['version']]['minecraft'] = [info['mcversion']]
except Exception: # MEH
err=traceback.format_exc()
print("Error on file " + file)
#print(err)
with open("mod.json", "w") as fp:
json.dump(modInfo, fp, sort_keys=True, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment