bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/Dataanalys
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
1 |
#!/usr/bin/env python3.1
|
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
2 |
#-*- coding: utf-8 -*-
|
3 |
||
4 |
||
1
by Gustav Hartvigsson
initial code commiinitial code committ |
5 |
import sys |
6 |
import sqlite3 |
|
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
7 |
import awnser_sheet |
8 |
import sqlCmd |
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
9 |
|
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
10 |
awnsht = awnser_sheet.awnserSheet() |
11 |
cmdClass = sqlCmd.commandPromt() |
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
12 |
|
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
13 |
#======================= connection to DB ===========================
|
14 |
||
15 |
conn = sqlite3.connect("./awnsers.sqlite") #makes the connection with the db file. |
|
16 |
db = conn.cursor() |
|
17 |
||
18 |
##create table from query from file: create table if not exists
|
|
19 |
||
20 |
f = open("./createDB.sql") |
|
21 |
query = f.read() |
|
22 |
db.execute(query) |
|
23 |
f.close() |
|
24 |
||
25 |
#===================== end DB connection ==========================
|
|
26 |
||
27 |
||
28 |
#===================== Futction section ===========================
|
|
29 |
||
1
by Gustav Hartvigsson
initial code commiinitial code committ |
30 |
## menu
|
31 |
def menu(): |
|
32 |
## menu options
|
|
33 |
menuOptions="""1. show DB |
|
34 |
2. edit DB
|
|
35 |
3. add to DB
|
|
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
36 |
4. exit
|
37 |
"""
|
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
38 |
|
39 |
print("select an option") |
|
40 |
print(menuOptions) |
|
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
41 |
menuOptionsInput = str(input(">>>>")) |
1
by Gustav Hartvigsson
initial code commiinitial code committ |
42 |
|
43 |
#ifs and thens
|
|
4
by Gustav Hartvigsson
fixed som shit and started the initial work on the awnser sheet... |
44 |
if(menuOptionsInput == "1" or menuOptionsInput.lower() == "s" ): |
1
by Gustav Hartvigsson
initial code commiinitial code committ |
45 |
dbShow() |
46 |
||
4
by Gustav Hartvigsson
fixed som shit and started the initial work on the awnser sheet... |
47 |
elif(menuOptionsInput == "2" or menuOptionsInput.lower() =="e" ): |
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
48 |
dbEdit() |
49 |
||
4
by Gustav Hartvigsson
fixed som shit and started the initial work on the awnser sheet... |
50 |
elif(menuOptionsInput == "3" or menuOptionsInput.lower() == "a" ): |
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
51 |
dbAdd() |
52 |
||
4
by Gustav Hartvigsson
fixed som shit and started the initial work on the awnser sheet... |
53 |
elif(menuOptionsInput == "4" or menuOptionsInput.lower() == "q" ): |
1
by Gustav Hartvigsson
initial code commiinitial code committ |
54 |
exit() |
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
55 |
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
56 |
else: |
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
57 |
print("You need to select an option! in the list") |
1
by Gustav Hartvigsson
initial code commiinitial code committ |
58 |
menu() |
59 |
||
60 |
||
61 |
||
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
62 |
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
63 |
|
64 |
#Show DB Function
|
|
65 |
def dbShow(): |
|
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
66 |
print("DEBUG : Running dbShow()") |
67 |
#TODO: make it print counts of occurunsus of different true (integer 1) values
|
|
68 |
||
1
by Gustav Hartvigsson
initial code commiinitial code committ |
69 |
getQuery =""" select * from awnsers; """ |
70 |
db.execute(getQuery) |
|
71 |
||
72 |
for row in db: |
|
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
73 |
print( row ) |
1
by Gustav Hartvigsson
initial code commiinitial code committ |
74 |
|
75 |
||
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
76 |
if(getQuery[0] == None): |
1
by Gustav Hartvigsson
initial code commiinitial code committ |
77 |
print("No data in table.") |
78 |
||
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
79 |
print("===== changing to database comand line =====") |
80 |
cmdClass.cmdloop() |
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
81 |
|
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
82 |
def dbEdit(): |
83 |
print("DEBUG: running dbEdit()") |
|
84 |
#TODO: make it
|
|
85 |
menu() |
|
86 |
||
87 |
||
9
by Gustav Hartvigsson
just added some TODO:s .... |
88 |
def dbAdd(): ##TODO: rename to dbCmd or somthing. |
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
89 |
print("DEBUG: running dbAdd()") |
8
by Gustav Hartvigsson
Made the dbAdd work.... and fixed some errors that I made when creatig the "create table awnsers(" file and fixed the inherited probem from that in awnser_sheet..... |
90 |
query = awnsht.questionAndReturn() #kallar annan fil. |
6
by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy... |
91 |
print(query) |
8
by Gustav Hartvigsson
Made the dbAdd work.... and fixed some errors that I made when creatig the "create table awnsers(" file and fixed the inherited probem from that in awnser_sheet..... |
92 |
print("commit this query to DB?") |
23
by Gusatv Hartvigsson
lots of changes, mostly done when I actualy ran the program, and saw the errors that I made. |
93 |
dbCommitString(query) |
8
by Gustav Hartvigsson
Made the dbAdd work.... and fixed some errors that I made when creatig the "create table awnsers(" file and fixed the inherited probem from that in awnser_sheet..... |
94 |
|
23
by Gusatv Hartvigsson
lots of changes, mostly done when I actualy ran the program, and saw the errors that I made. |
95 |
def dbCommitString(query): |
14
by Gusatv Hartvigsson
Added a few questions to the program, made use of the sqlAwnsersStart.sql" |
96 |
q = str(input("y/n > ")) |
23
by Gusatv Hartvigsson
lots of changes, mostly done when I actualy ran the program, and saw the errors that I made. |
97 |
q = q.lower() #save my life |
8
by Gustav Hartvigsson
Made the dbAdd work.... and fixed some errors that I made when creatig the "create table awnsers(" file and fixed the inherited probem from that in awnser_sheet..... |
98 |
if(q == "n"): |
99 |
menu() |
|
100 |
if(q == "y"): |
|
101 |
db.execute(query) |
|
102 |
conn.commit() |
|
103 |
menu() |
|
104 |
else: |
|
23
by Gusatv Hartvigsson
lots of changes, mostly done when I actualy ran the program, and saw the errors that I made. |
105 |
print("== Enter a valid input ==") |
106 |
dbCommitString(query) |
|
8
by Gustav Hartvigsson
Made the dbAdd work.... and fixed some errors that I made when creatig the "create table awnsers(" file and fixed the inherited probem from that in awnser_sheet..... |
107 |
|
3
by Gustav Hartvigsson
Made some changes and added the initial work on the different functions... |
108 |
|
109 |
#==================== end function setion ==================
|
|
110 |
||
111 |
||
112 |
#==================== main call section ====================
|
|
1
by Gustav Hartvigsson
initial code commiinitial code committ |
113 |
menu() |
114 |