Commit 9d3d7ec3 authored by Landon DeCoito's avatar Landon DeCoito
Browse files

getconnectedscript is now pep8 compliant

parent 8e6136c7
...@@ -5,12 +5,14 @@ import feedparser ...@@ -5,12 +5,14 @@ import feedparser
# TODO: ADD "getconnected" ATTRIBUTE TO LOAD_DATA DICTLIST # TODO: ADD "getconnected" ATTRIBUTE TO LOAD_DATA DICTLIST
def splitAndConvertTime(strin): def splitAndConvertTime(strin):
strin = strin.replace(" ", "") strin = strin.replace(" ", "")
strin = strin.split("-") strin = strin.split("-")
returnlist = ["",""] returnlist = ["", ""]
returnlist[1] = convertTime(strin[1]) returnlist[1] = convertTime(strin[1])
if not (strin[0][-2:] == "am" or strin[0][-2:] == "AM") and not (strin[0][-2:] == "pm" or strin[0][-2:] == "PM"): if not (strin[0][-2:] == "am" or strin[0][-2:] == "AM") \
and not (strin[0][-2:] == "pm" or strin[0][-2:] == "PM"):
if (strin[1][-2:] == "am"): if (strin[1][-2:] == "am"):
returnlist[0] = convertTime(strin[0] + "am") returnlist[0] = convertTime(strin[0] + "am")
else: else:
...@@ -19,8 +21,10 @@ def splitAndConvertTime(strin): ...@@ -19,8 +21,10 @@ def splitAndConvertTime(strin):
returnlist[0] = convertTime(strin[0]) returnlist[0] = convertTime(strin[0])
return returnlist return returnlist
def load_getconn_data(): def load_getconn_data():
feedtext = requests.get("https://getconnected.gmu.edu/events/events.rss").text feedtext = requests.get(
"https://getconnected.gmu.edu/events/events.rss").text
feedtext = cleanup(feedtext) feedtext = cleanup(feedtext)
# this calls the RSS feed parser from !feedparser # this calls the RSS feed parser from !feedparser
...@@ -34,66 +38,81 @@ def load_getconn_data(): ...@@ -34,66 +38,81 @@ def load_getconn_data():
title = entry.title title = entry.title
# print title # print title
sumdetsoup = BeautifulSoup(entry.summary_detail["value"].encode("utf-8"), "html.parser") sumdetsoup = BeautifulSoup(entry.summary_detail["value"]
.encode("utf-8"), "html.parser")
location = [sumdetsoup.div.span.text] location = [sumdetsoup.div.span.text]
# print location # print location
description = sumdetsoup.find_all("div")[1].text description = sumdetsoup.find_all("div")[1].text
# print description # print description
datetime = sumdetsoup.b.text datetime = sumdetsoup.b.text
# print datetime # print datetime
# this handles events which start and end on the same day # this handles events which start and end on the same day
if (datetime.count("(") == 1): if (datetime.count("(") == 1):
datesplit = datetime.split(", ") try:
weekday = datesplit[0] datesplit = datetime.split(", ")
temp = datesplit[1].split(" ")
monthday = temp[1] # parses out date info
month = temp[0] weekday = datesplit[0]
year = datesplit[2][:5] temp = datesplit[1].split(" ")
monthday = temp[1]
# uses helper function to get the start and end time month = temp[0]
parsedtimelist = splitAndConvertTime(datesplit[2][6:-1]) year = datesplit[2][:5]
timestart = parsedtimelist[0]
timestop = parsedtimelist[1] # uses helper function to get the start and end time
parsedtimelist = splitAndConvertTime(datesplit[2][6:-1])
dictlist.append({"id":uniqueid, "title":title, "dayofweek":weekday, "dayofmonth":monthday, "month":month, timestart = parsedtimelist[0]
"year":year, "timestart":timestart, "timestop":timestop, "location":location, "description":description}) timestop = parsedtimelist[1]
dictlist.append({"id": uniqueid, "title": title,
"dayofweek": weekday, "dayofmonth": monthday,
"month": month, "year": year,
"timestart": timestart, "timestop": timestop,
"location": location,
"description": description})
except Exception as e:
dictlist.append({"id": uniqueid, "error": str(e)})
# this handles events which start on one day and end on another # this handles events which start on one day and end on another
else: else:
datesplit = datetime.split(" - ") try:
datesplit = datetime.split(" - ")
# getting the information for the start day/time
tempsplits = datesplit[0].split(", ") # getting the information for the start day/time
weekday = tempsplits[0] tempsplits = datesplit[0].split(", ")
month = tempsplits[1].split(" ")[0] weekday = tempsplits[0]
monthday = tempsplits[1].split(" ")[1] month = tempsplits[1].split(" ")[0]
year = tempsplits[2].split(" ")[0] monthday = tempsplits[1].split(" ")[1]
timestart = datesplit[0].split("(")[1][:-1] year = tempsplits[2].split(" ")[0]
timestart = convertTime(timestart) timestart = datesplit[0].split("(")[1][:-1]
timestart = convertTime(timestart)
# getting the information for the end day/time
tempsplits = datesplit[1].split(", ") # getting the information for the end day/time
endweekday = tempsplits[0] tempsplits = datesplit[1].split(", ")
endmonth = tempsplits[1].split(" ")[0] endweekday = tempsplits[0]
endmonthday = tempsplits[1].split(" ")[1] endmonth = tempsplits[1].split(" ")[0]
endyear = tempsplits[2].split(" ")[0] endmonthday = tempsplits[1].split(" ")[1]
timestop = datesplit[1].split("(")[1][:-1] endyear = tempsplits[2].split(" ")[0]
timestop = convertTime(timestop) timestop = datesplit[1].split("(")[1][:-1]
timestop = convertTime(timestop)
dictlist.append({"id":uniqueid, "title":title, "dayofweek":weekday, "dayofmonth":monthday, "month":month,
"year":year, "timestart":timestart, "timestop":timestop, "location":location, "description":description, dictlist.append({"id": uniqueid, "title": title,
"enddayofweek":endweekday, "enddayofmonth":endmonthday, "endmonth":endmonth, "endyear":endyear}) "dayofweek": weekday, "dayofmonth": monthday,
"month": month, "year": year,
"timestart": timestart, "timestop": timestop,
"location": location,
"description": description,
"enddayofweek": endweekday,
"enddayofmonth": endmonthday,
"endmonth": endmonth, "endyear": endyear})
except Exception as e:
dictlist.append({"id": uniqueid, "error": str(e)})
return dictlist return dictlist
# dictlist.append({"id":uniqueid, "title":entry_title, "dayofweek":weekday, "dayofmonth":monthday, "month":month, "year":year, "timestart":timestart, "timestop":timestop, "location":location, "description":description})
# This was intended to figure out what objects are in each entry and what appears only sometimes
# The results are:
# Every event has: # Every event has:
# -------summary # -------summary
# -------published_parsed # -------published_parsed
......
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