Commit 32032477 authored by Robert Hitt's avatar Robert Hitt

Refactored to make things more pythonic

parent 978a89fa
...@@ -4,6 +4,20 @@ ...@@ -4,6 +4,20 @@
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests import requests
_MONTH_DICT = {
"January": 1,
"Febuary": 2,
"March": 3,
"April": 4,
"May": 5,
"June": 6,
"July": 7,
"August": 8,
"September": 9,
"October": 10,
"November": 11,
"December": 12
}
# this function cleans up some of the useless html leftovers to characters we can actually use # this function cleans up some of the useless html leftovers to characters we can actually use
def cleanup(dirtystring): def cleanup(dirtystring):
...@@ -26,7 +40,7 @@ def cleanup(dirtystring): ...@@ -26,7 +40,7 @@ def cleanup(dirtystring):
dirtystring = dirtystring.replace(replacement[0], replacement[1]) dirtystring = dirtystring.replace(replacement[0], replacement[1])
return dirtystring[:-1] return dirtystring[:-1]
# Simple event quality test # Simple event quality test
def qualityTest(desc): def qualityTest(desc):
# none, bad, okay, good # none, bad, okay, good
...@@ -42,7 +56,7 @@ def qualityTest(desc): ...@@ -42,7 +56,7 @@ def qualityTest(desc):
return "good" return "good"
elif length < 100: elif length < 100:
return "verygood" return "verygood"
else: else:
return "excellent" return "excellent"
# convertTime accepts strings in the form of "" # convertTime accepts strings in the form of ""
...@@ -81,39 +95,18 @@ def convertTime(stri): # this function is used for splicing the event times. ...@@ -81,39 +95,18 @@ def convertTime(stri): # this function is used for splicing the event times.
def filter_data_into_days(dictlist): def filter_data_into_days(dictlist):
new_dictlist = {} new_dictlist = {}
date_reference = ""
for event in dictlist: for event in dictlist:
if "error" in event: if "error" in event:
continue continue
event_date = event["dayofmonth"] + "/" + str(month_to_number(event["month"])) + "/" + event["year"] event_date = "{}/{}/{}".format(event["dayofmonth"],
_MONTH_DICT[event["month"]],
event["year"])
if event_date in new_dictlist: if event_date in new_dictlist:
new_dictlist[event_date].append(event) new_dictlist[event_date].append(event)
else: else:
new_dictlist[event_date] = [event] new_dictlist[event_date] = [event]
return new_dictlist return new_dictlist
def month_to_number(month):
month_dict = {
"January": 1,
"Febuary": 2,
"March": 3,
"April": 4,
"May": 5,
"June": 6,
"July": 7,
"August": 8,
"September": 9,
"October": 10,
"November": 11,
"December": 12
}
try:
out = month_dict[month]
return out
except:
raise Exception("Invalid month to convert to number")
def load_data(): def load_data():
""" """
...@@ -309,7 +302,7 @@ def load_data(): ...@@ -309,7 +302,7 @@ def load_data():
"year": year, "timestart": timestart, "timestop": timestop, "location": location, "description": description}) "year": year, "timestart": timestart, "timestop": timestop, "location": location, "description": description})
else: else:
dictlist.append({"id": uniqueid, "error": error}) dictlist.append({"id": uniqueid, "error": error})
return filter_data_into_days(dictlist) return filter_data_into_days(dictlist)
# everything in the house is fuzzy, stupid dogs were acting like pollinators, if that's how you even spell it # everything in the house is fuzzy, stupid dogs were acting like pollinators, if that's how you even spell it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment