Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DATABSE.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in file name

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Static Database

There is a file named 'backend/database.py' which populates a database (celesta.sqlite3) with the values from database_csv.csv.

If you'd like to add to the database, then just delete the database (celesta.sqlite3), modify the csv file, then run database.py again.
14 changes: 14 additions & 0 deletions backend/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import csv, sqlite3

con = sqlite3.connect("celesta.sqlite3") # change to 'sqlite:///your_filename.db'
cur = con.cursor()
cur.execute("CREATE TABLE member_info (id, first_name, last_name, email, member_type, faculty, watiam);") # use your column names here

with open('database_csv.csv','r', encoding='utf-8-sig') as fin: # `with` statement available in 2.5+
# csv.DictReader uses first line in file for column headings by default
dr = csv.DictReader(fin) # comma is default delimiter
to_db = [(i['id'], i['first_name'], i['last_name'], i['email'], i['member_type'], i['faculty'], i['watiam']) for i in dr]

cur.executemany("INSERT INTO member_info (id, first_name, last_name, email, member_type, faculty, watiam) VALUES (?, ?, ?, ? , ? , ? , ?);", to_db)
con.commit()
con.close()
Binary file added celesta.sqlite3
Binary file not shown.
25 changes: 25 additions & 0 deletions database_csv.csv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some more name and email formats? i.e. multi-word and hyphenated names (first and last), emails with numbers, non-uwaterloo emails

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
id,first_name,last_name,email,member_type,faculty,watiam
1,Sandra,Smith,[email protected],UNDERGRAD,ARTS,22477440
2,Danny,Boy,[email protected],GRADUATE,ENGINEERING,83621326
3,John,Williams,[email protected],ALUMNI,ENVIRONMENT,33482924
4,Smith,McJohns,[email protected],OTHER,HEALTH,99034687
5,Ally,Zebra,[email protected],UNDERGRAD,MATHEMATICS,94081876
6,Nurse,Joy,[email protected],GRADUATE,SCIENCE,92592349
7,Patrick,Davis,[email protected],ALUMNI,ARTS,29581142
8,Mana,Gere,[email protected],OTHER,ENGINEERING,31897808
9,Ray,Cruter,[email protected],UNDERGRAD,ENVIRONMENT,3395336
10,Giva,Rase,[email protected],GRADUATE,HEALTH,74975624
11,Dr ,Boomer,[email protected],ALUMNI,MATHEMATICS,32291797
12,Valerie,Torian,[email protected],OTHER,SCIENCE,77356045
13,Dig,Gits,[email protected],UNDERGRAD,ARTS,45683365
14,Suzy,Shaker,[email protected],GRADUATE,ENGINEERING,97930969
15,Cowen,Corr,[email protected],ALUMNI,ENVIRONMENT,1494307
16,Sina,Mattek,[email protected],OTHER,HEALTH,27733029
17,Engie,Chan,[email protected],UNDERGRAD,MATHEMATICS,5808933
18,King,Warrior,[email protected],GRADUATE,SCIENCE,83267579
19,Sean,Paul,[email protected],ALUMNI,ARTS,78629181
20,Juan,Paul,[email protected],OTHER,ENGINEERING,99553475
21,Sara,Colic,[email protected],UNDERGRAD,ENVIRONMENT,24045355
22,Teddy,Tzu,[email protected],GRADUATE,HEALTH,21386996
23,Anotha,Won,[email protected],ALUMNI,MATHEMATICS,50165059
24,Vivek,Goel,[email protected],OTHER,SCIENCE,1005502
Binary file removed db.sqlite3
Binary file not shown.