|
3 | 3 |
|
4 | 4 | from scry.db_queries import get_unique_cards |
5 | 5 | from scry.loading import Loading |
6 | | -from scry.request import find_current_release, check_date_past |
| 6 | +from scry.request import find_current_release, check_date_past, get_set_info |
7 | 7 | from . import ( |
8 | 8 | get_random_card, |
9 | 9 | insert_cards, |
@@ -140,43 +140,44 @@ def handle_search(args, db_connection): |
140 | 140 |
|
141 | 141 |
|
142 | 142 | def handle_set(args, db_connection): |
143 | | - # Search for a set of cards |
| 143 | + # Searches for a specific set of cards |
| 144 | + |
144 | 145 | connection = db_connection |
| 146 | + |
| 147 | + # loading animation |
| 148 | + loading = Loading().start() |
| 149 | + |
| 150 | + # use setcode, or find setcode of "latest" set |
145 | 151 | query_setcode = "" |
146 | 152 | if args.set_query.lower() == "latest": |
147 | | - # Find the moce recent release and query stats for it |
| 153 | + # Find the most recent release and query stats for it |
148 | 154 | current_set = find_current_release(set_codes()) |
149 | | - current_set_code = current_set.get("set_code") |
150 | | - query_setcode = str(current_set_code) |
151 | | - current_set_name = current_set.get("name") |
152 | | - print(f"Stats for {current_set_name} ({current_set_code}):") |
| 155 | + query_setcode = str(current_set) |
153 | 156 | else: |
154 | 157 | query_setcode = str(args.set_query) |
155 | | - print( |
156 | | - f"Stats for \033[1m{lookup_set_info("name", args.set_query.upper()).upper()}\033[0m" |
157 | | - ) |
158 | 158 |
|
159 | | - query = f"set:{query_setcode}" # unique:prints includes variations within set, otherwise only unique cards |
| 159 | + # request general set info from /set:code |
| 160 | + set_info = get_set_info(query_setcode) |
160 | 161 |
|
161 | | - card_list = get_card_list(query) or [] |
162 | | - stamp = get_timestamp() |
| 162 | + set_name = set_info.get("name") |
| 163 | + set_date = set_info.get("released_at") |
| 164 | + set_count = set_info.get("card_count") |
163 | 165 |
|
| 166 | + # request list of cards from set |
| 167 | + # optionally append `unique:prints` for variations within set |
| 168 | + setlist_query = f"set:{query_setcode}" |
| 169 | + card_list = get_card_list(setlist_query) or [] |
| 170 | + stamp = get_timestamp() |
164 | 171 | insert_cards(card_list, stamp, connection) |
165 | 172 |
|
166 | | - # loading animation |
167 | | - loading = Loading().start() |
168 | | - set_release_details = [] |
169 | | - set_release_details.append(lookup_set_info("release_date", query_setcode.upper())) |
170 | | - set_release_details.append(lookup_set_info("card_count", query_setcode.upper())) |
171 | | - set_release_details.append(get_unique_cards(connection, stamp)) |
172 | 173 | loading.end() |
173 | 174 |
|
174 | | - print( |
175 | | - f""" |
176 | | -\x1b[3m Released: {set_release_details[0]} |
177 | | - {set_release_details[1]} cards in set |
178 | | - (Showing {set_release_details[2]} unique cards only)\n \033[0m""" |
179 | | - ) |
| 175 | + print(f"Stats for \033[1m{set_name} ({query_setcode.upper()})\033[0m") |
| 176 | + print(f"\x1b[3m Released: {set_date}") |
| 177 | + print(f" {set_count} cards in set") |
| 178 | + print(f" Showing {get_unique_cards(connection,stamp)} unique cards\n \033[0m") |
| 179 | + |
| 180 | + # finally show stats for the set |
180 | 181 | print_stats(connection, stamp) |
181 | 182 |
|
182 | 183 |
|
@@ -232,9 +233,11 @@ def format_set_info(set_details) -> str: |
232 | 233 |
|
233 | 234 |
|
234 | 235 | def lookup_set_info(info: str, set_code: str) -> str: |
| 236 | + # TODO: don't call set codes every time!! |
235 | 237 | setlist = set_codes() |
236 | 238 | for s in setlist: |
237 | 239 | if set_code == s["set_code"]: |
| 240 | + print(s[info]) |
238 | 241 | return s[info] |
239 | 242 | return "Set info not found. Check the setcode is correct. You can request name, card_count, release_date" |
240 | 243 |
|
|
0 commit comments