/+junk/Dataanalys

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/Dataanalys
6 by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy...
1
#!/usr/bin/env python3.1
2
#-*- coding: utf-8 -*-
3
4
""" Testing the cmd interface """
5
6
import cmd
7
import sys
8
import sqlite3
9
10
class commandPromt(cmd.Cmd):
11
	""" Testing here """
12
13
	# init of DB and shit
14
	conn = sqlite3.connect("./awnsers.sqlite")
15
	db = conn.cursor()
16
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.....
17
	startQueryShow = "select * from awnsers where("
6 by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy...
18
	startQueryCount = "select count(*) from awnsers where("
19
	endQuery =");"
20
21
22
	def do_show(self,line):
23
		""" Shows the query where
24
		IE: select * from <table> where <Command>
25
		example:
9 by Gustav Hartvigsson
just added some TODO:s ....
26
			show test2 = 1 and test = 1"""
6 by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy...
27
		query = commandPromt.startQueryShow + line + commandPromt.endQuery
28
		try:
29
			result = commandPromt.db.execute(query)
30
		except:
31
			print("Dave, I can not show you that....")
32
		else:
33
			for row in result:
34
				print(row)
35
	
36
	def do_count(self,line):
37
		""" counts the query where
9 by Gustav Hartvigsson
just added some TODO:s ....
38
		IE: select count(*) from <table> where <Command>
39
		example:
40
			count test2 = 1 and test = 1"""
6 by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy...
41
		query = commandPromt.startQueryCount + line + commandPromt.endQuery
42
		try:
43
			result = commandPromt.db.execute(query)
44
		except:
45
			print("Dave, I can not count that....")
46
		else:
47
			for row in result:
48
				print(row[0])
9 by Gustav Hartvigsson
just added some TODO:s ....
49
	#TODO: Add a countAll command, it will show the numbor of each true value in the DB.
50
	#IE:
51
	#gud: 13
52
	#vegan: 4
53
	#etc etc.
6 by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy...
54
55
	def do_exit(self,line):
56
		import awnsers_and_db_edit
9 by Gustav Hartvigsson
just added some TODO:s ....
57
		print("====== returning to main menu ======")##FIXME: why is this not printed before going into the main menu?
6 by Gustav Hartvigsson
Added a camand line interface, and finished up the awnser sheet thingy...
58
		awnsers_and_db_edit.menu()
59
60
	def de_EOF(self, line):
61
		return(true)