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,85 +3,42 @@ from bs4 import BeautifulSoup ...@@ -3,85 +3,42 @@ 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
#print feed, "\n\n\n" feed = feedparser.parse(feedtext) # this calls the RSS feed parser from !feedparser
#ctr = 0
dictlist = []
for entry in feed.entries: # print feed, "\n\n\n"
# templist = {} # ctr = 0
#print entry.summary_detail.value dictlist = []
# templist["summary_detail"] = entry.summary_detail
'''print "----------------------------------" for entry in feed.entries:
print "1) ", entry.published_parsed, "\n" # print"==================================="
templist["published_parsed"] = entry.published_parsed
print entry.links, "\n"
templist["links"] = entry.links
print "3) ", entry.author, "\n"
templist["author"] = entry.author
print entry.summary, "\n"
templist["summary"] = entry.summary
print "5) ", entry.guidislink, "\n"
templist["guidislink"] = entry.guidislink
print entry.title_detail, "\n"
templist["title_detail"] = entry.title_detail
print "6) ", entry.link, "\n"
templist["link"] = entry.link
print entry.authors, "\n"
templist["authors"] = entry.authors
print "7) ", entry.title, "\n"
templist["title"] = entry.title
print entry.author_detail, "\n"
templist["author_detail"] = entry.author_detail
print "9) ", entry.id, "\n"
templist["id"] = entry.id
print entry.published, "\n"
templist["published"] = entry.published
print"-----------------------------------"'''
#print"==================================="
uniqueid = entry.id[-7:] uniqueid = entry.id[-7:]
#print uniqueid # print uniqueid
title = entry.title title = entry.title
#print title # print title
sumdetsoup = BeautifulSoup(entry.summary_detail["value"].encode("ascii", "replace"), "html.parser") sumdetsoup = BeautifulSoup(entry.summary_detail["value"].encode("ascii", "replace"), "html.parser")
location = [sumdetsoup.div.span.text] location = [sumdetsoup.div.span.text]
#print location # print location
description = sumdetsoup.find_all("div")[1].p.text description = sumdetsoup.find_all("div")[1].text
#print description # print description
datetime = sumdetsoup.b.text datetime = sumdetsoup.b.text
#print datetime # print datetime
if (datetime.count("(") == 1): if (datetime.count("(") == 1):
datesplit = datetime.split(", ") datesplit = datetime.split(", ")
...@@ -93,9 +50,9 @@ for entry in feed.entries: ...@@ -93,9 +50,9 @@ for entry in feed.entries:
parsedtimelist = doTheTime(datesplit[2][6:-1]) parsedtimelist = doTheTime(datesplit[2][6:-1])
timestart = parsedtimelist[0] timestart = parsedtimelist[0]
timestop = parsedtimelist[1] timestop = parsedtimelist[1]
# 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}) dictlist.append({"id":uniqueid, "title":title, "dayofweek":weekday, "dayofmonth":monthday, "month":month, "year":year, "timestart":timestart, "timestop":timestop, "location":location, "description":description})
return dictlist
print dictlist
#print "\n\n", sumdetsoup.prettify() #print "\n\n", sumdetsoup.prettify()
...@@ -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