updated master script to match curseforges new site

This commit is contained in:
iou1name 2019-08-03 19:13:15 -04:00
parent bc441ce6bd
commit 34d686f7f5

View File

@ -102,7 +102,7 @@ def scrape_curse_forge(url, phase=None):
files = bar.contents[bar.contents.index(h)+2].find_all("li") files = bar.contents[bar.contents.index(h)+2].find_all("li")
if phase: if phase:
for li in files: for li in files:
if li.div.div.get("title") == phase: if li.div.div.span.get("title") == phase:
break break
else: else:
print("No valid files for this release phase found.") print("No valid files for this release phase found.")
@ -110,12 +110,12 @@ def scrape_curse_forge(url, phase=None):
else: else:
li = files[0] 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.url = url
mod.release_phase = li.div.div.get("title") mod.release_phase = li.div.div.span.get("title")
mod.dl_link = "https://minecraft.curseforge.com" mod.dl_link = "https://www.curseforge.com"
mod.dl_link += li.contents[3].a.get("href") mod.dl_link += li.contents[5].a.get("href") + '/file'
mod.filename = li.contents[3].contents[3].a.get("data-name") mod.filename = li.contents[3].a.get("data-name")
mod.upload_date = datetime.utcfromtimestamp(int(li.abbr.get("data-epoch"))) mod.upload_date = datetime.utcfromtimestamp(int(li.abbr.get("data-epoch")))
return mod 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}") log_change(f"Updated {mod_latest.title} to {mod_latest.filename}")
if not delete: if not delete:
os.makedirs("mods_old", exist_ok=True) os.makedirs("mods_old", exist_ok=True)
os.rename(os.path.join("mods", mod_current.filename), #os.rename(os.path.join("mods", mod_current.filename),
os.path.join("mods_old", mod_current.filename) # os.path.join("mods_old", mod_current.filename)
) #)
else: else:
os.remove(os.path.join("mods", mod_current.filename)) os.remove(os.path.join("mods", mod_current.filename))
@ -313,6 +313,19 @@ def remove_mod(target, delete):
print(f"Removed {mod.title}") 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__": if __name__ == "__main__":
import argparse import argparse
@ -323,7 +336,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", "remove"], "post", "remove", "migrate"],
help="What action to perform.", help="What action to perform.",
) )
parser.add_argument( parser.add_argument(
@ -361,3 +374,5 @@ if __name__ == "__main__":
post_pack() post_pack()
elif args.action == "remove": elif args.action == "remove":
remove_mod(args.target, args.delete) remove_mod(args.target, args.delete)
elif args.action == "migrate":
url_migration()