|
|
|
@ -0,0 +1,55 @@ |
|
|
|
import copy |
|
|
|
import sys |
|
|
|
from quad_dialog import message,dicter |
|
|
|
import datetime |
|
|
|
import sqlite3 |
|
|
|
import pandas |
|
|
|
from decimal import Decimal as D |
|
|
|
import shutil |
|
|
|
from send2trash import send2trash |
|
|
|
import gc |
|
|
|
def test(): |
|
|
|
con = sqlite3.connect('test.db') |
|
|
|
cur = con.cursor() |
|
|
|
date = '2018-08-18' |
|
|
|
# print(date) |
|
|
|
quad_links = list(row[0] for row in cur.execute('SELECT link FROM links ORDER BY id')) |
|
|
|
quad_parts_base = pandas.read_sql('SELECT * FROM names',con).to_dict('records') |
|
|
|
|
|
|
|
current = copy.deepcopy(quad_parts_base) |
|
|
|
complete = None |
|
|
|
while not complete: |
|
|
|
complete = pandas.read_sql('SELECT * FROM parts where date == "{}"'.format(date),con).to_dict('records') |
|
|
|
if not complete: |
|
|
|
reset() |
|
|
|
# print(complete) |
|
|
|
for item in current: |
|
|
|
name = item['name'] |
|
|
|
link = item['link'] |
|
|
|
# print(link) |
|
|
|
item['product_name'] = complete[link]['product_name'] |
|
|
|
item['price'] = round(D(complete[link]['price']),2) |
|
|
|
item['time'] = complete[link]['time'] |
|
|
|
print(current) |
|
|
|
bought = message(quad_parts_base,current) |
|
|
|
|
|
|
|
quad_parts_base = dicter(quad_parts_base) |
|
|
|
for key,is_purchased in bought.items(): |
|
|
|
if is_purchased: |
|
|
|
# print(key) |
|
|
|
try: |
|
|
|
if quad_parts_base[key]['count'] > 1: |
|
|
|
cur.execute('UPDATE names SET count = count - 1 WHERE name == ?',(key,)) |
|
|
|
else: |
|
|
|
cur.execute('UPDATE names SET purchased = 1 WHERE name == ?',(key,)) |
|
|
|
except: |
|
|
|
print(quad_parts_base) |
|
|
|
con.commit() |
|
|
|
con.close() |
|
|
|
|
|
|
|
def reset(): |
|
|
|
try: |
|
|
|
send2trash('test.db') |
|
|
|
except: |
|
|
|
pass |
|
|
|
shutil.copy('quadparts.db','test.db') |