Skip to content

Commit

Permalink
move processing logic from db and update number processing
Browse files Browse the repository at this point in the history
  • Loading branch information
gogodr committed Apr 20, 2022
1 parent a854eec commit 0a94152
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
18 changes: 12 additions & 6 deletions modules/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
})
38 changes: 29 additions & 9 deletions modules/process.py
Original file line number Diff line number Diff line change
@@ -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('.', ''))
2 changes: 1 addition & 1 deletion modules/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0a94152

Please sign in to comment.