-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_data.py
More file actions
141 lines (110 loc) · 4.54 KB
/
event_data.py
File metadata and controls
141 lines (110 loc) · 4.54 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import datetime
import WazeRouteCalculator
import logging
import re
from colorama import Fore
from datetime import datetime
YEAR = "2023"
class Ev:
def __init__(self, date, store, location, frmt):
self.date = date
self.store = store.strip()
self.location = location.strip()
self.frmt = frmt.strip()
self.travelHrs = 0
self.travelMins = 0
def __lt__(self, other):
return self.date < other.date
def convertToDate(dateString):
splitDate = dateString.split(" ")
month = splitDate[0]
day = splitDate[1]
if(month == "June" or month == "june"):
month = "Jun"
elif(month == "July" or month == "july"):
month = "Jul"
return datetime.strptime(YEAR + "/" + month + "/" + day, "%Y/%b/%d").strftime("%Y/%m/%d")
def printColor(someEvent):
color = Fore.WHITE
if(someEvent.travelHrs >= 0):
color = Fore.GREEN
if(someEvent.travelHrs >= 2):
color = Fore.YELLOW
if(someEvent.travelHrs >= 3):
color = Fore.RED
duration = "\tDuration: " + str(someEvent.travelHrs) + " hrs " + str(someEvent.travelMins) + " mins"
if len(someEvent.location) < 11:
duration = "\t" + duration
print(color + "Loc: " + someEvent.location + duration + " (" + someEvent.date + " " + someEvent.store + ", " + someEvent.frmt + ")")
def isBadEvent(line):
return len(line.split(" - ")) != 4
def performRegex(line):
newLine = line
if re.search("\w-\w", line):
newLine = re.sub("(\w)-(\w)", r"\1 \2", newLine)
return newLine
def progressBar(iterable, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"):
total = len(iterable)
def printProgressBar (iteration):
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
filledLength = int(length * iteration // total)
bar = fill * filledLength + '-' * (length - filledLength)
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd)
printProgressBar(0)
for i, item in enumerate(iterable):
yield item
printProgressBar(i + 1)
print()
def parseData():
#logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
#logger.setLevel(logging.DEBUG)
#handler = logging.StreamHandler()
#logger.addHandler(handler)
allEvents = []
badEvents = []
isDSM = input("IA and NE events only? (y/n)")
if(isDSM == "n"):
drivingFrom = input("Your address: ")
showAll = input("Show all events? (y/s/n) ")
else:
drivingFrom = "Des Moines, IA"
showAll = "y"
isSpecificDateRange = input("Specify date range? (y/n) ")
if(isSpecificDateRange == "y"):
dateRangeStart = convertToDate(input("Date range start? Example: Jun 8 "))
dateRangeEnd = convertToDate(input("Date range end? Example: Jun 10 "))
with open("events.txt") as data:
lines = data.readlines()
#for line in lines:
for line in progressBar(lines, prefix="Progress:", suffix="Complete"):
cleanLine = performRegex(line)
if isBadEvent(cleanLine):
badEvents.append(cleanLine)
continue
values = cleanLine.split(" - ")
date = convertToDate(values[0].strip())
store = values[1]
location = values[2]
mtgFormat = values[3]
if (isDSM == "y" and (location.endswith("IA") or location.endswith("NE"))) or (isSpecificDateRange == "y" and dateRangeStart <= date and dateRangeEnd >= date) or (isSpecificDateRange == "n" and isDSM == "n"):
drivingTo = store.strip() + ", " + location.strip()
route = WazeRouteCalculator.WazeRouteCalculator(drivingFrom, drivingTo, "US", avoid_toll_roads=True)
routeDuration = route.calc_route_info()[0]
evnt = Ev(date, store, location, mtgFormat)
evnt.travelHrs = int(routeDuration // 60)
evnt.travelMins = int(routeDuration % 60)
if showAll == "n":
if evnt.travelHrs <= 2:
allEvents.append(evnt)
elif showAll == "s":
if evnt.travelHrs <= 3:
allEvents.append(evnt)
else:
allEvents.append(evnt)
for thisEvent in allEvents:
printColor(thisEvent)
if len(badEvents) > 0:
print("***Found issues with the following events: ")
for event in badEvents:
print(event)
parseData()