Skip to content

Commit ec6d761

Browse files
committed
Add Free Food
1 parent 7160198 commit ec6d761

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

app.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
from flask import Flask
22
from flask_restful import Api, Resource
33

4-
from resources.dining import Dining
5-
#from resources.weather import Weather
4+
#from resources.dining import Dining
5+
from resources.weather import Weather
66
from resources.wifi import Wifi
77
from resources.laundry import Laundry
88
from resources.main import Main
9+
from resources.free_food import FreeFood
910

1011
app = Flask(__name__)
1112
api = Api(app)
1213

1314
api.add_resource(Main, '/')
14-
#api.add_resource(Weather, '/weather')
15-
api.add_resource(Dining, '/dining/search/<query>', '/dining/<hall>/<dateFrom>/<dateTo>', '/dining/information', '/dining/balance')
15+
api.add_resource(Weather, '/weather')
16+
#api.add_resource(Dining, '/dining/search/<query>', '/dining/<hall>/<dateFrom>/<dateTo>', '/dining/information', '/dining/balance')
1617
#api.add_resource(Wifi, '/wifi', '/wifi/<latitude>/<longitude>')
1718
api.add_resource(Wifi, '/wifi')
1819
api.add_resource(Laundry, '/laundry')
19-
#api.add_resource(Foo, '/Foo', '/Foo/<str:id>')
2020
#api.add_resource(UniversityDirectory, '', '')
2121
#api.add_resource(DailyIllini, '', '')
2222
#api.add_resource(Buildings, '', '')
2323
#api.add_resource(AthleticSchedule, '', '')
2424
#api.add(Maintenance, '', '')
25+
api.add_resource(FreeFood, '/freefood')
2526

2627
if __name__ == '__main__':
2728
app.run(debug=True)

resources/dining.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
from flask_restful import Resource
1+
from flask_restful import Resource, reqparse
22
import urllib2
33
import json
4+
import requests
45

56
class Dining(Resource):
67
def get(self):
7-
request_url = "https://web.housing.illinois.edu/MobileDining/WebService/Search.aspx?k=7A828F94-620B-4EE3-A56F-328036CC3C04"
8-
# Add route parameters
9-
request_url += "?id=" + hallId + "&from=" + fromDate + "&to=" + toDate + "&t=json"
10-
response = urllib2.urlopen(request_url)
11-
return json.load(response)
8+
request_url = "https://web.housing.illinois.edu/MobileDining/WebService/Search.aspx?k=7A828F94-620B-4EE3-A56F-328036CC3C04"
9+
# Add route parameters
10+
request_url += "?id=" + hallId + "&from=" + fromDate + "&to=" + toDate + "&t=json"
11+
response = urllib2.urlopen(request_url)
12+
return json.load(response)
13+
14+
def post(self, username, password):
15+
request_url = "https://webservices.admin.uillinois.edu/aitsWS/security/login/json"
16+
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '39', 'User-Agent': 'UI%20Dining/15 CFNetwork/758.1.6 Darwin/15.0.0', 'Connection': 'keep-alive', 'Accept-Language': 'en-us', 'Accept-Encoding': 'gzip, deflate', 'Proxy-Connection': 'keep-alive', 'Host': 'webservices.admin.uillinois.edu'}
17+
req = requests.post(request_url, data={'username': username, 'password': password)
18+
19+
request_url_2 = "https://web.housing.illinois.edu/MobileDining/WebService/MyBalances.asmx/CreateLongSession?k=d93b5fbd-d32c-4558-a5de-e9ab8dd6a31d-AITSWebService&netID=npant3" # build string
20+
# GET /MobileDining/WebService/MyBalances.asmx/CreateLongSession?k=7A828F94-620B-4EE3-A56F-328036CC3C04&EASID=e5654b49-6458-41c3-b662-d76eed9dada5-AITSWebService&netID=npant3 HTTP/1.1
21+
# use same headers as above
22+
payload = { 'EASID': '', 'netID': username, 'k': '7A828F94-620B-4EE3-A56F-328036CC3C04' }
23+
requests.get(request_url_2)
1224

1325

1426
# For dining/info endpoint: https://web.housing.illinois.edu/MobileDining/WebService/SettingTable.aspx?k=7A828F94-620B-4EE3-A56F-328036CC3C04&t=json&ts=5-10-2012%2014:30:00

resources/free_food.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask_restful import Resource
2+
import urllib2
3+
import json
4+
5+
class FreeFood(Resource):
6+
def get(self):
7+
response = urllib2.urlopen("http://uiucfreefood.com/appJson/")
8+
return json.load(response)

resources/weather.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import urllib2
44
import re
55

6+
data = {}
7+
68
class Weather(Resource):
79
global data
810
webpage = urllib2.urlopen('https://www.atmos.illinois.edu/weather/')
@@ -17,6 +19,7 @@ class Weather(Resource):
1719
weather_data = str(soup.find_all('font')[6])
1820

1921
match = re.compile(r'.*?>\\n(.*?)\\n')
22+
data["weather_condition"] = weather_data
2023
#data['weather_condition'] = match.search(weather_data)
2124
match = re.compile(r'Temperature:.*?([0-9]+)')
2225
data['temperature'] = match.search(weather_data).group(1)

0 commit comments

Comments
 (0)