Skip to content

Commit ca26cd5

Browse files
committed
fix picture position
1 parent d4ba90f commit ca26cd5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

database/tombll_manage_data.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Manage data for the tombll database."""
22
import os
33
import sys
4+
import re
45
import sqlite3
56
import json
67
import logging
@@ -78,6 +79,15 @@ def print_download_list(level_id, con):
7879
print(row)
7980

8081

82+
def parse_position(s):
83+
"""Pares the letter to int from an jpg name."""
84+
match = re.match(r'^(\d+)([a-z]?)$', s)
85+
if not match:
86+
raise ValueError(f"Invalid format: {s}")
87+
suffix = match.group(2)
88+
return ord(suffix) - ord('a') + 1 if suffix else 0
89+
90+
8191
def add_tombll_json_to_database(data, con):
8292
"""Insert level data and related details into the database.
8393
@@ -108,7 +118,7 @@ def add_tombll_json_to_database(data, con):
108118
# Fetch the .webp image data for the screen
109119
picture['data'] = \
110120
scrape_trle.get_trle_cover(screen.replace("https://www.trle.net/screens/", ""))
111-
picture['position'] = scrape_trle.scrape_common.url_basename_prefix(screen)
121+
picture['position'] = parse_position(scrape_trle.scrape_common.url_basename_prefix(screen))
112122
picture['md5sum'] = scrape_trle.scrape_common.calculate_data_md5(picture['data'])
113123
tombll_create.database_screen(picture, level_id, con)
114124

@@ -121,7 +131,8 @@ def add_tombll_json_to_database(data, con):
121131
picture = data_factory.make_picture()
122132
picture['data'] = \
123133
scrape_trle.get_trle_cover(screen.replace("https://www.trle.net/screens/", ""))
124-
picture['position'] = scrape_trle.scrape_common.url_basename_prefix(screen)
134+
picture['position'] = \
135+
parse_position(scrape_trle.scrape_common.url_basename_prefix(screen))
125136
picture['md5sum'] = scrape_trle.scrape_common.calculate_data_md5(picture['data'])
126137
webp_imgage_array.append(picture)
127138

@@ -259,7 +270,7 @@ def update_tombll_json_to_database(data, level_id, con):
259270
# Fetch the .webp image data for the screen
260271
picture['data'] = \
261272
scrape_trle.get_trle_cover(screen.replace("https://www.trle.net/screens/", ""))
262-
picture['position'] = scrape_trle.scrape_common.url_basename_prefix(screen)
273+
picture['position'] = parse_position(scrape_trle.scrape_common.url_basename_prefix(screen))
263274
picture['md5sum'] = scrape_trle.scrape_common.calculate_data_md5(picture['data'])
264275
picture_id = tombll_create.database_screen(picture, level_id, con)
265276
new_set.add(picture_id)
@@ -273,7 +284,8 @@ def update_tombll_json_to_database(data, level_id, con):
273284
picture = data_factory.make_picture()
274285
picture['data'] = \
275286
scrape_trle.get_trle_cover(screen.replace("https://www.trle.net/screens/", ""))
276-
picture['position'] = scrape_trle.scrape_common.url_basename_prefix(screen)
287+
picture['position'] = \
288+
parse_position(scrape_trle.scrape_common.url_basename_prefix(screen))
277289
picture['md5sum'] = scrape_trle.scrape_common.calculate_data_md5(picture['data'])
278290
webp_imgage_array.append(picture)
279291

0 commit comments

Comments
 (0)