Skip to content

Commit 63d850a

Browse files
committed
update level cards
1 parent 1bb9b15 commit 63d850a

File tree

5 files changed

+90
-56
lines changed

5 files changed

+90
-56
lines changed

database/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def show_menu():
1313
print("1. new - Create a new empty index database and add static data")
1414
print("2. new - Create a new full index database, without info and walkthrough data")
1515
print("3. new - Create a new full index database, with info and walkthrough data")
16-
print("4. update - Insert missing TRLE book basic records")
17-
print("5. update - Insert missing TRLE book records with info and walkthrough")
16+
print("4. update - Insert missing TRLE card records")
17+
print("5. update - Insert missing TRLE full records with info and walkthrough")
1818
print("6. resync all - Update or remove every record to mirror TRLE")
1919
print("7. trle - Run https TRLE")
2020
print("8. trle_local - Run TRLE local")
@@ -30,15 +30,17 @@ def main_menu():
3030
if choice == "1":
3131
make_tombll_database.run()
3232
elif choice == "2":
33-
pass
33+
make_tombll_database.run()
34+
tombll_view.update_level_cards()
3435
elif choice == "3":
35-
pass
36+
make_tombll_database.run()
37+
tombll_view.update_levels()
3638
elif choice == "4":
37-
pass
39+
tombll_view.update_level_cards()
3840
elif choice == "5":
39-
pass
41+
tombll_view.update_levels()
4042
elif choice == "6":
41-
pass
43+
print("Not Implemented...")
4244
elif choice == "7":
4345
tombll_view.scrape_trle_index()
4446
elif choice == "8":

database/screenshot1.jpg

-1.28 MB
Loading

database/tombll_manage_data.py

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,24 @@ def print_info():
3535
-rm [lid] Remove one level record
3636
-u [lid] Update a level record
3737
38-
-ld [Level.LevelID] List download files records
39-
-ad [Level.LevelID Zip.name Zip.size Zip.md5sum]
38+
-ld [lid] List download files records
39+
-ad [lid Zip.name Zip.size Zip.md5sum]
4040
Add a local zip file to a level without a file
4141
"""
4242
print(help_text.strip())
4343

4444

4545
def list_levels():
46-
"""List all level in the database."""
46+
"""Retrieve and prints a list of level information."""
47+
# Fetch all rows
4748
con = database_make_connection()
48-
print_list(con)
49+
results = tombll_read.database_level_list(con)
4950
con.close()
5051

52+
# Iterate over the results and print each row
53+
for row in results:
54+
print(row)
55+
5156

5257
def add_level(lid):
5358
"""Add a level by taking the lid number."""
@@ -173,16 +178,23 @@ def add_download(lid, name, size, md5):
173178

174179
con = database_make_connection()
175180
database_begin_write(con)
176-
tombll_create.database_zip_file(data, lid, con)
181+
level_id = tombll_read.database_level_id(lid, con)
182+
tombll_create.database_zip_file(data, level_id, con)
177183
database_commit_and_close(con)
178184

179185

180186
def list_downloads(lid):
181-
"""List all download files for a level by taking the lid number."""
187+
"""Print a list of ZIP file entries associated with a specific level."""
188+
# Fetch all rows
182189
con = database_make_connection()
183-
print_download_list(lid, con)
190+
level_id = tombll_read.database_level_id(lid, con)
191+
results = tombll_read.database_zip_list(level_id, con)
184192
con.close()
185193

194+
# Print each row in the result
195+
for row in results:
196+
print(row)
197+
186198

187199
def get_local_page(offset, con):
188200
"""Pass down API to get a TRLE page from the database."""
@@ -232,25 +244,6 @@ def database_commit_and_close(con):
232244
con.close()
233245

234246

235-
def print_list(con):
236-
"""
237-
Retrieve and prints a list of level information.
238-
239-
Args:
240-
con (sqlite3.Connection): An open SQLite database connection.
241-
242-
Returns:
243-
None: This function does not return any value.
244-
It prints the results directly to the console.
245-
"""
246-
# Fetch all rows
247-
results = tombll_read.database_level_list(con)
248-
249-
# Iterate over the results and print each row
250-
for row in results:
251-
print(row)
252-
253-
254247
def trle_level_url(lid):
255248
"""
256249
Get level TRLE url from lid number.
@@ -261,26 +254,6 @@ def trle_level_url(lid):
261254
return f"https://www.trle.net/sc/levelfeatures.php?lid={lid}"
262255

