created scripts

This commit is contained in:
Samuel Walker 2024-06-19 21:10:32 -06:00
parent eb88fec7af
commit ae392a7f64
2 changed files with 78 additions and 0 deletions

51
Main.py Normal file
View File

@ -0,0 +1,51 @@
# Windows path: os.getenv('LOCALAPPDATA')/Programs/PrismLauncher/prismlauncher.exe
# Windows instance path: os.getenv('APPDATA')/PrismLauncher/instances
# Linux instance path: .local/share/PrismLauncher/instances
from ftplib import FTP
import os
import io
import json
import tempfile
import subprocess
def main():
instance_name = "Familycraft Season 7"
prism_command = "prismlauncher"
prism_instance_path = os.getenv("HOME")+"/.local/share/PrismLauncher/instances"
if os.name == 'nt':
prism_command = os.getenv('LOCALAPPDATA')+"/Programs/PrismLauncher/prismlauncher.exe"
prism_instance_path = os.getenv("APPDATA")+"/PrismLauncher/instances"
ftp = FTP("gitea.piwalker.net")
ftp.login()
bio = io.BytesIO()
ftp.retrbinary("RETR versions.json", bio.write)
bio.seek(0)
versions = json.load(bio)
bio.close()
version = "0.0.0"
if os.path.exists(prism_instance_path+"/"+instance_name+"/version.txt"):
with open(prism_instance_path+"/"+instance_name+"/version.txt", 'r') as fp:
version = fp.readline()
if version != versions[len(versions)-1]["Version"]:
#version = versions[len(versions)-1]["Version"]
# Update Modpack
with tempfile.TemporaryDirectory() as temp_dir:
modpack = open(os.path.join(temp_dir, instance_name+".mrpack"), 'wb')
ftp.retrbinary("RETR "+versions[len(versions)-1]["File"], modpack.write)
modpack.close()
subprocess.run([prism_command, '-I', modpack.name])
#with open(prism_instance_path+"/"+instance_name+"/version.txt", 'w') as fp:
# fp.seek(0)
# fp.truncate()
# fp.write(version)
subprocess.run([prism_command, '-l', instance_name])
if __name__ == "__main__":
main();

27
Upload.py Normal file
View File

@ -0,0 +1,27 @@
from ftplib import FTP
from getpass import getpass
import json
import io
import datetime
fileName = "modpack.mrpack"
username = input("Username: ")
password = getpass()
version_tag = input("Version Number: ")
ftp = FTP("gitea.piwalker.net", username, password)
bio = io.BytesIO()
ftp.retrbinary("RETR versions.json", bio.write)
bio.seek(0)
versions = json.load(bio)
bio.close()
time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
versions.append({"Version":version_tag, "Date":time, "File":"Versions/fcs7-"+time+".mrpack"})
with open(fileName, 'rb') as fp:
ftp.storbinary("STOR "+versions[len(versions)-1]["File"], fp)
bio = io.BytesIO()
bio.write(json.dumps(versions).encode())
bio.seek(0)
ftp.storbinary("STOR versions.json", bio)
bio.close()
ftp.close()