added post_pack() to master

This commit is contained in:
iou1name 2019-06-02 18:56:52 -04:00
parent 508b2781f1
commit 7ac8c364d1
2 changed files with 37 additions and 2 deletions

View File

@ -4,6 +4,10 @@ Configuration settings for overwrought_master.py.
`mc_ver` is used literally when searching for an appropriate verison of `mc_ver` is used literally when searching for an appropriate verison of
a mod to download. Should not include the minor version. a mod to download. Should not include the minor version.
`modpack_name` is used for vanity purposes when naming the modpack. `modpack_name` is used for vanity purposes when naming the modpack.
`password` is the password used for uploading to the remote server.
`remote_addr` is the address of the remote Overwrought server.
""" """
mc_ver = "1.12" mc_ver = "1.12"
modpack_name = "motherlode1" modpack_name = "motherlode1"
password = r"""PASSWORD"""
remote_addr = "https://stream.steelbea.me/overwrought"

View File

@ -4,7 +4,6 @@ A script for updating mods in a minecraft modpack.
""" """
import os import os
import re import re
import json
import sqlite3 import sqlite3
from datetime import datetime from datetime import datetime
@ -241,6 +240,36 @@ def generate_summary():
file.write(html) file.write(html)
def post_pack():
"""
Uploads the modpack to the remote server.
"""
data = {'password': config_master.password}
mods = get_all_mods()
res = requests.get(config_master.remote_addr + '/get')
res.raise_for_status()
mods_remote = res.json()
mods = [mod for mod in mods if mod.filename not in mods_remote]
files = {}
for mod in mods:
files[mod.filename] = open(os.path.join('mods', mod.filename), 'rb')
files[config_master.modpack_name + '.html'] = open(
config_master.modpack_name, 'rb')
res = requests.post(
url=config_master.remote_addr + '/post',
data=data,
files=files
)
res.raise_for_status()
for file in files.values():
file.close()
print('Success!')
if __name__ == "__main__": if __name__ == "__main__":
import argparse import argparse
@ -250,7 +279,7 @@ if __name__ == "__main__":
) )
parser.add_argument( parser.add_argument(
"action", "action",
choices=["add", "add_all", "update", "update_all", "summary"], choices=["add", "add_all", "update", "update_all", "summary", "post"],
help="What action to perform.", help="What action to perform.",
) )
parser.add_argument( parser.add_argument(
@ -284,3 +313,5 @@ if __name__ == "__main__":
update_mod_all(args.delete) update_mod_all(args.delete)
elif args.action == "summary": elif args.action == "summary":
generate_summary() generate_summary()
elif args.action == "post":
post_pack()