From 0a941529ebf5d62dfe3c1ab88868e468b4a223b0 Mon Sep 17 00:00:00 2001 From: Gogodr Date: Wed, 20 Apr 2022 13:27:20 -0500 Subject: [PATCH] move processing logic from db and update number processing --- README.md | 2 +- index.py | 6 +++--- modules/db.py | 18 ++++++++++++------ modules/process.py | 38 +++++++++++++++++++++++++++++--------- modules/scan.py | 2 +- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f8078ea..98f313b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## LostArk Market Watcher 0.1.1 +## LostArk Market Watcher 0.1.3 This app listens to the screenshot folder for new files. Each new file is scanned and if the market window is detected in the picture then the image is segmented. Each segment then is parsed usin Tesseract OCR and classified diff --git a/index.py b/index.py index 9dd537f..ab18814 100644 --- a/index.py +++ b/index.py @@ -13,7 +13,7 @@ import pystray from PIL import Image -version = '0.1.1' +version = '0.1.3' screenshootsdir, region = checkconfig() firestore = None observer = None @@ -30,8 +30,8 @@ def on_created(event): res = scan(event.src_path) for item in res: playPulse() - firestore.add_entry(name=item['name'], avg_price=item['avgPrice'], - cheapest_remaining=item['cheapestRemaining'], low_price=item['lowPrice'], recent_price=item['recentPrice']) + print(item) + firestore.add_entry(item) playSuccess() except: playError() diff --git a/modules/db.py b/modules/db.py index b77ab76..f709b24 100644 --- a/modules/db.py +++ b/modules/db.py @@ -67,8 +67,7 @@ def __init__(self, region): else: self.login() - def add_entry(self, name, avg_price, cheapest_remaining, low_price, recent_price): - item = get_market_item_by_name(name) + def add_entry(self, item): item_doc = self.db.collection(self.region).where( 'name', '==', item['name']).get() @@ -77,11 +76,18 @@ def add_entry(self, name, avg_price, cheapest_remaining, low_price, recent_price self.region).add(document_data=item) else: item_doc = item_doc[0] + self.db.collection(self.region).document(item_doc.id).update({ + 'avgPrice': item['avgPrice'], + 'cheapestRemaining': item['cheapestRemaining'], + 'lowPrice': item['lowPrice'], + 'recentPrice': item['recentPrice'], + 'updatedAt': datetime.utcnow() + }) self.db.collection(self.region).document(item_doc.id).collection('entries').add({ - 'avgPrice': avg_price, - 'cheapestRemaining': cheapest_remaining, - 'lowPrice': low_price, - 'recentPrice': recent_price, + 'avgPrice': item['avgPrice'], + 'cheapestRemaining': item['cheapestRemaining'], + 'lowPrice': item['lowPrice'], + 'recentPrice': item['recentPrice'], 'createdAt': datetime.utcnow() }) diff --git a/modules/process.py b/modules/process.py index 36b36ce..29acf58 100644 --- a/modules/process.py +++ b/modules/process.py @@ -1,21 +1,41 @@ +import re + +from modules.market import get_market_item_by_name def process_items(raw): items = [] for chain in raw: name = chain[0].strip() - if name.find('[Sold in bundles of 10 units]') > 0: - name = name[0:name.find('[Sold in bundles of 10 units]')].strip() - if name.find('[Sold in bundles of 100 units]') > 0: - name = name[0:name.find('[Sold in bundles of 100 units]')].strip() - avg_price = float(chain[1].replace(',', '')) - recent_price = float(chain[2].replace(',', '')) - low_price = float(chain[3].replace(',', '')) - cheapest_remaining = int(chain[4].replace(',', '').replace('.', '')) + if name.find('[Sold in bundles') > 0: + name = name[0:name.find('[Sold in bundles')].strip() + + item = get_market_item_by_name(name) + if item is None: + continue + + avg_price = process_number(chain[1]) + recent_price = process_number(chain[2]) + low_price = process_number(chain[3]) + cheapest_remaining = process_number(chain[4]) + items.append({ - 'name': name, + 'name': item['name'], + 'amount': item['amount'], + 'image': item['image'], + 'category': item['category'], + 'subcategory': item['subcategory'], + 'rarity': item['rarity'], 'avgPrice': avg_price, 'recentPrice': recent_price, 'lowPrice': low_price, 'cheapestRemaining': cheapest_remaining }) return items + +def process_number(n): + test = re.search('(\.\d)$', n) + if test is not None: + return (int(n[0:test.start(0)].replace('.', '')) + + (int(n[test.start(0)+1:]) / 10)) + else: + return int(n.replace('.', '')) \ No newline at end of file diff --git a/modules/scan.py b/modules/scan.py index a6513ea..e28e898 100644 --- a/modules/scan.py +++ b/modules/scan.py @@ -125,7 +125,7 @@ def process_cropped(screenshoot, rec, i, a): pimg, lang='eng', config='--psm 6 -c tessedit_char_blacklist=!') else: e_text = pytesseract.image_to_string( - pimg, lang='eng', config='--psm 13 --oem 1 -c tessedit_char_whitelist=0123456789,.') + pimg, lang='eng', config='--psm 13 --oem 1 -c tessedit_char_whitelist=0123456789.') return e_text