Mercurial > hg > horiscopes
comparison V1/temp.py @ 3:c2898c2a3cc6
develop csv data parse - need to test
author | DaveM |
---|---|
date | Sun, 10 Dec 2017 17:25:53 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:e541264bcb9b | 3:c2898c2a3cc6 |
---|---|
1 def parsePartnerDOB(dob): | |
2 dob_ = dob.split('/') | |
3 if(len(dob_) != 3): | |
4 # deal with no /'s | |
5 try: | |
6 d = int(dob_[0]) | |
7 m = int(dob_[1]) | |
8 y = int(dob_[2]) | |
9 if y < 100: | |
10 y = y + 1900 | |
11 if(d > 31 or m > 12 or y > 2017 or y < 1900): | |
12 print 'error with DOB '+d+'/'+m+'/'+y | |
13 except TypeError: | |
14 return None | |
15 return (d,m,y) | |
16 | |
17 def monthStringToNum(s): | |
18 m = {'jan':1,'feb':2, | |
19 'mar':3,'apr':4,'may':5, | |
20 'jun':6,'jul':7,'aug':8, | |
21 'sep':9,'oct':10,'nov':11, | |
22 'dec':12} | |
23 s_ = string.strip()[:3].lower() | |
24 try: | |
25 out = m[s] | |
26 return out | |
27 except: | |
28 raise ValueError('Not a month') | |
29 | |
30 def parseDOB(d,m,y): | |
31 d = int(d.strip()) | |
32 y = int(y.strip()) | |
33 try: | |
34 m = monthStringToNum(m.strip()) | |
35 except ValueError: | |
36 m = int(m.strip()) | |
37 if(y < 100): | |
38 y = y + 1900 | |
39 return (d,m,y) | |
40 | |
41 def parseTOB(T): | |
42 timeFlat = None | |
43 try: | |
44 T = T.lower().strip() | |
45 if 'am' in T: | |
46 timeFlag = 0 | |
47 T.replace('am','') | |
48 if 'pm' in T: | |
49 timeFlag = 1 | |
50 T.replace('pm','') | |
51 t.strip() | |
52 if ':' in T: | |
53 T.split(':') | |
54 H = int(T[0]) | |
55 M = int(T[1]) | |
56 elif '.' in T: | |
57 T.split('.') | |
58 H = int(T[0]) | |
59 M = int(T[1]) | |
60 else: | |
61 int(T) | |
62 if T < 24 : | |
63 H = T | |
64 M = 0 | |
65 elif T > 100: | |
66 H = T/100 | |
67 M = T%100 | |
68 if timeFlag is not None: | |
69 if timeFlag == 0: | |
70 H = H%12 | |
71 else: | |
72 H = H%12 + 12 | |
73 except ValueError: | |
74 H = 12 | |
75 M = 00 | |
76 return (H,M) | |
77 | |
78 def regulateData(dataDict): | |
79 p_DOBQ = "What is your partner's date of birth? Please use the format DD/MM/YYYY (for example, 29/03/1981)." | |
80 p_TOBQ = "At what exact time were your partner born? Please use the format HHMM (for example, 2204)." | |
81 DOB_DQ = "Which day (numeric) have you been born?" | |
82 DOB_MQ = "Which month have you been born?" | |
83 DOB_YQ = "Year Of Birth" | |
84 TOB_Q = "At what exact time were you born? Please use the format HHMM (for example, 2204)." | |
85 dataDict['DOB'] = parseDOB(dataDict[DOB_DQ],dataDict[DOB_MQ],dataDict[DOB_YQ]) | |
86 dataDict['TOB'] = parseTOB(dataDict[TOB_Q]) | |
87 dataDict['pDOB'] = parsePartnerDOB(dataDict[p_DOBQ]) | |
88 dataDict['pTOB'] = parseTOB(dataDict[p_TOBQ]) | |
89 | |
90 return dataDict |