Skip to content

Commit a700ba0

Browse files
author
Georgi Tenev
committed
Merge branch 'release/first_release'
Conflicts: application/static/img/Thumbs.db application/static/js/home.js application/static/js/main.js application/templates/base.html
2 parents b86e215 + 0f77b9d commit a700ba0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5062
-649
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ venv
1111

1212
# Don't store secret keys in version control
1313
secret_keys.py
14+
application/static/js/Thumbs.db
15+
application/static/img/Thumbs.db

app.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
application: cobalt-mantis-732
1+
application: terra-cognita
22
version: 1
33
runtime: python27
44
api_version: 1

application/api/servers/airquality.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import urllib2
2+
import json
3+
import sys
4+
5+
from google.appengine.api import users
6+
from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
7+
from flask import request, render_template, flash, url_for, redirect, Blueprint
8+
from flask_cache import Cache
9+
from application.decorators import login_required, admin_required
10+
from application.forms import ExampleForm
11+
from application.models import ExampleModel
12+
from application import app
13+
from application.api.servers.xmltodict import xmltodict
14+
15+
def getData():
16+
url = 'http://uk-air.defra.gov.uk/assets/rss/current_site_levels.xml'
17+
18+
f = urllib2.urlopen(url)
19+
xmldata = f.read()
20+
f.close()
21+
22+
data = xmltodict.parse(xmldata)
23+
data = data['rss']['channel']['item']
24+
jsondata = json.dumps(data)
25+
26+
return jsondata

application/api/servers/foodstandartsagency.py

+57-8
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,70 @@
1212

1313
from flask_cache import Cache
1414

15-
16-
1715
from application.decorators import login_required, admin_required
1816
from application.forms import ExampleForm
1917
from application.models import ExampleModel
2018

2119
from application import app
2220

23-
# Flask-Cache (configured to use App Engine Memcache API)
24-
cache = Cache(app)
2521

26-
def getData(name, location, format):
27-
url = "http://ratings.food.gov.uk/search/" + name + "/" + location + "/" + format
28-
data = urllib2.urlopen(url)
22+
url = 'http://ratings.food.gov.uk/'
23+
format = 'json'
24+
25+
#private
26+
def getData():
27+
global url, format
28+
29+
try:
30+
#obtaining the data in order to get the number of entries
31+
data = json.load(urllib2.urlopen(url + '/' + format))
32+
33+
#building the new url setting the parameter PageSize to be equal to the number of entries
34+
url += '/1/' + data['FHRSEstablishment']['Header']['ItemCount'] + '/' + format
35+
36+
data = urllib2.urlopen(url, timeout=20)
37+
except Exception as e:
38+
url = 'http://ratings.food.gov.uk/'
39+
raise
40+
#for testing purposes
41+
#print url
42+
#print json.load(data)
43+
44+
#reseting the url
45+
url = 'http://ratings.food.gov.uk/'
2946
#remove the headers, and only get the relevant info
3047
result = json.load(data)['FHRSEstablishment']['EstablishmentCollection']['EstablishmentDetail']
48+
result = json.dumps(result)
49+
50+
return result
51+
52+
#IMPORTANT!
53+
#
54+
#In order to get data for every location or every restaurant pass 'all' as a value (e.g. searchNameLoc(all, southampton))
55+
def searchNameLoc(name, location):
56+
global url
57+
if name == 'all':
58+
name = '^'
59+
if location =='all':
60+
location = '^'
61+
url += 'search/' + name + "/" + location
62+
return getData()
63+
64+
def searchName(name):
65+
global url
66+
67+
if name == 'all':
68+
name = '^'
69+
url += 'search-name/' + name
70+
return getData()
71+
72+
def searchLoc(location):
73+
global url
74+
if location =='all':
75+
location = '^'
76+
url += 'search-address/' + location
77+
return getData()
3178

32-
return result
79+
#searchNameLoc('tesco','southampton')
80+
#searchName('parfait')
81+
#searchLoc('southampton')

