Mercurial > hg > horiscopes
comparison V2/runme.py @ 3:c2898c2a3cc6
develop csv data parse - need to test
author | DaveM |
---|---|
date | Sun, 10 Dec 2017 17:25:53 +0000 |
parents | e541264bcb9b |
children | 99115e36316b |
comparison
equal
deleted
inserted
replaced
2:e541264bcb9b | 3:c2898c2a3cc6 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 import dParse as dp | |
2 import requests | 3 import requests |
3 import re | 4 import re |
4 import time | 5 import time |
5 import csv | 6 import csv |
6 import random | 7 import random |
57 | 58 |
58 def parseCSV(filename): | 59 def parseCSV(filename): |
59 stream = csv.DictReader(open(filename,'rb')) | 60 stream = csv.DictReader(open(filename,'rb')) |
60 dictList = [] | 61 dictList = [] |
61 for line in stream: | 62 for line in stream: |
62 dictList.append(line) | 63 dictList.append(dp.regulateData(line)) |
64 | |
65 # dictList = headerParse(dictList) | |
66 # dictList = validateData(dictList) | |
63 return dictList | 67 return dictList |
64 | 68 |
65 def printToFile(filename,data): | 69 def printToFile(filename,data): |
66 keys = data[0].keys() | 70 keys = data[0].keys() |
67 with open(filename,'w') as stream: | 71 with open(filename,'w') as stream: |
68 dict_writer = csv.DictWriter(stream, keys) | 72 dict_writer = csv.DictWriter(stream, keys) |
69 dict_writer.writeheader() | 73 dict_writer.writeheader() |
70 dict_writer.writerows(data) | 74 dict_writer.writerows(data) |
71 | 75 |
72 def main(): | 76 def testMain(): |
77 people = parseCSV('individuals.csv') | |
78 | |
79 def _main(): | |
73 # people = dict() | 80 # people = dict() |
74 people = parseCSV('individuals.csv') | 81 people = parseCSV('individuals.csv') |
75 horiscopeList = [] | 82 horiscopeList = [] |
76 # people = [1,2,3,4,5] | 83 # people = [1,2,3,4,5] |
77 for person in people: | 84 for person in people: |
83 horiscopeList.append(person) | 90 horiscopeList.append(person) |
84 print horiscopeList | 91 print horiscopeList |
85 printToFile('outputdata.csv',horiscopeList) | 92 printToFile('outputdata.csv',horiscopeList) |
86 | 93 |
87 if __name__ == "__main__": | 94 if __name__ == "__main__": |
88 main() | 95 testMain() |