-
Notifications
You must be signed in to change notification settings - Fork 0
/
from_csv.py
37 lines (26 loc) · 1.01 KB
/
from_csv.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
# add the records in csv file to the database at dna_str table
import csv
from cs50 import SQL
from helpers import hash_str
# open the database
db = SQL("sqlite:///dna_str_db.db")
# open the csv file
with open("large.csv", "r") as file:
reader = csv.DictReader(file)
# iterate over the csv file
for row in reader:
# get the STR counts
STRs = ["AGATC", "TTTTTTCT", "AATG", "TCTAG", "GATA", "TATC", "GAAA", "TCTG"]
count = []
for STR in STRs:
count.append(int(row[STR]))
# print the STR counts
print(count)
# print name
print(row["name"])
# add the new DNA STR to the database
try:
db.execute("INSERT INTO dna_str (owner_name, hashed, AGATC, TTTTTTCT, AATG, TCTAG, GATA, TATC, GAAA, TCTG) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
row["name"], hash_str(count), count[0], count[1], count[2], count[3], count[4], count[5], count[6], count[7])
except:
print("Error")