application/api/servers/geocoding.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
handles interaction with the worldbank api
3-
4-
"""
51
import urllib2
62
import json
73

@@ -36,15 +32,24 @@
3632

3733
components = "components=country:UK"
3834
def getData(address):
35+
address = urllib2.quote(address, safe="%/:=&?~#+!$,;'@()*[]")
3936
url = "https://maps.googleapis.com/maps/api/geocode/json?address="+address+"&"+components+"&"+"sensor=false"+"&"+"key="+API_KEY
4037
request = urllib2.urlopen(url)
41-
result = json.load(request)
38+
#result = json.load(request)
4239

40+
return request.read()
41+
42+
def getBounds(address):
43+
locationData = json.loads(getData(address))
44+
try:
45+
bounds = locationData["results"][0]["geometry"]["bounds"]
46+
except Exception, e:
47+
bounds = locationData["results"][0]["geometry"]["viewport"]
48+
result = [[bounds["northeast"]["lat"], bounds["northeast"]["lng"]],[bounds["southwest"]["lat"], bounds["southwest"]["lng"]]]
4349
return result
4450

45-
46-
47-
48-
49-
50-
51+
def getCoordinates(address):
52+
locationData = json.loads(getData(address))
53+
location = locationData["results"][0]["geometry"]["location"]
54+
result = [location["lat"], location["lng"]]
55+
return result

application/api/servers/houses.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import urllib2
2+
import json
3+
4+
from google.appengine.api import users
5+
from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
6+
from flask import request, render_template, flash, url_for, redirect, Blueprint
7+
from flask_cache import Cache
8+
from application.decorators import login_required, admin_required
9+
from application.forms import ExampleForm
10+
from application.models import ExampleModel
11+
from application import app
12+
13+
url = 'http://api.nestoria.co.uk/api?'
14+
format = 'json'
15+
country = 'uk'
16+
pretty = '1'
17+
18+
#private
19+
def getData():
20+
global url
21+
22+
#for testing purposes
23+
# print url
24+
# print json.load(data)
25+
try:
26+
data = urllib2.urlopen(url+'1')
27+
data = json.load(data)
28+
total_pages = int(data['response']['total_pages'])
29+
if total_pages > 20:
30+
total_pages = 20
31+
32+
result = '['
33+
34+
for i in range(0, total_pages):
35+
data = urllib2.urlopen(url + str(i+1))
36+
data = json.load(data)
37+
38+
result += json.dumps(data['response']['listings'])[1:-1] + ', '
39+
except Exception as e:
40+
url = 'http://api.nestoria.co.uk/api?'
41+
raise
42+
43+
44+
result = result[:-2] + ']'
45+
46+
url = 'http://api.nestoria.co.uk/api?'
47+
48+
return result
49+
50+
#private
51+
def urlBuild(req):
52+
global url
53+
54+
url += 'pretty=' + pretty + '&'
55+
56+
if(type(req) is str):
57+
url += 'place_name=' + req + '&'
58+
59+
elif(req and len(req) == 4):
60+
if(req[3] == 'km' or req[3] == 'mi'):
61+
url += 'centre_point=' + str(req[0]) + ',' + str(req[1]) + ',' + str(req[2]) + req[3] + '&'
62+
elif(req[3]):
63+
url += 'south_west=' + str(req[0]) + ',' + str(req[1]) + '&north_east=' + str(req[2]) + ',' + str(req[3]) + '&'
64+
65+
66+
#req is expected to be a name of a plcae or an array with 4 elements with either
67+
# 4 numbers indicating the lat,lng of the south west and north east points of the area
68+
# OR
69+
# 3 numbers indicating the lat,lng of a point that is going to be considered a center of the area
70+
# followed by the radius and either 'km' or 'mi' as the last 4th element
71+
def getListing(req,listing_type):
72+
global url
73+
74+
urlBuild(req)
75+
76+
url += 'encoding=' + format + '&action=search_listings&country=' + country + "&listing_type=" + listing_type + "&number_of_results=50&page="
77+
return getData()
78+
79+
#getListing([51,-3,10,'km'],'rent')
80+
#getListing('southampton','buy')

0 commit comments

Comments
 (0)