-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_select.py
89 lines (70 loc) · 2.03 KB
/
db_select.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
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
#!/usr/bin/python
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by the db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return None
def create_combinations(iterable, r):
"""
Create all unique sets of r length from the iterable input
:param iterable: a list or tuple containing a number of variables
:param r: the length of the subset to find in the variable e.g. all sets of 3 numbers from 6 given
:return: A list holding all unique sets
"""
j = iterable
unique_set = []
for comb in j:
unique_set.insert(comb)
return unique_set
def select_draws(conn, x):
"""
Query all rows in the tasks table
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM lotto WHERE DrawID <= " + str(x))
num = []
rows = cur.fetchall()
for row in rows:
# print(row)
num.append(row[0], row[5:11])
print(num)
return num
def select_task_by_priority(conn, priority):
"""
Query tasks by priority
:param conn: the Connection object
:param priority:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM lotto WHERE priority=?", (priority,))
rows = cur.fetchall()
for row in rows:
print(row)
def main():
database = "/home/lol/PycharmProjects/lottery/db/uklotto.db"
# create a database connection
conn = create_connection(database)
with conn:
# print("1. Query task by priority:")
# select_task_by_priority(conn, 1)
print("Get the first 100 draws")
draws = select_draws(conn, 10)
result = []
for draw in draws:
combo = create_combinations(draw, 3)
result.append(draw, combo)
print(result)
if __name__ == '__main__':
main()