-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
40 lines (30 loc) · 1.68 KB
/
init.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
35
36
37
38
39
40
################################################################################
# Initializes the database for user login/storage #
# #
# Authors #
# Yicheng Wang #
# #
# Description #
# Initializes database in db/ for user login and storage #
# #
################################################################################
# Dev Log
# Project Created: 2015-12-19 12:42 - Yicheng W.
import sqlite3
from hashlib import sha256
from database import *
from sys import argv
conn = sqlite3.connect("./db/infos.db")
c = conn.cursor()
create_base = "CREATE TABLE %s (%s)" # no user input needed, use %s
# password = hexstring of hash
c.execute(create_base % ("users", "email TEXT, password TEXT, first TEXT, last TEXT"))
# note will be html source code with markup
c.execute(create_base % ("sites", "id INTEGER, email TEXT, title TEXT, site TEXT, comments TEXT, notes TEXT, shared INTEGER, t INTEGER"))
if '--test' in argv or '-t' in argv:
m = sha256()
m.update("12345")
password = m.hexdigest()
c.execute('insert into users values("[email protected]", "%s", "Yicheng", "Wang")' % password)
c.execute('insert into sites values(0, "[email protected]", "test", "test", "", "", 0, 0)')
conn.commit()