Skip to content

Commit 1d40fb7

Browse files
committed
fix BtB downlaoding when name dont match exactly
also fix how some levels seem to share the same zip file...
1 parent ef0dc8d commit 1d40fb7

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

database/scrape_trle_download.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,29 @@ def _get_trle_btb_download_info(trle_btb_url, lid):
195195
parted = trle_btb_url.split("BtB")
196196
btb_soup = None
197197
for case in ["web", "Web"]:
198-
if parted[1] == f"/{case}/index.html" and len(parted) > 1:
198+
if parted[1] == f"/{case}/index.html" and len(parted) == 2:
199199
btb_soup = scrape_common.get_soup(parted[0] + "BtB" + f"/{case}/downloads.html")
200+
break
200201

201202
if not btb_soup:
202-
print("Fucked up")
203+
print("No BtB download page soup")
203204
sys.exit(1)
205+
204206
trle_info = _get_trle_info(lid)
205207
trle_title = trle_info[0]
206208
trle_zip_size = trle_info[2]
209+
210+
btb_title = scrape_common.normalize_level_name(" - ".join(trle_title.split(" - ")[1:]))
211+
207212
link_tag = None
208-
if isinstance(trle_info[0], str):
209-
link_tag = btb_soup.find("a", string=trle_title.split(" - ")[1])
213+
for a in btb_soup.find_all("a"):
214+
if scrape_common.normalize_level_name(a.get_text()) == btb_title:
215+
link_tag = a
216+
break
217+
218+
if not link_tag:
219+
print("No BtB link tag found")
220+
sys.exit(1)
210221

211222
download_url = None
212223
if isinstance(link_tag, Tag):

database/tombll_create.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def database_zip_file(zip_file, level_id, con):
165165
Returns:
166166
int: The ID of the newly inserted zip file.
167167
"""
168+
# SQL queries for selecting, inserting, and linking tags
169+
query_select_id = "SELECT ZipID FROM Zip WHERE name = ?"
170+
168171
# SQL queries for inserting ZIP file data and linking ZIP files to a level
169172
query_insert = '''
170173
INSERT INTO Zip (name, size, md5sum, url, version, release)
@@ -182,10 +185,12 @@ def database_zip_file(zip_file, level_id, con):
182185
)
183186

184187
# Insert the ZIP file and get its ID
185-
zip_id = tombll_common.query_return_id(query_insert, insert_args, con)
188+
zip_id = tombll_common.query_return_id(query_select_id, (zip_file.get('name'), ), con)
189+
if zip_id is None:
190+
zip_id = tombll_common.query_return_id(query_insert, insert_args, con)
186191

187192
# Link the ZIP file to the level in ZipList table
188-
query_insert_middle = "INSERT INTO ZipList (zipID, levelID) VALUES (?, ?)"
193+
query_insert_middle = "INSERT OR IGNORE INTO ZipList (zipID, levelID) VALUES (?, ?)"
189194
middle_args = (zip_id, level_id)
190195
tombll_common.query_run(query_insert_middle, middle_args, con)
191196
return zip_id

0 commit comments

Comments
 (0)