Skip to content

Commit 26fa2ba

Browse files
authored
!stalks: overwrite buys, rename table to 'price' (#14)
1 parent e92d53e commit 26fa2ba

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

acnh.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS user (
55
timezone TEXT
66
);
77

8-
CREATE TABLE IF NOT EXISTS sell_price (
8+
CREATE TABLE IF NOT EXISTS price (
99
user_id TEXT,
1010
week_local TEXT,
1111
week_index INTEGER,
@@ -14,8 +14,8 @@ CREATE TABLE IF NOT EXISTS sell_price (
1414
FOREIGN KEY(user_id) REFERENCES user(id)
1515
);
1616

17-
CREATE UNIQUE INDEX IF NOT EXISTS idx_sell_price_user_expiration
18-
ON sell_price (user_id, expiration);
17+
CREATE UNIQUE INDEX IF NOT EXISTS idx_price_user_expiration
18+
ON price (user_id, expiration);
1919

2020
CREATE TABLE IF NOT EXISTS sell_trigger (
2121
user_id TEXT PRIMARY KEY,

animal_crossing.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def _stalk_set_buy_price(cmd, price):
8080
week_local, _, expiration = _user_time_info(user_time)
8181
with db:
8282
db.execute('''
83-
INSERT INTO sell_price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
83+
INSERT INTO price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
84+
ON CONFLICT(user_id, expiration) DO UPDATE SET price = excluded.price
8485
''', (user_id, week_local, 0, expiration.astimezone(datetime.timezone.utc), value))
8586

8687
expires_in = readable_rel(expiration - user_time)
@@ -91,7 +92,7 @@ def _stalk_list_buy_prices(cmd):
9192
current_time = datetime.datetime.now(datetime.timezone.utc)
9293
sunday = _date_to_sunday(current_time)
9394
cur = db.execute('''
94-
SELECT username, expiration, price FROM sell_price
95+
SELECT username, expiration, price FROM price
9596
JOIN user ON user_id = user.id
9697
WHERE week_local = ? AND week_index = 0
9798
''', (str(sunday),))
@@ -157,17 +158,17 @@ def _stalk_set_sell_price(cmd, price):
157158
week_local, week_index, expiration = _user_time_info(user_time)
158159
with db:
159160
db.execute('''
160-
INSERT INTO sell_price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
161+
INSERT INTO price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
161162
ON CONFLICT(user_id, expiration) DO UPDATE SET price = excluded.price
162163
''', (user_id, week_local, week_index, expiration.astimezone(datetime.timezone.utc), value))
163164

164165
sunday = _date_to_sunday(current_time)
165166
with db:
166-
cur = db.execute('SELECT week_index, price FROM sell_price WHERE user_id = ? AND week_local = ?',
167+
cur = db.execute('SELECT week_index, price FROM price WHERE user_id = ? AND week_local = ?',
167168
(user_id, str(sunday),))
168-
week_rows = cur.fetchall()
169+
week_price_rows = cur.fetchall()
169170
week_prices = [None] * 13
170-
for row in week_rows:
171+
for row in week_price_rows:
171172
week_prices[row['week_index']] = row['price']
172173

173174
expires_in = readable_rel(expiration - user_time)
@@ -193,7 +194,7 @@ def _stalk_list_sale_prices(cmd):
193194
sunday = _date_to_sunday(current_time)
194195
cur = db.execute('''
195196
SELECT username, week_index, expiration, price
196-
FROM sell_price
197+
FROM price
197198
JOIN user ON user_id = user.id
198199
WHERE week_local == ?
199200
''', (str(sunday),))
@@ -291,8 +292,8 @@ def _turnip_prophet(week_prices):
291292

292293
def migrate(dry_run):
293294
with db:
294-
cur = db.execute('''SELECT user_id, expiration, price, timezone FROM sell_price
295-
JOIN user ON sell_price.user_id = user.id''')
295+
cur = db.execute('''SELECT user_id, expiration, price, timezone FROM price
296+
JOIN user ON price.user_id = user.id''')
296297
rows = cur.fetchall()
297298
print('migrating', len(rows), 'rows; dry-run:', dry_run)
298299
if not dry_run:

0 commit comments

Comments
 (0)