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
|
import argparse
import sqlite3
import random
import csv
ap = argparse.ArgumentParser()
ap.add_argument('output', help='the file to output the database to')
ap.add_argument('input', help='a csv file to read from. if a row has one cell, that is the name of the entry. if a row has two cells, the first is the name of the entry, and the second is either a unicode emoji or a discord emoji id for the entry.')
ap.add_argument('-s', '--shuffle', help='shuffle entries. by default, entries are in the order they appear in the csv.', action='store_true')
a = ap.parse_args()
entries = []
# csv rows are either "name" or "name, emoji"
with open(a.input, newline='') as file:
reader = csv.reader(file)
for row in reader:
if len(row) == 0:
continue
if len(row) <= 2:
entries.append(list(map(lambda x: x.strip(), row)))
else:
print('encountered a row with more than two cells')
exit(1)
if a.shuffle:
random.shuffle(entries)
dbcon = sqlite3.connect(a.output)
cur = dbcon.cursor()
cur.execute('''
CREATE TABLE entries(
name TEXT UNIQUE NOT NULL,
emoji TEXT,
status INT NOT NULL,
last_poll_number INT NOT NULL,
sort_number INT UNIQUE NOT NULL
)
''')
cur.execute('''
CREATE TABLE polls(
poll_number INT UNIQUE NOT NULL,
entry_1 TEXT NOT NULL,
entry_2 TEXT NOT NULL,
posted INT NOT NULL,
expires INT NOT NULL,
channel_id TEXT NOT NULL,
message_id TEXT NOT NULL,
voters_1 TEXT,
voters_2 TEXT
)
''')
cur.execute('''
CREATE TABLE users(
id TEXT UNIQUE NOT NULL,
global_display TEXT NOT NULL,
avatar_hash TEXT,
retrieved INT NOT NULL
)
''')
for i, row in enumerate(entries):
name = row[0]
emoji = row[1] if len(row) > 0 else None
cur.execute('INSERT INTO entries VALUES(?, ?, 0, 0, ?)', (name, emoji, i))
dbcon.commit()
|