/+junk/Dataanalys

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/Dataanalys
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3.1
#-*- coding: utf-8 -*-


import sys
import sqlite3
import awnser_sheet
import sqlCmd

awnsht = awnser_sheet.awnserSheet()
cmdClass = sqlCmd.commandPromt()

#======================= connection to DB ===========================

conn = sqlite3.connect("./awnsers.sqlite") #makes the connection with the db file.
db = conn.cursor()

##create table from query from file: create table if not exists

f = open("./createDB.sql")
query = f.read()
db.execute(query)
f.close()

#===================== end DB connection ==========================


#===================== Futction section ===========================

## menu
def menu():
	## menu options
	menuOptions="""1. show DB
2. edit DB
3. add to DB
4. exit
"""

	print("select an option")
	print(menuOptions)
	menuOptionsInput = str(input(">>>>"))

	#ifs and thens
	if(menuOptionsInput == "1" or menuOptionsInput.lower() == "s" ):
		dbShow()
		
	elif(menuOptionsInput == "2" or menuOptionsInput.lower() =="e" ):
		dbEdit()
	
	elif(menuOptionsInput == "3" or menuOptionsInput.lower() == "a" ):
		dbAdd()
	
	elif(menuOptionsInput == "4" or menuOptionsInput.lower() == "q" ):
		exit()
	
	else:
		print("You need to select an option! in the list")
		menu()
	




#Show DB Function
def dbShow():
	print("DEBUG : Running dbShow()")
	#TODO: make it print counts of occurunsus of different true (integer 1) values
	
	getQuery =""" select * from awnsers; """
	db.execute(getQuery)
	
	for row in db:
		print( row )
	
	
	if(getQuery[0] == None):
		print("No data in table.")
	
	print("===== changing to database comand line =====")
	cmdClass.cmdloop()

def dbEdit():
	print("DEBUG: running dbEdit()")
	#TODO: make it 
	menu()


def dbAdd(): ##TODO: rename to dbCmd or somthing.
	print("DEBUG: running dbAdd()")
	query = awnsht.questionAndReturn() #kallar annan fil.
	print(query)
	print("commit this query to DB?")
	dbCommitString(query)
	
def dbCommitString(query):
	q = str(input("y/n > "))
	q = q.lower() #save my life
	if(q == "n"):
		menu()
	if(q == "y"):
		db.execute(query)
		conn.commit()
		menu()
	else:
		print("== Enter a valid input ==")
		dbCommitString(query)
	

#==================== end function setion ==================


#==================== main call section ====================
menu()