This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_copy_non_open_source_mods.py
65 lines (56 loc) · 1.88 KB
/
5_copy_non_open_source_mods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json
import os
import re
import shutil
import tkinter
from tkinter import filedialog
import requests
from bs4 import BeautifulSoup
# Instantiate the CurseForgeAPy client
def choose_dir():
root = tkinter.Tk()
root.withdraw()
file_path = filedialog.askdirectory()
return file_path
def main():
with open("correct_branch.json") as in_file:
source_links = json.loads(in_file.read())
mods = choose_dir()
try:
os.mkdir("raw_mods")
except FileExistsError:
pass
for project in source_links['not_found']:
id = project['id']
r = requests.get(f"https://cflookup.com/{id}")
soup = BeautifulSoup(r.text, 'lxml')
file = soup.find_all('table', {
'class': 'table table-striped table-dark text-start table-bordered caption-top'})[
-1].find_all('td')[0].text.lower()
mod_name_splited = re.split('-|_|\.', file)
mod_name = mod_name_splited[0]
possible_mods = []
for mod in os.listdir(mods):
if mod.lower() \
.replace('-', '') \
.replace('_', '') \
.replace('.', '').startswith(mod_name):
possible_mods.append(mod)
idx = 2
while len(possible_mods) > 1:
mod_name = ''.join(mod_name_splited)[0:idx]
for mod in possible_mods:
if not mod.lower() \
.replace('-', '') \
.replace('_', '') \
.replace('.', '').startswith(mod_name):
possible_mods.remove(mod)
idx += 1
if len(possible_mods) == 0:
print('err', mod_name, file)
continue
mod = possible_mods[0]
print(mod, mod_name)
shutil.copyfile(os.path.join(mods, mod), os.path.join('raw_mods', mod))
if __name__ == "__main__":
main()