Mercurial > hg > horiscopes
comparison V4/runme.py @ 22:a5b8e2b91d8f
fixing None Planets bug and reformatting output of fullResults
author | DaveM |
---|---|
date | Thu, 08 Mar 2018 20:36:44 +0000 |
parents | 0264a7888d54 |
children | 11d4e438045e |
comparison
equal
deleted
inserted
replaced
21:0264a7888d54 | 22:a5b8e2b91d8f |
---|---|
42 | 42 |
43 def uniquify(itemList): | 43 def uniquify(itemList): |
44 keyDict = {} | 44 keyDict = {} |
45 for item in itemList: | 45 for item in itemList: |
46 keyDict[item] = 1 | 46 keyDict[item] = 1 |
47 return keyDict.keys() | 47 return sorted(keyDict.keys()) |
48 | 48 |
49 def outputPeople(filename,people): | 49 def outputPeople(filename,people): |
50 with open(filename, "wb") as csv_file: | 50 with open(filename, "wb") as csv_file: |
51 dictKeys = [] | 51 dictKeys = [] |
52 for person in people: | 52 for person in people: |
53 if person.issue is None: | 53 if person.issue is None: |
54 person.horiscope.calcAllAspects() | 54 person.horiscope.makeAllAspectTreple() |
55 dictKeys += person.horiscope.aspect.keys() | 55 dictKeys += person.horiscope.aspectTreple.keys() |
56 dictKeys = uniquify(dictKeys) | 56 dictKeys = uniquify(dictKeys) |
57 writer = csv.DictWriter(csv_file, ['id']+dictKeys) | 57 writer = csv.DictWriter(csv_file, ['id','score']+dictKeys) |
58 writer.writeheader() | 58 writer.writeheader() |
59 for person in people: | 59 for person in people: |
60 if person.issue is None: | 60 if person.issue is None: |
61 tempDict = {'id':person.id} | 61 tempDict = {'id':person.id,'score':person.score} |
62 tempDict.update(person.horiscope.aspect) | 62 tempDict.update(person.horiscope.aspectTreple) |
63 # pdb.set_trace() | 63 # pdb.set_trace() |
64 writer.writerow(tempDict) | 64 writer.writerow(tempDict) |
65 | 65 |
66 def outputScores(filename,people): | 66 def outputScores(filename,people): |
67 with open(filename, "wb") as csv_file: | 67 with open(filename, "wb") as csv_file: |
82 # def requestURL(url,payload): | 82 # def requestURL(url,payload): |
83 # r = requests.get(url, params=payload) | 83 # r = requests.get(url, params=payload) |
84 # time.sleep(5) | 84 # time.sleep(5) |
85 # return r | 85 # return r |
86 | 86 |
87 def loadPickUpdate(filename): | |
88 | |
87 def loadPick(filename): | 89 def loadPick(filename): |
88 with open(filename, 'rb') as handle: | 90 with open(filename, 'rb') as handle: |
89 b = pickle.load(handle) | 91 b = pickle.load(handle) |
90 return b | 92 return b |
91 | 93 |
98 issue = person.identifyIssues() | 100 issue = person.identifyIssues() |
99 if issue is not None: | 101 if issue is not None: |
100 print 'SKIPPING person '+ person.id + ' error with ' + issue | 102 print 'SKIPPING person '+ person.id + ' error with ' + issue |
101 else: | 103 else: |
102 print 'parsing person '+ person.id | 104 print 'parsing person '+ person.id |
103 person.makePayload() | 105 if person.resp is None: |
104 person.requestURL() | 106 print 'Posting Request for person '+ person.id |
107 person.makePayload() | |
108 person.requestURL() | |
109 print 'parsing person '+ person.id | |
105 person.horiscope = person.parsePage() | 110 person.horiscope = person.parsePage() |
106 # person.horiscope.printPositions() | 111 # person.horiscope.printPositions() |
107 if saveFile is not None: | 112 if saveFile is not None: |
108 savePick(saveFile,people) | 113 savePick(saveFile,people) |
109 | 114 |