Skip to content

Commit

Permalink
Unauthenticated handling and update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gogodr committed May 23, 2022
1 parent 1dcd3e3 commit 302f2ae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ def process_screenshot(self, file):
time.sleep(1)
if Config().delete_screenshots == True:
os.remove(file)
except:
except Exception as ex:
if Config().play_audio == True:
playError()
AppLogger().error(traceback.format_exc())
AppLogger().exception(ex)

def new_version(self, new_version):
self.message_box.emit({"type": "REGION", "new_version": new_version})
Expand Down
2 changes: 1 addition & 1 deletion modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class Config(metaclass=Singleton):
version = "0.8.3"
version = "0.8.4"
region: str
game_region: str
debug = False
Expand Down
27 changes: 15 additions & 12 deletions modules/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from modules.sound import playError, playPulse
from PySide6.QtCore import Signal, QObject
from packaging import version
from google.api_core.exceptions import Unauthenticated

project = 'lostarkmarket-79ddf'

Expand All @@ -34,11 +35,11 @@ def __init__(self):
AppLogger().info(f"Got Watcher Region: '{Config().region}'")
self.db.document(
"app-info/market-watcher").on_snapshot(self.new_version_cb)
except NoTokenError:
AppLogger().error(traceback.format_exc)
except NoTokenError as ex:
AppLogger().exception(ex)

def refresh_credentials(self):
if (self.last_refresh is None) or (self.last_refresh + timedelta(minutes=30) < datetime.now()):
def refresh_credentials(self, forced=False):
if (self.last_refresh is None) or (self.last_refresh + timedelta(minutes=30) < datetime.now()) or forced:
AppLogger().info(f"Refresh credentials")
try:
refresh_token()
Expand All @@ -47,12 +48,10 @@ def refresh_credentials(self):
refresh_token=Config().refresh_token
)
self.last_refresh = datetime.now()
except:
traceback.print_exc()
AppLogger().error("Error getting credentials")
AppLogger().error(traceback.format_exc)
except Exception as ex:
AppLogger().exception(ex)

def add_entry(self, market_line: MarketLine):
def add_entry(self, market_line: MarketLine, retries: int = 0):
try:
# Refresh credentials if needed
self.refresh_credentials()
Expand Down Expand Up @@ -106,15 +105,19 @@ def add_entry(self, market_line: MarketLine):
'author': Config().uid,
'watcher_version': Config().version
})

AppLogger().info(
f"Updated: {market_line.name} | {market_line.avg_price} | {market_line.recent_price} | {market_line.lowest_price} | {market_line.cheapest_remaining}")
if Config().play_audio:
playPulse()
except:
except Unauthenticated:
self.refresh_credentials(True)
if retries < 3:
self.add_entry(market_line, retries + 1)

except Exception as ex:
AppLogger().error(
f"Failed: {market_line.name} | {market_line.avg_price} | {market_line.recent_price} | {market_line.lowest_price} | {market_line.cheapest_remaining}")
AppLogger().error(traceback.format_exc())
AppLogger().exception(ex)
if Config().play_audio:
playError()

Expand Down
14 changes: 6 additions & 8 deletions modules/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from modules.common.singleton import Singleton
from modules.config import Config

from PySide6.QtCore import Signal, QObject

import logging
import os

Expand Down Expand Up @@ -101,12 +99,12 @@ def signal_enable(self, signal):
self.signal_handler_info.addFilter(LoggingFilter(logging.INFO))
self.logger.addHandler(self.signal_handler_info)

if self.file_handler_error is None:
self.file_handler_error = SignalHandler(signal)
self.file_handler_error.setFormatter(self.log_formatter)
self.file_handler_error.setLevel(logging.ERROR)
self.file_handler_error.addFilter(LoggingFilter(logging.ERROR))
self.logger.addHandler(self.file_handler_error)
if self.signal_handler_error is None:
self.signal_handler_error = SignalHandler(signal)
self.signal_handler_error.setFormatter(self.log_formatter)
self.signal_handler_error.setLevel(logging.ERROR)
self.signal_handler_error.addFilter(LoggingFilter(logging.ERROR))
self.logger.addHandler(self.signal_handler_error)

def signal_disable(self):
if self.signal_handler_info:
Expand Down
2 changes: 1 addition & 1 deletion modules/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def match_market(screenshot, tab="market") -> typing.Tuple[float, typing.Tuple[i
_, maxVal, _, maxLoc = cv2.minMaxLoc(res)

if Config().debug == True:
print(f"{tab}: {maxVal}")
AppLogger().debug(f"{tab}: {maxVal}")
if maxVal > threshold:
screenshot = cv2.rectangle(
screenshot, (maxLoc[0], maxLoc[1]), (maxLoc[0]+sample.shape[1], maxLoc[1]+sample.shape[0]), (0, 0, 255), 2)
Expand Down
5 changes: 3 additions & 2 deletions ui/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PySide6.QtWidgets import QMainWindow, QFileDialog
from PySide6.QtCore import QFile, Qt, Signal
from PySide6.QtGui import QIcon
from modules.logging import AppLogger
from modules.sound import VolumeController

from ui.common.draggablewindow import DraggableWindow
Expand Down Expand Up @@ -122,5 +123,5 @@ def show_ui(self):
self.cbPlaySounds.setChecked(Config().play_audio)
self.slVolume.setValue(Config().volume)
self.show()
except:
traceback.print_exc()
except Exception as ex:
AppLogger().exception(ex)

0 comments on commit 302f2ae

Please sign in to comment.