/
process_csv.py
57 lines (44 loc) · 1.29 KB
/
process_csv.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
#!/usr/bin/env python
import sys
import os
import csv
import copy
#import SharesInfo from company_shares module
from company_shares import SharesInfo
# constants
TEST_CSV_PATH = './test_data.csv'
def main():
"""
Call SharesInfo methods to process the CSV
"""
displayMainMenu()
def displayMainMenu():
print "\n\nOptions Menu:"
print "*****************"
print "1. Enter the CSV file path to process:"
print "2. Test using the test CSV file in the tool dir."
print "3. Exit"
while(True):
choice = raw_input('Enter the choice(1-3): ')
try:
choice = int(str(choice).strip())
if not choice in range(1,4):
raise Exception
break
except Exception:
print "Invalid Choice."
if choice == 1:
filePath = raw_input("Enter the CSV file path to process: ")
processCsvDataDisplayResults(filePath)
elif choice == 2:
filePath = TEST_CSV_PATH
processCsvDataDisplayResults(filePath)
else:
sys.exit(0)
print "Correct Choice"
def processCsvDataDisplayResults(filePath):
sharesInfo = SharesInfo(filePath)
sharesInfo.processCsvFile()
displayMainMenu()
if __name__ == '__main__':
main()