Commit f6c6a179 authored by Landon DeCoito's avatar Landon DeCoito

Getconnectedparscript now returns a 25Live data -esque JSON

parent 97dd56b1
from flask import Flask from flask import Flask
from flask import Response from flask import Response
from parscript import load_data from parscript import load_data
from getconnectedscript import load_getconn_data
import json import json
app = Flask(__name__) app = Flask(__name__)
@app.route("/") @app.route("/25Live")
def display_data(): def display_data():
resp = Response(json.dumps(load_data(), ensure_ascii=False).encode('utf-8')) resp = Response(json.dumps(load_data(), ensure_ascii=False).encode('utf-8'))
resp.headers['Content-Type'] = 'application/json; charset=utf-8' resp.headers['Content-Type'] = 'application/json; charset=utf-8'
return resp return resp
@app.route("/getconn")
def display_GC_data():
resp = Response(json.dumps(load_getconn_data(), ensure_ascii=False).encode('utf-8'))
resp.headers['Content-Type'] = 'application/json; charset=utf-8'
return resp
...@@ -3,103 +3,60 @@ from bs4 import BeautifulSoup ...@@ -3,103 +3,60 @@ from bs4 import BeautifulSoup
from parscript import cleanup, doTheTime from parscript import cleanup, doTheTime
import feedparser import feedparser
#TODO: ADD "getconnected" ATTRIBUTE TO LOAD_DATA DICTLIST # TODO: ADD "getconnected" ATTRIBUTE TO LOAD_DATA DICTLIST
#woah = cleanup(requests.get("https://getconnected.gmu.edu/events/events.rss").text) # woah = cleanup(requests.get("https://getconnected.gmu.edu/events/events.rss").text)
#soup = BeautifulSoup(woah, "lxml") # soup = BeautifulSoup(woah, "lxml")
#print soup.prettify # print soup.prettify
feedtext = requests.get("https://getconnected.gmu.edu/events/events.rss").text def load_getconn_data():
feedtext = cleanup(feedtext) feedtext = requests.get("https://getconnected.gmu.edu/events/events.rss").text
feedtext = feedtext.replace("’", "'") feedtext = cleanup(feedtext)
feed = feedparser.parse(feedtext)#this calls the RSS feed parser from !feedparser
feed = feedparser.parse(feedtext) # this calls the RSS feed parser from !feedparser
#print feed, "\n\n\n"
#ctr = 0 # print feed, "\n\n\n"
dictlist = [] # ctr = 0
dictlist = []
for entry in feed.entries:
# templist = {} for entry in feed.entries:
#print entry.summary_detail.value # print"==================================="
# templist["summary_detail"] = entry.summary_detail uniqueid = entry.id[-7:]
# print uniqueid
'''print "----------------------------------"
print "1) ", entry.published_parsed, "\n" title = entry.title
templist["published_parsed"] = entry.published_parsed # print title
print entry.links, "\n" sumdetsoup = BeautifulSoup(entry.summary_detail["value"].encode("ascii", "replace"), "html.parser")
templist["links"] = entry.links
location = [sumdetsoup.div.span.text]
print "3) ", entry.author, "\n" # print location
templist["author"] = entry.author
description = sumdetsoup.find_all("div")[1].text
print entry.summary, "\n" # print description
templist["summary"] = entry.summary
print "5) ", entry.guidislink, "\n" datetime = sumdetsoup.b.text
templist["guidislink"] = entry.guidislink # print datetime
print entry.title_detail, "\n" if (datetime.count("(") == 1):
templist["title_detail"] = entry.title_detail datesplit = datetime.split(", ")
weekday = datesplit[0]
print "6) ", entry.link, "\n" month = datesplit[1].split(" ")
templist["link"] = entry.link monthday = month[1]
month = month[0]
print entry.authors, "\n" year = datesplit[2][:5]
templist["authors"] = entry.authors parsedtimelist = doTheTime(datesplit[2][6:-1])
timestart = parsedtimelist[0]
print "7) ", entry.title, "\n" timestop = parsedtimelist[1]
templist["title"] = entry.title # print {"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, "dayofweek":weekday, "dayofmonth":monthday, "month":month, "year":year, "timestart":timestart, "timestop":timestop, "location":location, "description":description})
print entry.author_detail, "\n" return dictlist
templist["author_detail"] = entry.author_detail
print "9) ", entry.id, "\n" #print "\n\n", sumdetsoup.prettify()
templist["id"] = entry.id #print"==================================="
print entry.published, "\n"
templist["published"] = entry.published
print"-----------------------------------"'''
#print"==================================="
uniqueid = entry.id[-7:]
#print uniqueid
title = entry.title
#print title
sumdetsoup = BeautifulSoup(entry.summary_detail["value"].encode("ascii", "replace"), "html.parser")
location = [sumdetsoup.div.span.text]
#print location
description = sumdetsoup.find_all("div")[1].p.text
#print description
datetime = sumdetsoup.b.text
#print datetime
if (datetime.count("(") == 1):
datesplit = datetime.split(", ")
weekday = datesplit[0]
month = datesplit[1].split(" ")
monthday = month[1]
month = month[0]
year = datesplit[2][:5]
parsedtimelist = doTheTime(datesplit[2][6:-1])
timestart = parsedtimelist[0]
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})
print dictlist
#print "\n\n", sumdetsoup.prettify()
#print"==================================="
#dictlist.append({"id":uniqueid, "title":entry_title, "dayofweek":weekday, "dayofmonth":monthday, "month":month, "year":year, "timestart":timestart, "timestop":timestop, "location":location, "description":description}) #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 #This was intended to figure out what objects are in each entry and what appears only sometimes
...@@ -120,22 +77,3 @@ print dictlist ...@@ -120,22 +77,3 @@ print dictlist
#-------published #-------published
####Some events have: ####Some events have:
#-------tags #-------tags
'''for key in feed.entries[0].keys():
everyone.append(key)
some = []
for entry in feed.entries:
#print "----------------------------------"
for key in entry.keys():
if not key in everyone:
some.append(key)
for key in everyone:
if not (key in entry.keys()):
everyone.remove(key)
some.append(key)
#print"-----------------------------------"
#ctr += 1
print "Everyone: \n", everyone
print "Some: \n", some'''
...@@ -14,6 +14,7 @@ def cleanup(str): #this function cleans up some of the useless html leftovers to ...@@ -14,6 +14,7 @@ def cleanup(str): #this function cleans up some of the useless html leftovers to
str = str.replace("Performing any medical procedures?: FALSE \n" , "") str = str.replace("Performing any medical procedures?: FALSE \n" , "")
str = str.replace("Parking Needed?: FALSE \n" , "") str = str.replace("Parking Needed?: FALSE \n" , "")
str = str[0:len(str) - 1] str = str[0:len(str) - 1]
str = str.replace("’", "'")
return str return str
class eventException: #this class is just an exception for our use class eventException: #this class is just an exception for our use
......
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