示例#1
0
from cornice.service import Service

from appartmapp.immoscoutapi import sanitize_is24
from restbase import path

search = Service(name='search', path=path('search'), renderer='json')

@search.get(accept='application/json')
def query(request):
	results = request.is24api.radius_search('apartmentrent', '51.5','10.5','500')
	results = results['resultlist.resultlist']['resultlistEntries'][0]['resultlistEntry']
	results = [sanitize_is24(item) for item in results]
	return dict(results=results)

示例#2
0
from cornice.service import Service
from restbase import path
import psycopg2
import math
search = Service(name='others', path=path('others'), renderer='json')


def distance(p0, p1):
    return math.sqrt((float(p0[0]) - float(p1[0]))**2 +
                     (float(p0[1]) - float(p1[1]))**2)


@search.get(accept='application/json')
def query(request):
    if "lat" in request.GET:
        lat = request.GET["lat"]
    else:
        lat = "50.5"
    if "lng" in request.GET:
        lng = request.GET["lng"]
    else:
        lng = "10.5"
    if "dist" in request.GET:
        dist = request.GET["dist"]
    else:
        dist = "0.1"
    con = psycopg2.connect(database='appartmapp', user='******')
    cur = con.cursor()
    cur.execute('SELECT * from items')
    rows = cur.fetchall()
    result = [(row) for row in rows
示例#3
0
文件: appinfo.py 项目: Doik/rest-seed
from cornice.service import Service
from pyramid.settings import asbool

from restbase import path


app_info = Service(name='appinfo', path=path(''),
    renderer='json', accept='application/json')


@app_info.get()
def get_app_info(request):
    settings = request.registry.settings
    result = dict(debug=asbool(settings.debug), demo=asbool(settings.demo))
    if request.user is None:
        result['authenticated'] = False
    else:
        result['authenticated'] = True
        result['user'] = request.user
    return result
示例#4
0
from cornice.service import Service
from restbase import path
import psycopg2
import math
search = Service(name='others', path=path('others'), renderer='json')
def distance(p0, p1):
    return math.sqrt((float(p0[0]) - float(p1[0]))**2 + (float(p0[1]) - float(p1[1]))**2)
@search.get(accept='application/json')
def query(request):
	if "lat" in request.GET:
		lat=request.GET["lat"]
	else:
		lat="50.5"
	if "lng" in request.GET:
		lng=request.GET["lng"]
	else:
		lng="10.5"
	if "dist" in request.GET:
		dist=request.GET["dist"]
	else:
		dist="0.1"
	con = psycopg2.connect(database='appartmapp', user='******') 
	cur = con.cursor()
	cur.execute('SELECT * from items')
	rows = cur.fetchall()
	result = [(row) for row in rows if (distance((lat, lng), (row[4], row[5])) <= float(dist))]
	return dict(results=result)

示例#5
0
from cornice.service import Service

from appartmapp.immoscoutapi import sanitize_is24
from restbase import path

search = Service(name='search', path=path('search'), renderer='json')


@search.get(accept='application/json')
def query(request):
    results = request.is24api.radius_search('apartmentrent', '51.5', '10.5',
                                            '500')
    results = results['resultlist.resultlist']['resultlistEntries'][0][
        'resultlistEntry']
    results = [sanitize_is24(item) for item in results]
    return dict(results=results)