|
@@ -5,9 +5,11 @@ from selenium.webdriver.common.keys import Keys
|
|
|
from selenium.webdriver.common.by import By
|
|
|
from datetime import datetime
|
|
|
import pandas as pd
|
|
|
+from tinydb import Query
|
|
|
import json
|
|
|
from player import Player
|
|
|
from config import Config
|
|
|
+from db import MarketDB
|
|
|
|
|
|
@dataclass
|
|
|
class Market():
|
|
@@ -83,3 +85,25 @@ class Market():
|
|
|
def show(self):
|
|
|
pdf=self.df.drop(['link','card-id','phid'], axis=1)
|
|
|
print(pdf.to_string(index=False))
|
|
|
+
|
|
|
+ def commit(self):
|
|
|
+ today=self.asOf.strftime('%Y-%m-%d')
|
|
|
+ current=MarketDB.search(Query()['date']==today)
|
|
|
+ if len(current)==0:
|
|
|
+ for Card in self.Cards:
|
|
|
+ thisCard={}
|
|
|
+ thisCard['date'] = today
|
|
|
+ thisCard['count'] = 1
|
|
|
+ thisCard['card-num'] = Card['card-num']
|
|
|
+ thisCard['name'] = Card['name']
|
|
|
+ thisCard['qty'] = Card['qty']
|
|
|
+ thisCard['cost'] = Card['cost']
|
|
|
+ MarketDB.insert(thisCard)
|
|
|
+ else:
|
|
|
+ for Card in self.Cards:
|
|
|
+ thisCard=MarketDB.search(Query().fragment({'date':today,'card-num':Card['card-num']}))[0]
|
|
|
+ newData={}
|
|
|
+ newData['count']=thisCard['count']+1
|
|
|
+ newData['cost']=(thisCard['count']*thisCard['cost']+Card['cost'])/(thisCard['count']+1)
|
|
|
+ newData['qty']=(thisCard['count']*thisCard['qty']+Card['qty'])/(thisCard['qty']+1)
|
|
|
+ MarketDB.update(newData,Query().fragment({'date':today,'card-num':Card['card-num']}))
|