Skip to content

Commit

Permalink
refresh token bugfix and log scroll to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
gogodr committed Apr 30, 2022
1 parent ed61580 commit 1240c11
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## LostArk Market Watcher 0.4.4
## LostArk Market Watcher 0.4.6
This app listens to the screenshot folder for new files.
Starting on the version 0.3.0 this app needs to be launched through the [Lost Ark Market Launcher](https://github.com/gogodr/LostArk-Market-Launcher)
Each new file is scanned and if the market window is detected in the picture then the image is segmented.
Expand Down Expand Up @@ -28,6 +28,10 @@ Audio files from [MixKit](https://mixkit.co/)
- Add Gold / Royal Crystal / Blue Crystal converstions support

### Changelog
### 0.4.6
- Bugfix: Refresh season token every 30 minutes
- Log: Scroll to bottom automatically

### 0.4.5
- Add Adventure Tome items

Expand Down
2 changes: 1 addition & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ui.config.config import LostArkMarketWatcherConfig
from ui.log.log import LostArkMarketWatcherLog

version = '0.4.5'
version = '0.4.6'
debug = False


Expand Down
56 changes: 40 additions & 16 deletions modules/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import traceback
from datetime import datetime
from datetime import datetime, timedelta
from slugify import slugify
from google.oauth2.credentials import Credentials
from google.cloud.firestore import Client
Expand All @@ -17,30 +17,54 @@


class MarketDb(QObject):
log = Signal(str)
region = None
creds = None
db = None
uid = None
log: Signal = Signal(str)
region: str = None
id_token: str = None
refresh_token: str = None
uid: str = None
creds: Credentials = None
db: Client = None
last_refresh: datetime = None

def __init__(self):
try:
super(MarketDb, self).__init__()
_, self.refresh_token, _ = get_tokens()
self.id_token, self.refresh_token, self.uid = refresh_token(
self.refresh_token)
self.creds = Credentials(
token=self.id_token,
refresh_token=self.refresh_token
)
super(MarketDb, self).__init__()
self.refresh_credentials()
self.db = Client(project=project, credentials=self.creds)
self.region = self.db.document(
f'collaborators/{self.uid}').get().get('region')
except NoTokenError:
traceback.print_exc()

def refresh_credentials(self):
needs_refresh = False
if self.last_refresh is None:
needs_refresh = True
elif self.last_refresh + timedelta(minutes=30) < datetime.now():
needs_refresh = True

if needs_refresh:
self.log.emit(f"Refresh credentials")
try:
if self.refresh_token is None:
_, self.refresh_token, _ = get_tokens()
self.id_token, self.refresh_token, self.uid = refresh_token(
self.refresh_token)
self.creds = Credentials(
token=self.id_token,
refresh_token=self.refresh_token
)
self.last_refresh = datetime.now()
except:
self.error.emit("Error getting credentials")
self.error.emit(traceback.format_exc)


def add_entry(self, market_line: MarketLine, play_audio=True):
try:
# Refresh credentials if needed
self.refresh_credentials()

# Get item data based on dictionary
item = process_item(market_line)

Expand Down Expand Up @@ -79,7 +103,7 @@ def add_entry(self, market_line: MarketLine, play_audio=True):
if play_audio == True:
playPulse()
except:
self.log.emit(f"Add Entry Failed: {market_line.name}")
self.error.emit(f"Add Entry Failed: {market_line.name}")
self.error.emit(traceback.format_exc())
if play_audio == True:
playError()
traceback.print_exc()
5 changes: 4 additions & 1 deletion ui/log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QListWidgetItem
from PySide6.QtWidgets import QApplication, QMainWindow, QListWidgetItem, QListWidget
from PySide6.QtCore import QFile, Qt, Signal
from PySide6.QtUiTools import QUiLoader
from PySide6.QtGui import QColor
Expand All @@ -30,6 +30,8 @@ def load_ui(self):
self.ui.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)
self.ui.btnClose.clicked.connect(self.close)
self.ui.lLog.setWordWrap(True)
self.ui.lLog.setAutoScroll(True)
self.ui.lLog.setAutoScrollMargin(20)
self.ui.lblTitle.setText(
f"Lost Ark Market Watcher v{self.version} - {self.region} - Log")
ui_file.close()
Expand All @@ -53,6 +55,7 @@ def log(self, txt, error=False, save_log=False):
with open(f'{datetime.now().strftime("%m-%d-%Y")}.log', "a") as file_object:
file_object.write(f"{log_txt}\n")
self.ui.lLog.addItem(i)
self.ui.lLog.scrollToBottom()


if __name__ == "__main__":
Expand Down

0 comments on commit 1240c11

Please sign in to comment.