263256

264-
def print_download_list(level_id, con):
265-
"""
266-
Print a list of ZIP file entries associated with a specific level.
267-
268-
Args:
269-
level_id (int): The ID of the level for which to retrieve ZIP files.
270-
con (sqlite3.Connection): An active SQLite database connection.
271-
272-
Returns:
273-
None: This function prints the query results to the console.
274-
275-
"""
276-
# Fetch all rows
277-
results = tombll_read.database_zip_list(level_id, con)
278-
279-
# Print each row in the result
280-
for row in results:
281-
print(row)
282-
283-
284257
def parse_position(s):
285258
"""Pares the letter to int from an jpg name."""
286259
match = re.match(r'^(\d+)([a-z]?)$', s)

database/tombll_read.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def database_level_list(con):
4949
List: List of all levels.
5050
"""
5151
query = '''
52-
SELECT Level.LevelID, Info.Title, Author.value
52+
SELECT Info.trleID, Info.Title, Author.value
5353
FROM Level
5454
JOIN Info ON Level.infoID = Info.InfoID
5555
JOIN AuthorList ON Level.LevelID = AuthorList.levelID
@@ -77,7 +77,7 @@ def database_zip_list(level_id, con):
7777
None: List of all zip files.
7878
"""
7979
query = '''
80-
SELECT Zip.*
80+
SELECT Zip.name, Zip.size, Zip.md5sum, Zip.url, Zip.version, Zip.release
8181
FROM Level
8282
JOIN ZipList ON Level.LevelID = ZipList.levelID
8383
JOIN Zip ON ZipList.zipID = Zip.ZipID

database/tombll_view.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""terminal menus, prompts for data, tests and setting up the database."""
1+
"""Terminal menus, prompts for data, tests and setting up the database."""
22

33
import os
44
import sqlite3
@@ -8,6 +8,65 @@
88
os.chdir(os.path.dirname(os.path.abspath(__file__)))
99

1010

11+
def compare_pages(estimate):
12+
"""Get the range from database and server pages. Its a bit stupid but lets do this at first."""
13+
db_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tombll.db')
14+
con = sqlite3.connect(db_path)
15+
database_page = tombll_manage_data.get_local_page(0, con)
16+
con.close()
17+
18+
database_id = 1
19+
if database_page['levels']:
20+
database_id = database_page['levels'][0]['trle_id']
21+
22+
trle_id = int(tombll_manage_data.get_trle_page(0)['levels'][0]['trle_id'])
23+
total_records = trle_id - database_id + 1
24+
about_time_sec = total_records * estimate
25+
26+
hours, remainder = divmod(about_time_sec, 3600)
27+
minutes, seconds = divmod(remainder, 60)
28+
29+
print(f"There are {total_records} level records (or fewer) to update.")
30+
print(f"Estimated time: {hours:02d}:{minutes:02d}:{seconds:02d}")
31+
32+
return (database_id, trle_id)
33+
34+
35+
def update_level_cards():
36+
"""
37+
Update the database by getting the missing last card records.
38+
39+
Get a local page from the database and compare it to a scraped page from trle.net.
40+
Then add all the level cards in the range of ID numbers from the last date ID in the database
41+
to the last date ID on trle.net.
42+
"""
43+
trle_range = compare_pages(6)
44+
print("I will upload a database on MEGA to offload the server.")
45+
print("The program can't even handle that many records right now.")
46+
print("There is no reason for you to test this.")
47+
print("Do you want to continue?")
48+
awn = input("y or n: ")
49+
if awn == 'y':
50+
tombll_manage_data.add_level_card_range(trle_range[0], trle_range[1])
51+
52+
53+
def update_levels():
54+
"""
55+
Update the databse by getting the missing last level records.
56+
57+
Get a local page from the database and then compare it by a scraped page form trle.net.
58+
Then add all the level in the range of id numbers from the last date id on the database
59+
to the last date id on trle.net.
60+
"""
61+
'''
62+
trle_range = compare_pages(7)
63+
print("Do you want to continue?")
64+
awn = input("y or n: ")
65+
if awn == 'y':
66+
tombll_manage_data.add_level_range(trle_range[0], trle_range[1])
67+
'''
68+
69+
1170
def scrape_trle_index():
1271
"""Browse TRLE data by using normal https requests."""
1372
offset = 0

0 commit comments

Comments
 (0)