-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc4e157
commit 8e6e26a
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
id|first_name|last_name|middle_name|party | ||
33|Joseph|Biden||D | ||
36|Samuel|Brownback||R | ||
34|Hillary|Clinton|R.|D | ||
39|Christopher|Dodd|J.|D | ||
26|John|Edwards||D | ||
22|Rudolph|Giuliani||R | ||
24|Mike|Gravel||D | ||
16|Mike|Huckabee||R | ||
30|Duncan|Hunter||R | ||
31|Dennis|Kucinich||D | ||
37|John|McCain||R | ||
20|Barack|Obama||D | ||
32|Ron|Paul||R | ||
29|Bill|Richardson||D | ||
35|Mitt|Romney||R | ||
38|Tom|Tancredo||R | ||
41|Fred|Thompson|D.|R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sqlite3 | ||
|
||
#create a database | ||
db = sqlite3.connect("candidates") | ||
|
||
cursor = db.cursor() | ||
|
||
cursor.execute("""DROP TABLE IF EXISTS candidates""") | ||
|
||
cursor.execute("""CREATE TABLE candidates ( | ||
id INTEGER PRIMARY KEY NOT NULL, | ||
first_name TEXT, | ||
last_name TEXT, | ||
middle_initial TEXT, | ||
party TEXT NOT NULL)""") | ||
|
||
with open('candidates.txt') as f: | ||
next(f) | ||
for line in f: | ||
uid, first_name, last_name, middle_initial, party = line.strip().split("|") #strip means that u take away the space at the end | ||
cursor.execute("""INSERT INTO candidates | ||
(id, first_name, last_name, middle_initial, party) | ||
VALUES ( ?, ?, ?, ?, ?)""", (int(uid), first_name, last_name, middle_initial, party)) | ||
|
||
|
||
db.commit() | ||
db.close() | ||
|