From 34d686f7f5dd4d68b78a66aaac2063974bc8cee7 Mon Sep 17 00:00:00 2001 From: iou1name Date: Sat, 3 Aug 2019 19:13:15 -0400 Subject: [PATCH] updated master script to match curseforges new site --- overwrought_master.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/overwrought_master.py b/overwrought_master.py index b8a66f5..40e77a2 100755 --- a/overwrought_master.py +++ b/overwrought_master.py @@ -102,7 +102,7 @@ def scrape_curse_forge(url, phase=None): files = bar.contents[bar.contents.index(h)+2].find_all("li") if phase: for li in files: - if li.div.div.get("title") == phase: + if li.div.div.span.get("title") == phase: break else: print("No valid files for this release phase found.") @@ -110,12 +110,12 @@ def scrape_curse_forge(url, phase=None): else: li = files[0] - mod.title = re.search(r"-(.*?)- Mods", soup.title.text).group(1).strip() + mod.title = re.search(r"(.*?)- Mods", soup.title.text).group(1).strip() mod.url = url - mod.release_phase = li.div.div.get("title") - mod.dl_link = "https://minecraft.curseforge.com" - mod.dl_link += li.contents[3].a.get("href") - mod.filename = li.contents[3].contents[3].a.get("data-name") + mod.release_phase = li.div.div.span.get("title") + mod.dl_link = "https://www.curseforge.com" + mod.dl_link += li.contents[5].a.get("href") + '/file' + mod.filename = li.contents[3].a.get("data-name") mod.upload_date = datetime.utcfromtimestamp(int(li.abbr.get("data-epoch"))) return mod @@ -204,9 +204,9 @@ def update_mod(target, delete=False, phase=None): log_change(f"Updated {mod_latest.title} to {mod_latest.filename}") if not delete: os.makedirs("mods_old", exist_ok=True) - os.rename(os.path.join("mods", mod_current.filename), - os.path.join("mods_old", mod_current.filename) - ) + #os.rename(os.path.join("mods", mod_current.filename), + # os.path.join("mods_old", mod_current.filename) + #) else: os.remove(os.path.join("mods", mod_current.filename)) @@ -313,6 +313,19 @@ def remove_mod(target, delete): print(f"Removed {mod.title}") +def url_migration(): + """ + Curseforge changed their urls from `minecraft.curseforge.com/projects/mod` + to `www.curseforge.com/minecraft/mc-mods/mod`. This function updates + urls saved in the database to comply with this. + """ + for mod in get_all_mods(): + url = 'https://www.curseforge.com/minecraft/mc-mods/' + url += mod.url.split('/')[-1] + mod.url = url + mod.save() + + if __name__ == "__main__": import argparse @@ -323,7 +336,7 @@ if __name__ == "__main__": parser.add_argument( "action", choices=["add", "add_all", "update", "update_all", "summary", - "post", "remove"], + "post", "remove", "migrate"], help="What action to perform.", ) parser.add_argument( @@ -361,3 +374,5 @@ if __name__ == "__main__": post_pack() elif args.action == "remove": remove_mod(args.target, args.delete) + elif args.action == "migrate": + url_migration()