|
3 | 3 | from configparser import ConfigParser, ParsingError |
4 | 4 | from urllib.parse import quote, unquote |
5 | 5 |
|
6 | | -from cs2tracker.constants import CAPSULE_PAGES, CONFIG_FILE, INVENTORY_IMPORT_FILE |
| 6 | +from cs2tracker.constants import ( |
| 7 | + CONFIG_FILE, |
| 8 | + INVENTORY_IMPORT_FILE, |
| 9 | +) |
7 | 10 | from cs2tracker.util.padded_console import get_console |
8 | 11 |
|
9 | 12 | STEAM_MARKET_LISTING_BASEURL_CS2 = "https://steamcommunity.com/market/listings/730/" |
10 | 13 | STEAM_MARKET_LISTING_REGEX = r"^https://steamcommunity.com/market/listings/\d+/.+$" |
11 | 14 |
|
| 15 | +CUSTOM_SECTIONS = [ |
| 16 | + "Skins", |
| 17 | + "Special Items", |
| 18 | + "Agents", |
| 19 | + "Charms", |
| 20 | + "Patches", |
| 21 | + "Patch Packs", |
| 22 | + "Stickers", |
| 23 | + "Souvenirs", |
| 24 | + "Others", |
| 25 | +] |
| 26 | + |
| 27 | +PREEXISTING_SECTIONS = [ |
| 28 | + "Cases", |
| 29 | + "Katowice 2014 Sticker Capsule", |
| 30 | + "Cologne 2014 Sticker Capsule", |
| 31 | + "DreamHack 2014 Sticker Capsule", |
| 32 | + "Katowice 2015 Sticker Capsule", |
| 33 | + "Cologne 2015 Sticker Capsule", |
| 34 | + "Cluj-Napoca 2015 Sticker Capsule", |
| 35 | + "Columbus 2016 Sticker Capsule", |
| 36 | + "Cologne 2016 Sticker Capsule", |
| 37 | + "Atlanta 2017 Sticker Capsule", |
| 38 | + "Krakow 2017 Sticker Capsule", |
| 39 | + "Boston 2018 Sticker Capsule", |
| 40 | + "London 2018 Sticker Capsule", |
| 41 | + "Katowice 2019 Sticker Capsule", |
| 42 | + "Berlin 2019 Sticker Capsule", |
| 43 | + "2020 RMR Sticker Capsule", |
| 44 | + "Stockholm 2021 Sticker Capsule", |
| 45 | + "Antwerp 2022 Sticker Capsule", |
| 46 | + "Rio 2022 Sticker Capsule", |
| 47 | + "Paris 2023 Sticker Capsule", |
| 48 | + "Copenhagen 2024 Sticker Capsule", |
| 49 | + "Shanghai 2024 Sticker Capsule", |
| 50 | + "Austin 2025 Sticker Capsule", |
| 51 | +] |
| 52 | + |
12 | 53 | console = get_console() |
13 | 54 |
|
14 | 55 |
|
@@ -46,19 +87,12 @@ def delete_display_sections(self): |
46 | 87 |
|
47 | 88 | def _validate_config_sections(self): |
48 | 89 | """Validate that the configuration file has all required sections.""" |
49 | | - if not self.has_section("User Settings"): |
50 | | - raise ValueError("Missing 'User Settings' section in the configuration file.") |
51 | | - if not self.has_section("App Settings"): |
52 | | - raise ValueError("Missing 'App Settings' section in the configuration file.") |
53 | | - if not self.has_section("Stickers"): |
54 | | - raise ValueError("Missing 'Stickers' section in the configuration file.") |
55 | | - if not self.has_section("Cases"): |
56 | | - raise ValueError("Missing 'Cases' section in the configuration file.") |
57 | | - if not self.has_section("Skins"): |
58 | | - raise ValueError("Missing 'Skins' section in the configuration file.") |
59 | | - for capsule_section in CAPSULE_PAGES: |
60 | | - if not self.has_section(capsule_section): |
61 | | - raise ValueError(f"Missing '{capsule_section}' section in the configuration file.") |
| 90 | + for section in CUSTOM_SECTIONS: |
| 91 | + if not self.has_section(section): |
| 92 | + raise ValueError(f"Missing '{section}' section in the configuration file.") |
| 93 | + for section in PREEXISTING_SECTIONS: |
| 94 | + if not self.has_section(section): |
| 95 | + raise ValueError(f"Missing '{section}' section in the configuration file.") |
62 | 96 |
|
63 | 97 | def _validate_config_values(self): |
64 | 98 | # pylint: disable=too-many-branches |
@@ -136,23 +170,22 @@ def read_from_inventory_file(self): |
136 | 170 | try: |
137 | 171 | with open(INVENTORY_IMPORT_FILE, "r", encoding="utf-8") as inventory_file: |
138 | 172 | inventory_data = json.load(inventory_file) |
139 | | - sorted_inventory_data = dict(sorted(inventory_data.items())) |
140 | 173 |
|
141 | 174 | added_to_config = set() |
142 | | - for item_name, item_owned in sorted_inventory_data.items(): |
143 | | - option = self.name_to_option(item_name, href=True) |
144 | | - for section in self.sections(): |
145 | | - if option in self.options(section): |
146 | | - self.set(section, option, str(item_owned)) |
147 | | - added_to_config.add(item_name) |
148 | | - |
149 | | - for item_name, item_owned in sorted_inventory_data.items(): |
150 | | - if item_name not in added_to_config: |
| 175 | + for _, item_infos in inventory_data.items(): |
| 176 | + for item_name, item_owned in item_infos.items(): |
151 | 177 | option = self.name_to_option(item_name, href=True) |
152 | | - if item_name.startswith("Sticker"): |
153 | | - self.set("Stickers", option, str(item_owned)) |
154 | | - else: |
155 | | - self.set("Skins", option, str(item_owned)) |
| 178 | + for section in self.sections(): |
| 179 | + if option in self.options(section): |
| 180 | + self.set(section, option, str(item_owned)) |
| 181 | + added_to_config.add(item_name) |
| 182 | + |
| 183 | + for section, item_infos in inventory_data.items(): |
| 184 | + sorted_item_infos = dict(sorted(item_infos.items())) |
| 185 | + for item_name, item_owned in sorted_item_infos.items(): |
| 186 | + if item_name not in added_to_config: |
| 187 | + option = self.name_to_option(item_name, href=True) |
| 188 | + self.set(section, option, str(item_owned)) |
156 | 189 |
|
157 | 190 | self.write_to_file() |
158 | 191 | except (FileNotFoundError, json.JSONDecodeError) as error: |
|
0 commit comments