Add new flags.

This commit is contained in:
Matúš Tejiščák 2024-02-13 10:59:33 +01:00
parent ef214535dd
commit ba919f8e0a
2 changed files with 11 additions and 4 deletions

View File

@ -46,14 +46,20 @@ while Q:
)
resp.raise_for_status()
z = resp.json()['result']
log.info('%s (%d) + %s (%d) -> %s', x, x_rank, y, y_rank, z)
response = resp.json()
z = response['result']
is_new = response['isNew']
log.info(
'%s (%d) + %s (%d) -> %s%s',
x, x_rank, y, y_rank, z,
' [NEW!]' if is_new else ''
)
z_rank = 1+max(x_rank, y_rank)
db.execute('''
insert into words (word, rank) values (?, ?)
insert into words (word, rank, is_new) values (?, ?, ?)
on conflict(word) do update set rank = ? where rank > ?
''', (z, z_rank, z_rank, z_rank))
''', (z, z_rank, is_new, z_rank, z_rank))
db.executemany(
'insert or ignore into combos (x, y, z) values (?, ?, ?)',

View File

@ -1,5 +1,6 @@
CREATE TABLE words (
word text not null,
is_new boolean not null,
rank integer not null,
primary key (word)
);