summaryrefslogtreecommitdiff
path: root/make-db.py
diff options
context:
space:
mode:
Diffstat (limited to 'make-db.py')
-rw-r--r--make-db.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/make-db.py b/make-db.py
new file mode 100644
index 0000000..e639110
--- /dev/null
+++ b/make-db.py
@@ -0,0 +1,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()