-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move processing logic from db and update number processing
- Loading branch information
Showing
5 changed files
with
46 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('.', '')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters