-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhorse.py
More file actions
80 lines (74 loc) · 1.84 KB
/
Copy pathhorse.py
File metadata and controls
80 lines (74 loc) · 1.84 KB
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
import psycopg2
import psycopg2.extras
#ensures unicode output
import psycopg2.extensions
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
import re
import settings
import pprint
from datetime import datetime
from re import sub
from sqlalchemy.engine.url import URL
import connect
def _sanitycheck(val):
if type(val) == 'list':
return val[0] is not None
else:
return val is not None
#refactor get attribute
def _gethorsevalue(horsecode, attr):
assert _sanitycheck(args)
#does attribute exist?
conn,c1 = connect()
try:
sql = c1.mogrify("SELECT %s from horse h WHERE h.code=%s;", (attr, horsecode) )
c1.execute(sql)
val = c1.fetchone()
c1.close()
conn.close()
return val
except:
pass
def _gethorsename(horsecode):
'''returns a single horse name for this horsecode'''
if horsecode is None:
return None
conn,c1 = connect()
# print horsecode
sql = c1.mogrify("SELECT h.name from horse h WHERE h.code=%s;", (horsecode,) )
print sql
c1.execute(sql)
horsename = c1.fetchone()[0]
# print horsename[0]
c1.close()
conn.close()
return horsename
def _gethorse(horsecode):
'''returns the row of data about this horsecode'''
if horsecode is None:
return None
conn,c1 = connect()
# print horsecode
sql = c1.mogrify("SELECT * from horse h WHERE h.code=%s;", (horsecode,) )
print sql
c1.execute(sql)
h = c1.fetchone()
c1.close()
conn.close()
pprint.pprint(h)
return h
#what about horses which changed names- same code!
def _gethorseid(horsecode):
'''returns a single horseid for this horsecode'''
if horsecode is None:
return None
conn,c1 = connect.connect()
print horsecode
sql = c1.mogrify("SELECT h.id from horse h WHERE h.code=%s;", (horsecode,) )
print sql
c1.execute(sql)
horseid = c1.fetchone()[0]
c1.close()
conn.close()
return horseid