Repository navigation
Expand file tree
/
Copy pathdatabase.py
More file actions
173 lines (167 loc) · 4.99 KB
/
Copy pathdatabase.py
File metadata and controls
173 lines (167 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import sqlite3
import json
import time
DB_PATH = "auctions.db"
def get_db_connection():
conn = sqlite3.connect(DB_PATH,timeout=15)
return conn
def create_tables(conn):
conn.execute(
"""
CREATE TABLE IF NOT EXISTS item_listings (
uuid TEXT PRIMARY KEY,
item_id TEXT,
name TEXT,
price INTEGER,
reforge TEXT,
enchantments TEXT,
tier TEXT,
rarity_upgrades INTEGER,
dye_item TEXT,
hot_potato_count INTEGER,
gemstones TEXT,
dungeon_item_level INTEGER,
bin INTEGER,
start INTEGER,
end INTEGER
)
""")
conn.execute(
"""
CREATE TABLE IF NOT EXISTS pet_listings (
uuid TEXT PRIMARY KEY,
species TEXT,
pet_tier TEXT,
exp REAL,
held_item TEXT,
skin TEXT,
candy_used INTEGER,
price INTEGER,
bin INTEGER,
start INTEGER,
end INTEGER
)
"""
)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS ended_auctions (
auction_id TEXT PRIMARY KEY,
item_id TEXT,
name TEXT,
quantity INTEGER,
price INTEGER,
bin INTEGER,
sold_at INTEGER,
enchantments TEXT,
rarity_upgrades INTEGER,
bids TEXT,
hot_potato_count INTEGER,
gemstones TEXT,
reforge TEXT,
dungeon_item_level INTEGER
)
"""
)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS bazaar_prices (
product_id TEXT PRIMARY KEY,
instabuy REAL,
instasell REAL,
buy_volume INTEGER,
sell_volume INTEGER,
updated_at INTEGER
)
"""
)
conn.execute(
"""
CREATE INDEX IF NOT EXISTS idx_ended_auctions_item_bin_sold
ON ended_auctions (item_id, bin, sold_at)
"""
)
conn.execute(
"""
CREATE INDEX IF NOT EXISTS idx_item_listings_bin
ON item_listings (bin)
"""
)
conn.commit()
def insert_item_listing(conn, item_data, auction):
conn.execute(
"""
INSERT OR REPLACE INTO item_listings (
uuid, item_id, name, price, reforge, enchantments, tier, rarity_upgrades, dye_item, hot_potato_count, gemstones, dungeon_item_level, bin, start, end
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
auction["uuid"],
item_data["item_id"],
item_data["name"],
auction["starting_bid"],
item_data["reforge"],
json.dumps(item_data["enchantments"]),
item_data["tier"],
item_data["rarity_upgrades"],
item_data["dye_item"],
item_data["hot_potato_count"],
item_data["gemstones"],
item_data["dungeon_item_level"],
int(auction.get("bin", False)),
auction["start"],
auction["end"],
)
)
def insert_pet(conn, pet_data, auction):
conn.execute("""
INSERT OR REPLACE INTO pet_listings
(uuid, species, pet_tier, exp, held_item, skin, candy_used,
price, bin, start, end)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
auction["uuid"],
pet_data["species"],
pet_data["pet_tier"],
pet_data["exp"],
pet_data["held_item"],
pet_data["skin"],
pet_data["candy_used"],
auction["starting_bid"],
int(auction.get("bin", False)),
auction["start"],
auction["end"],
)
)
def insert_ended_auction(conn, sold_data, auction):
conn.execute("""
INSERT OR REPLACE INTO ended_auctions
(auction_id, item_id, name, quantity, price, bin, sold_at, enchantments, rarity_upgrades, bids, hot_potato_count, gemstones, reforge, dungeon_item_level)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
auction["auction_id"],
sold_data["item_id"],
sold_data.get("name", ""),
sold_data["quantity"],
auction["price"],
int(auction.get("bin", False)),
auction["timestamp"],
sold_data.get("enchantments", "[]"),
sold_data.get("rarity_upgrades", 0),
json.dumps(auction.get("bids", [])),
sold_data.get("hot_potato_count", 0),
sold_data.get("gemstones", "{}"),
sold_data.get("reforge", ""),
sold_data.get("dungeon_item_level", 0),
)
)
def upsert_bazaar_prices(conn,prices):
now = int(time.time() * 1000)
conn.executemany("""
INSERT OR REPLACE INTO bazaar_prices
(product_id, instabuy, instasell, buy_volume, sell_volume, updated_at)
VALUES (?, ?, ?, ?, ?, ?)
""", [
(pid, p["instabuy"], p["instasell"], p["buy_volume"], p["sell_volume"], now)
for pid, p in prices.items()
])