Commit 32032477 authored by Robert Hitt's avatar Robert Hitt

Refactored to make things more pythonic

parent 978a89fa
......@@ -4,6 +4,20 @@
from bs4 import BeautifulSoup
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
def cleanup(dirtystring):
......@@ -81,40 +95,19 @@ def convertTime(stri): # this function is used for splicing the event times.
def filter_data_into_days(dictlist):
new_dictlist = {}
date_reference = ""
for event in dictlist:
if "error" in event:
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:
new_dictlist[event_date].append(event)
else:
new_dictlist[event_date] = [event]
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():
"""
Parses the XML from Mason and mines 2 BTC.
......
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