Skip to content

Commit eafe369

Browse files
committed
fix date scraping and displaying
1 parent 5b1eae2 commit eafe369

File tree

3 files changed

+55
-29
lines changed

3 files changed

+55
-29
lines changed

database/scrape_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ def get_trle_class(soup):
233233

234234
def get_trle_release(soup):
235235
"""Extract the release date."""
236-
return soup.find('td', string='release date:').find_next('td').get_text(strip=True) or ""
236+
raw_date = soup.find('td', string='release date:').find_next('td').get_text(strip=True) or ""
237+
return convert_to_iso(raw_date)
237238

238239

239240
def get_trle_difficulty(soup):

database/tombll_read.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,8 @@ def trle_page(offset, con, limit=20, sort_latest_first=False):
210210
"""Get a trle page."""
211211
page = data_factory.make_trle_page_data()
212212
page['offset'] = offset
213-
214-
order_direction = 1 if sort_latest_first else 0
215-
216213
result = []
214+
217215
page['records_total'] = tombll_common.query_return_everything("""
218216
SELECT COUNT(*)
219217
FROM Info
@@ -222,29 +220,50 @@ def trle_page(offset, con, limit=20, sort_latest_first=False):
222220
INNER JOIN Author ON Author.AuthorID = AuthorList.authorID
223221
""", None, con)[0][0]
224222

225-
result = tombll_common.query_return_everything("""
226-
SELECT
227-
Info.trleID,
228-
Author.value,
229-
Info.title,
230-
InfoDifficulty.value,
231-
InfoDuration.value,
232-
InfoClass.value,
233-
InfoType.value,
234-
Info.release
235-
FROM Info
236-
INNER JOIN Level ON (Info.InfoID = Level.infoID)
237-
INNER JOIN AuthorList ON (Level.LevelID = AuthorList.levelID)
238-
INNER JOIN Author ON (Author.AuthorID = AuthorList.authorID)
239-
LEFT JOIN InfoDifficulty ON (InfoDifficulty.InfoDifficultyID = Info.difficulty)
240-
LEFT JOIN InfoDuration ON (InfoDuration.InfoDurationID = Info.duration)
241-
INNER JOIN InfoType ON (InfoType.InfoTypeID = Info.type)
242-
LEFT JOIN InfoClass ON (InfoClass.InfoClassID = Info.class)
243-
ORDER BY
244-
CASE WHEN ? = 0 THEN Info.release END ASC,
245-
CASE WHEN ? = 1 THEN Info.release END DESC
246-
LIMIT ? OFFSET ?;
247-
""", (order_direction, order_direction, limit, offset), con)
223+
if sort_latest_first:
224+
result = tombll_common.query_return_everything("""
225+
SELECT
226+
Info.trleID,
227+
Author.value,
228+
Info.title,
229+
InfoDifficulty.value,
230+
InfoDuration.value,
231+
InfoClass.value,
232+
InfoType.value,
233+
Info.release
234+
FROM Info
235+
INNER JOIN Level ON (Info.InfoID = Level.infoID)
236+
INNER JOIN AuthorList ON (Level.LevelID = AuthorList.levelID)
237+
INNER JOIN Author ON (Author.AuthorID = AuthorList.authorID)
238+
LEFT JOIN InfoDifficulty ON (InfoDifficulty.InfoDifficultyID = Info.difficulty)
239+
LEFT JOIN InfoDuration ON (InfoDuration.InfoDurationID = Info.duration)
240+
INNER JOIN InfoType ON (InfoType.InfoTypeID = Info.type)
241+
LEFT JOIN InfoClass ON (InfoClass.InfoClassID = Info.class)
242+
ORDER BY Info.release DESC
243+
LIMIT ? OFFSET ?
244+
""", (limit, offset), con)
245+
else:
246+
result = tombll_common.query_return_everything("""
247+
SELECT
248+
Info.trleID,
249+
Author.value,
250+
Info.title,
251+
InfoDifficulty.value,
252+
InfoDuration.value,
253+
InfoClass.value,
254+
InfoType.value,
255+
Info.release
256+
FROM Info
257+
INNER JOIN Level ON (Info.InfoID = Level.infoID)
258+
INNER JOIN AuthorList ON (Level.LevelID = AuthorList.levelID)
259+
INNER JOIN Author ON (Author.AuthorID = AuthorList.authorID)
260+
LEFT JOIN InfoDifficulty ON (InfoDifficulty.InfoDifficultyID = Info.difficulty)
261+
LEFT JOIN InfoDuration ON (InfoDuration.InfoDurationID = Info.duration)
262+
INNER JOIN InfoType ON (InfoType.InfoTypeID = Info.type)
263+
LEFT JOIN InfoClass ON (InfoClass.InfoClassID = Info.class)
264+
ORDER BY Info.release ASC
265+
LIMIT ? OFFSET ?
266+
""", (limit, offset), con)
248267

249268
for row in result:
250269
level = data_factory.make_trle_level_data()

database/tombll_view.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Terminal menus, prompts for data, tests and setting up the database."""
2-
32
import os
43
import sqlite3
54

5+
import shutil
66
import tombll_manage_data
77

8+
size = shutil.get_terminal_size(fallback=(149, 14))
89
os.chdir(os.path.dirname(os.path.abspath(__file__)))
910

1011

@@ -100,8 +101,13 @@ def _print_trle_page(page):
100101
print(f"{page['offset'] + len(page['levels'])} of {page['records_total']} records")
101102
levels = page['levels']
102103

104+
if size.columns < 149:
105+
print("You're scrren is to small")
106+
print("Make you font smaller")
107+
input("Press Enter see the page")
108+
103109
# Column widths for even spacing
104-
column_widths = [6, 20, 70, 17, 11, 16, 6, 10]
110+
column_widths = [6, 20, 70, 17, 11, 16, 6, 11]
105111

106112
headers = ["ID", "Author", "Level Name", "Difficulty",
107113
"Duration", "Class", "Type", "Released"]

0 commit comments

Comments
 (0)