-
-
Save goofwear/b57f2006d9776f3f0e37eb25c7478de4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import argparse | |
import io | |
import os | |
import string | |
import sys | |
import tempfile | |
import zipfile | |
import bs4 # pip install bs4 | |
import requests # pip install requests | |
import uncompyle6 # pip install uncompyle6 | |
BMDURL = "https://basementalcc.com/download/" | |
MCURL = "https://deaderpoolmc.tumblr.com/tagged/mcccrelease" | |
WWURL = "http://wickedwhims.tumblr.com/tagged/Download" | |
PATCHURL = "https://help.ea.com/en-us/help/the-sims/the-sims-4/the-sims-4-updates/" | |
TS4FOLDER = os.path.join(os.path.expanduser("~"), "Documents", "Electronic Arts", "The Sims 4") | |
def get_mod_packages(filtername): | |
rootmod = os.path.join(TS4FOLDER, "Mods") | |
results = [] | |
for root, dirs, files in os.walk(rootmod): | |
for filex in files: | |
if filex.endswith(filtername): | |
results.append(os.path.join(root, filex)) | |
return results | |
def generic_package_cracker(packname, pyoname): | |
gpacks = get_mod_packages(packname) | |
if not gpacks: | |
return None | |
elif len(gpacks) > 1: | |
raise SystemExit("MORE THAN ONE COPY OF {0} FOUND!".format(packname)) | |
else: | |
with tempfile.TemporaryDirectory() as tmpdirname: | |
zipf = zipfile.ZipFile(gpacks[0]) | |
with zipf.open(pyoname) as gvp: | |
with open(os.path.join(tmpdirname, "tempfile.pyc"), "wb") as gtfile: | |
gtfile.write(gvp.read()) | |
with io.StringIO() as dummy: | |
decomp = uncompyle6.decompile_file(os.path.join(tmpdirname, "tempfile.pyc"), dummy)[0] | |
return decomp.text | |
def get_local_mccc(): | |
dtext = generic_package_cracker("mc_cmd_center.ts4script", "mc_cmd_version.pyo") | |
if dtext is None: | |
mcversion = "Not installed" | |
else: | |
mcversion = dtext.split("\n")[0].split(" = '")[-1].replace("'", "") | |
return mcversion | |
def get_local_basemental(): | |
dtext = generic_package_cracker("basementaldrugs.ts4script", "bmdversion.pyo") | |
if dtext is None: | |
bmversion = "Not installed" | |
else: | |
bmversion = [txt for txt in dtext.split("\n") if txt][-1].split(": v")[-1].split("'")[0] | |
return bmversion | |
def get_local_wwhims(): | |
dtext = generic_package_cracker("TURBODRIVER_WickedWhims_Scripts.ts4script", "wickedwhims/version_registry.pyo") | |
if dtext is None: | |
wwversion = "Not installed" | |
else: | |
dct = dtext.split("\n")[0:5] | |
wwbase = ".".join([field.split(" = ")[-1] for field in dct[0:4]]) | |
wwhotfix = string.ascii_lowercase[int(dct[4].split(" = ")[-1]) - 1] | |
wwversion = "{0}{1}".format(wwbase, wwhotfix) | |
return wwversion | |
def get_local_game_version(): | |
gvt = os.path.join(TS4FOLDER, "GameVersion.txt") | |
with open(gvt, "r") as afile: | |
gvtraw = afile.read() | |
gvtclean = gvtraw.split("\x00")[-1] | |
return gvtclean | |
def clean_latest_version(inver): | |
inver2 = inver.split("-")[1].strip() | |
stripvers = [ver.strip() for ver in inver2.split("/")] | |
splitvers = [sver.split(" ") for sver in stripvers] | |
pcver = splitvers[0][1] | |
macver = splitvers[1][1] | |
return pcver, macver | |
def get_latest_versions(): | |
req = requests.get(PATCHURL) | |
soup = bs4.BeautifulSoup(req.text, "html.parser") | |
h4s = soup.find_all("h4") | |
latest = h4s[0].text | |
pcver, macver = clean_latest_version(latest) | |
verdict = {"Windows": pcver, "Mac": macver} | |
return verdict | |
def get_latest_basemental(): | |
req = requests.get(BMDURL) | |
soup = bs4.BeautifulSoup(req.text, "html.parser") | |
plist = soup.find_all("p", {"style": "text-align: center;"}) | |
latest = plist[0].text.replace("DOWNLOAD VERSION ", "") | |
return latest | |
def get_latest_mccc(): | |
req = requests.get(MCURL) | |
soup = bs4.BeautifulSoup(req.text, "html.parser") | |
latestp = soup.find_all("p")[0].text | |
finalver = latestp.strip().split("\n")[0].split(" is ")[-1].rstrip(".") | |
return finalver | |
def get_latest_wwhims(): | |
req = requests.get(WWURL) | |
soup = bs4.BeautifulSoup(req.text, "html.parser") | |
latesth = soup.find_all("h2")[0].text | |
finalver = latesth.replace("WickedWhims ", "") | |
return finalver | |
def current_versions(): | |
vcurrent = get_local_game_version() | |
mcurrent = get_local_mccc() | |
bcurrent = get_local_basemental() | |
wcurrent = get_local_wwhims() | |
curdict = {} | |
curdict["The Sims 4"] = vcurrent | |
curdict["MC Command Center"] = mcurrent | |
curdict["Basemental Drugs"] = bcurrent | |
curdict["Wicked Whims"] = wcurrent | |
return curdict | |
def latest_versions_remote(): | |
vlatest = get_latest_versions() | |
mlatest = get_latest_mccc() | |
blatest = get_latest_basemental() | |
wlatest = get_latest_wwhims() | |
latdict = {} | |
latdict["The Sims 4"] = "{0} (Windows)/{1} (Mac)".format(vlatest["Windows"], vlatest["Mac"]) | |
latdict["MC Command Center"] = mlatest | |
latdict["Basemental Drugs"] = blatest | |
latdict["Wicked Whims"] = wlatest | |
return latdict | |
def main(llatest=False): | |
latdict = latest_versions_remote() | |
if llatest: | |
curdict = current_versions() | |
print("LATEST PUBLIC VERSIONS") | |
print("~"*32) | |
for key, val in latdict.items(): | |
print("{0}: {1}".format(key, val)) | |
if llatest: | |
print("\tYour version: {0}".format(curdict[key])) | |
def handle_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-u", "--update-check", dest="llatest", help="check if local game/mods are up to date", action="store_true", default=False) | |
parser.set_defaults() | |
args = parser.parse_args(sys.argv[1:]) | |
main(args.llatest) | |
if __name__ == "__main__": | |
handle_args() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment