Skip to content

Commit 12e3fc9

Browse files
committed
fix: update description regex
1 parent bb2b22c commit 12e3fc9

File tree

4 files changed

+126
-64
lines changed

4 files changed

+126
-64
lines changed

gui/main_window.py

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,40 @@
33

44
from PyQt6.QtCore import QPropertyAnimation, Qt, QTimer, QUrl
55
from PyQt6.QtGui import QColor, QDesktopServices
6-
from PyQt6.QtWidgets import (QApplication, QComboBox, QHBoxLayout, QHeaderView,
7-
QLabel, QMainWindow, QMessageBox, QPushButton,
8-
QStyle, QStyledItemDelegate, QTableWidget,
9-
QTableWidgetItem, QVBoxLayout, QWidget)
10-
11-
from __version__ import __version__ as version, __version_description__
12-
from gui.styles import (COMBO_BOX, COPY_LABEL, FOOTER, FOOTER_LABEL, HEADER,
13-
HEADER_LABEL, MAIN_WINDOW, MESSAGE_BOX, START_BUTTON,
14-
STATUS_LABEL, TABLE_WIDGET, UPDATE_BUTTON,
15-
get_update_message)
6+
from PyQt6.QtWidgets import (
7+
QApplication,
8+
QComboBox,
9+
QHBoxLayout,
10+
QHeaderView,
11+
QLabel,
12+
QMainWindow,
13+
QMessageBox,
14+
QPushButton,
15+
QStyle,
16+
QStyledItemDelegate,
17+
QTableWidget,
18+
QTableWidgetItem,
19+
QVBoxLayout,
20+
QWidget,
21+
)
22+
23+
from __version__ import __version__ as version
24+
from __version__ import __version_description__
25+
from gui.styles import (
26+
COMBO_BOX,
27+
COPY_LABEL,
28+
FOOTER,
29+
FOOTER_LABEL,
30+
HEADER,
31+
HEADER_LABEL,
32+
MAIN_WINDOW,
33+
MESSAGE_BOX,
34+
START_BUTTON,
35+
STATUS_LABEL,
36+
TABLE_WIDGET,
37+
UPDATE_BUTTON,
38+
get_update_message,
39+
)
1640
from poeNinja.ninjaAPI import PoeNinja
1741
from utils.utils import Utils
1842

@@ -45,7 +69,9 @@ def _setup_ui(self) -> None:
4569

4670
def _configure_main_window(self) -> None:
4771
"""Configure main window properties."""
48-
self.setWindowTitle(f"Path of Exile Card Flipper v{version} | github.com/ezbooz")
72+
self.setWindowTitle(
73+
f"Path of Exile Card Flipper v{version} | github.com/ezbooz"
74+
)
4975
self.setFixedSize(1070, 700)
5076
self.central_widget = QWidget(self)
5177
self.setCentralWidget(self.central_widget)
@@ -94,7 +120,9 @@ def _create_table(self) -> None:
94120
self.table_widget.setShowGrid(False)
95121
self.table_widget.verticalHeader().setVisible(False)
96122
self.table_widget.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
97-
self.table_widget.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
123+
self.table_widget.setSelectionBehavior(
124+
QTableWidget.SelectionBehavior.SelectRows
125+
)
98126
self.table_widget.setSelectionMode(QTableWidget.SelectionMode.SingleSelection)
99127

100128
def _create_controls(self) -> None:
@@ -182,11 +210,7 @@ def _fetch_and_process_data(self) -> Optional[List[Dict]]:
182210
highscores = self.utils.calculate_highscores(
183211
divination_data, currency_data, unique_items
184212
)
185-
return sorted(
186-
highscores.values(),
187-
key=lambda x: x["Profit"],
188-
reverse=True
189-
)
213+
return sorted(highscores.values(), key=lambda x: x["Profit"], reverse=True)
190214

191215
def _display_results(self, highscores_sorted: List[Dict]) -> None:
192216
"""Display processed results in the table."""
@@ -204,10 +228,12 @@ def _get_divine_orb_value(self) -> Optional[float]:
204228
with open("Data\\Currency.json", "r") as file:
205229
data = json.load(file)
206230
return next(
207-
(line["receive"]["value"]
208-
for line in data["lines"]
209-
if line["currencyTypeName"] == "Divine Orb"),
210-
None
231+
(
232+
line["receive"]["value"]
233+
for line in data["lines"]
234+
if line["currencyTypeName"] == "Divine Orb"
235+
),
236+
None,
211237
)
212238
except (FileNotFoundError, json.JSONDecodeError):
213239
return None
@@ -216,10 +242,18 @@ def _setup_table_structure(self, data: List[Dict]) -> None:
216242
"""Configure table structure and headers."""
217243
self.table_widget.setRowCount(len(data))
218244
self.table_widget.setColumnCount(8)
219-
self.table_widget.setHorizontalHeaderLabels([
220-
"#", "Name", "Type", "Total profit", "Profit per card",
221-
"1 card price", "Total set price", "Reward price"
222-
])
245+
self.table_widget.setHorizontalHeaderLabels(
246+
[
247+
"#",
248+
"Name",
249+
"Type",
250+
"Total profit",
251+
"Profit per card",
252+
"1 card price",
253+
"Total set price",
254+
"Reward price",
255+
]
256+
)
223257

224258
header = self.table_widget.horizontalHeader()
225259
for col in range(self.table_widget.columnCount()):
@@ -255,9 +289,7 @@ def to_divine(value: float) -> float:
255289
self._create_table_item(row, 0, str(row + 1))
256290
self._create_table_item(row, 1, item["Name"], align_left=True)
257291
self._create_table_item(row, 2, item["Type"], align_left=True)
258-
self._create_table_item(
259-
row, 3, f"{int(item['Profit'])} c ({profit_divine} d)"
260-
)
292+
self._create_table_item(row, 3, f"{int(item['Profit'])} c ({profit_divine} d)")
261293
self._create_table_item(
262294
row, 4, f"{int(item['Profitpercard'])} c ({profit_per_card_divine} d)"
263295
)
@@ -267,8 +299,9 @@ def to_divine(value: float) -> float:
267299
row, 7, f"{int(item['Sellprice'])} c ({sellprice_divine} d)"
268300
)
269301

270-
def _create_table_item(self, row: int, col: int, text: str,
271-
align_left: bool = False) -> QTableWidgetItem:
302+
def _create_table_item(
303+
self, row: int, col: int, text: str, align_left: bool = False
304+
) -> QTableWidgetItem:
272305
"""Create and configure a table widget item."""
273306
item = QTableWidgetItem(text)
274307
item.setBackground(QColor(0, 0, 0, 0))
@@ -340,9 +373,7 @@ def _hide_copy_label(self) -> None:
340373
self.fade_animation.setDuration(200)
341374
self.fade_animation.setStartValue(1)
342375
self.fade_animation.setEndValue(0)
343-
self.fade_animation.finished.connect(
344-
lambda: self.copy_label.setVisible(False)
345-
)
376+
self.fade_animation.finished.connect(lambda: self.copy_label.setVisible(False))
346377
self.fade_animation.start()
347378

348379
def check_for_updates(self) -> None:
@@ -363,7 +394,9 @@ def check_for_updates(self) -> None:
363394
self.show_notification("You have the latest version")
364395
self.status_label.setText("You have the latest version")
365396

366-
def _show_update_message(self, remote_version: str, remote_description: str) -> None:
397+
def _show_update_message(
398+
self, remote_version: str, remote_description: str
399+
) -> None:
367400
"""Show update available message box."""
368401
msg_box = QMessageBox(self)
369402
msg_box.setWindowTitle("Update Available")
@@ -383,12 +416,14 @@ def generate_trade_link(self, row: int, column: int) -> None:
383416
"query": {
384417
"status": {"option": "online"},
385418
"type": item_name,
386-
"stats": [{"type": "and", "filters": []}]
419+
"stats": [{"type": "and", "filters": []}],
387420
},
388-
"sort": {"price": "asc"}
421+
"sort": {"price": "asc"},
389422
}
390423

391424
encoded_query = json.dumps(trade_query)
392-
trade_url = f"https://www.pathofexile.com/trade/search/{league}?q={encoded_query}"
425+
trade_url = (
426+
f"https://www.pathofexile.com/trade/search/{league}?q={encoded_query}"
427+
)
393428

394-
QDesktopServices.openUrl(QUrl(trade_url))
429+
QDesktopServices.openUrl(QUrl(trade_url))

gui/styles.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@
192192
"""
193193

194194

195-
def get_update_message(remote_version, current_version, current_description="") -> str:
195+
def get_update_message(remote_version, current_version, description) -> str:
196196
return f"""
197-
<p style='font-size:14px;'>A new version (<b>v{remote_version}</b>) is available!</p>
197+
<p style='font-size:14px;'><b>A new version (v{remote_version}) is available!</b></p>
198198
<p style='font-size:13px;'>Current version: v{current_version}</p>
199-
<p style='font-size:13px;'><i>What's new in your version:</i><br>{current_description}</p><br>
199+
<p style='font-size:13px;'><b>What's new in your version:</b><br>{description }</p><br>
200200
<p style='font-size:14px;'>Download update:
201201
<a href='https://github.com/ezbooz/Path-of-Exile-divination-cards-flipper-POE'
202202
style='color:#4CAF50; text-decoration:none;'><b>GitHub Repository</b></a></p>

poeNinja/ninjaAPI.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Dict, List, Union
2+
23
from utils.utils import Utils
34

45

@@ -35,14 +36,20 @@ def _build_endpoints(self, league_name: str) -> Dict[str, Union[str, List[str]]]
3536
"""
3637
return {
3738
"currency": self._build_url("currencyoverview", league_name, "Currency"),
38-
"divination": self._build_url("itemoverview", league_name, "DivinationCard"),
39+
"divination": self._build_url(
40+
"itemoverview", league_name, "DivinationCard"
41+
),
3942
"uniques": [
4043
self._build_url("itemoverview", league_name, unique_type)
4144
for unique_type in [
42-
"UniqueMap", "UniqueJewel", "UniqueFlask",
43-
"UniqueWeapon", "UniqueArmour", "UniqueAccessory"
45+
"UniqueMap",
46+
"UniqueJewel",
47+
"UniqueFlask",
48+
"UniqueWeapon",
49+
"UniqueArmour",
50+
"UniqueAccessory",
4451
]
45-
]
52+
],
4653
}
4754

4855
def _build_url(self, endpoint: str, league_name: str, item_type: str) -> str:
@@ -102,4 +109,4 @@ def _generate_filename(self, url: str, directory: str) -> str:
102109
Full file path string
103110
"""
104111
item_name = self.utils.get_item_name(url)
105-
return f"{directory}//{item_name}.json"
112+
return f"{directory}//{item_name}.json"

utils/utils.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Utils:
1818
ITEM_NAME_MAPPINGS = {
1919
"Master Cartographer's Sextant": "Awakened Sextant",
2020
"Charan's Sword": "Oni-Goroshi",
21-
"Azyran's Reward": "The Anima Stone"
21+
"Azyran's Reward": "The Anima Stone",
2222
}
2323

2424
def __init__(self):
@@ -72,7 +72,7 @@ def save_data_to_file(data: Union[Dict, List], file_path: str) -> None:
7272
data: Data to save (dict or list)
7373
file_path: Path to save file
7474
"""
75-
with open(file_path, "w+", encoding='utf-8') as outfile:
75+
with open(file_path, "w+", encoding="utf-8") as outfile:
7676
json.dump(data, outfile, ensure_ascii=False, indent=2)
7777

7878
@staticmethod
@@ -85,24 +85,32 @@ def load_data() -> Tuple[Dict, Dict, Dict]:
8585
- Currency data
8686
- Unique items data
8787
"""
88-
with open("Data\\DivinationCard.json", "r", encoding='utf-8') as f:
88+
with open("Data\\DivinationCard.json", "r", encoding="utf-8") as f:
8989
divination_data = json.load(f)
9090

91-
with open("Data\\Currency.json", "r", encoding='utf-8') as f:
91+
with open("Data\\Currency.json", "r", encoding="utf-8") as f:
9292
currency_data = json.load(f)
9393

9494
unique_items = {}
9595
for file in os.listdir("Uniquedata"):
9696
file_path = os.path.join("Uniquedata", file)
97-
with open(file_path, "r", encoding='utf-8') as f:
97+
with open(file_path, "r", encoding="utf-8") as f:
9898
data = json.load(f)
9999
for item in data["lines"]:
100100
unique_items[item["name"]] = item["chaosValue"]
101101

102102
return divination_data, currency_data, unique_items
103103

104104
@staticmethod
105-
def process_card(name, chaos_value, stack_size, explicit_modifiers, currency, unique_items, divination_data):
105+
def process_card(
106+
name,
107+
chaos_value,
108+
stack_size,
109+
explicit_modifiers,
110+
currency,
111+
unique_items,
112+
divination_data,
113+
):
106114
total_cost = chaos_value * stack_size
107115
type_info = explicit_modifiers[0]["text"]
108116
match = re.match("<(.*)>{(.*)}", type_info)
@@ -117,7 +125,9 @@ def process_card(name, chaos_value, stack_size, explicit_modifiers, currency, un
117125
try:
118126
reward_value = currency.get(items[1], 0) * float(items[0])
119127
except KeyError:
120-
print(f"KeyError: Item '{items[1]}' not found in currency data for card '{name}'")
128+
print(
129+
f"KeyError: Item '{items[1]}' not found in currency data for card '{name}'"
130+
)
121131
return None
122132
elif match.group(1) == "uniqueitem":
123133
reward_type = "Unique"
@@ -129,15 +139,19 @@ def process_card(name, chaos_value, stack_size, explicit_modifiers, currency, un
129139
try:
130140
reward_value = unique_items.get(item_reward, 0)
131141
except KeyError:
132-
print(f"KeyError: Item '{item_reward}' not found in unique items data for card '{name}'")
142+
print(
143+
f"KeyError: Item '{item_reward}' not found in unique items data for card '{name}'"
144+
)
133145
return None
134146
else:
135147
reward_type = "Divination"
136148
item_reward = match.group(2)
137149
try:
138150
reward_value = divination_data.get(item_reward, 0)
139151
except KeyError:
140-
print(f"KeyError: Item '{item_reward}' not found in divination data for card '{name}'")
152+
print(
153+
f"KeyError: Item '{item_reward}' not found in divination data for card '{name}'"
154+
)
141155
return None
142156
profit = round((reward_value - total_cost), 2)
143157
return {
@@ -148,7 +162,7 @@ def process_card(name, chaos_value, stack_size, explicit_modifiers, currency, un
148162
"Stack": stack_size,
149163
"Profitpercard": round(profit / stack_size, 2),
150164
"Total": total_cost,
151-
"Sellprice": reward_value
165+
"Sellprice": reward_value,
152166
}
153167
return None
154168

@@ -160,10 +174,7 @@ def _handle_special_names(card_name: str, reward_content: str) -> str:
160174
return Utils.ITEM_NAME_MAPPINGS.get(reward_content, reward_content)
161175

162176
def calculate_highscores(
163-
self,
164-
divination_data: Dict,
165-
currency_data: Dict,
166-
unique_items: Dict[str, float]
177+
self, divination_data: Dict, currency_data: Dict, unique_items: Dict[str, float]
167178
) -> Dict[str, Dict]:
168179
"""Calculate profit highscores for divination cards.
169180
@@ -201,7 +212,9 @@ def get_current_leagues() -> List[Dict]:
201212
List of active league dictionaries
202213
"""
203214
try:
204-
req = Request(Utils.POE_API_LEAGUES_URL, headers={"User-Agent": Utils.USER_AGENT})
215+
req = Request(
216+
Utils.POE_API_LEAGUES_URL, headers={"User-Agent": Utils.USER_AGENT}
217+
)
205218
with urlopen(req) as response:
206219
leagues = json.loads(response.read().decode("utf-8"))
207220

@@ -244,15 +257,22 @@ def check_for_updates() -> Optional[tuple[str, str]]:
244257
content = response.read().decode()
245258

246259
version_match = re.search(r'__version__ = "(.*?)"', content)
247-
description_match = re.search(r'__version_description__ = "(.*?)"', content)
260+
description_match = re.search(
261+
r'__version_description__ = """([\s\S]*?)"""',
262+
content,
263+
)
248264

249265
if not version_match:
250266
return None
251267

252268
version = version_match.group(1)
253-
description = description_match.group(1) if description_match else "No description available."
269+
description = (
270+
description_match.group(1)
271+
if description_match
272+
else "No description available."
273+
)
254274
return version, description
255275

256276
except Exception as e:
257277
print(f"Error checking for updates: {e}")
258-
return None
278+
return None

0 commit comments

Comments
 (0)