-
Notifications
You must be signed in to change notification settings - Fork 56
/
init_db.py
34 lines (25 loc) · 1 KB
/
init_db.py
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
import sqlite3
def main():
connection = sqlite3.connect("database.db")
with open("pokedex/schema.sql") as f:
connection.executescript(f.read())
cur = connection.cursor()
with open("pokemon.txt") as file:
lines = file.readlines()
pokemon_number = 1
for line in lines:
name, description = line.split(";")
cur.execute(
f"INSERT INTO POKEDEX (id, pokemon_name, image_url, description) VALUES ("
f"{pokemon_number}, "
f'"{name}", '
f'"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{pokemon_number}.png", '
f'"{description}")'
)
pokemon_number += 1
cur.execute('INSERT INTO SUBSCRIBERS (id, email) VALUES (1, "[email protected]")')
cur.execute('INSERT INTO SUBSCRIBERS (id, email) VALUES (2, "[email protected]")')
connection.commit()
connection.close()
if __name__ == '__main__':
main()