コード例 #1
0
ファイル: views.py プロジェクト: daaku/weekend
def menu(request):
    if 'lat' in request.GET and 'lon' in request.GET and 'restaurant' in request.GET:

        lat = request.GET['lat']                   # 37.4248085022
        lon = request.GET['lon']                   # -122.074012756
        restaurant = request.GET['restaurant']     # Country Deli
        restaurantName= request.GET['restaurant']     # Country Deli

        friends = items_in_graph(request, restaurant)

        params = {
            'q': "select * from xml where url='http://api.boorah.com/restaurants/WebServices/RestaurantSearch?radius=15&sort=distance&start=0&lat=%s&long=%s&name=%s&auth=%s' and itemPath = 'Response.ResultSet.Result'" % (lat, lon, quote(restaurant), settings.BOORAH_API_KEY),
            'format': 'json',
        }
        response = json.loads(unicode(yahoo_oauth.make_signed_req(YQL_PUBLIC_URL, content=params).read(), 'utf-8'))

        menu = []
        try:
            # get restaurant json - then fetch menu url - then fetch yql menu

            # allmenus_yql = select * from html where url='http://www.allmenus.com/ca/mountain-view/123349-quiznos-sub/menu/' and xpath='//div[@class="menu_item"]'
            # menupages_yql = select * from html where url='http://www.menupages.com/Partnermenu.asp?partner=7&restaurantId=10522&t=1235342717&auth=4b479e7b075fef07b533cd1acee30369' and xpath='//div[@id="restaurant-menu"]/table/tbody/tr/th'

	    restaurant = response['query']['results']['Result'][0]
            link = restaurant['LinkSet']['Link']

            if link['type'] == 'menu':
                params = {
                    'q': "select * from html where url='%s' and xpath = '//iframe'" % (link['url']),
                    'format': 'json',
                }
                menu = json.loads(unicode(yahoo_oauth.make_signed_req(YQL_PUBLIC_URL, content=params).read(), 'utf-8'))['query']['results']['iframe']['src']

                if 'allmenus' in menu:
                    response = yahoo_oauth.make_signed_req(menu)
                    response = yahoo_oauth.make_signed_req('http://allmenus.com' + response.getheader('location'))

                    params = {
                        'q': "select * from html where url='%s' and xpath='//div[@class=\"menu_item\"]'" % ('http://allmenus.com' + response.getheader('location')),
                        'format': 'json',
                    }

                    data = json.loads(unicode(yahoo_oauth.make_signed_req(YQL_PUBLIC_URL, content=params).read(), 'utf-8'))
                    menu = data['query']['results']['div']

        except:
            pass

        return HttpResponse(render('common/menu.html', { 'menu': menu, 'friends': friends, 'restaurant': restaurantName  }))

    else:
        return HttpResponseRedirect('/')

    return HttpResponse()
コード例 #2
0
ファイル: yosdk.py プロジェクト: daaku/weekend
def geocode(request, location):
    access_token = yahoo_oauth.get_access_token(request)
    params = {
        'q': 'select * from geo.places where text="' + location + '"',
        'format': 'json',
    }
    response = yahoo_oauth.make_signed_req(YQL_URL, content=params, token=access_token, request=request)
    body = json.loads(unicode(response.read(), 'utf-8'))['query']['results']['place'][0]['centroid']
    return body
コード例 #3
0
ファイル: yosdk.py プロジェクト: daaku/weekend
def social_graph(request):
    access_token = yahoo_oauth.get_access_token(request)
    params = {
        'q': 'select * from social.profile (0, 9999) where guid in (select guid from social.connections (0, 9999) where owner_guid=me)',
        'format': 'json',
    }
    response = yahoo_oauth.make_signed_req(YQL_URL, content=params, token=access_token, request=request)
    body = json.loads(unicode(response.read(), 'utf-8'))['query']['results']['profile']
    return body
コード例 #4
0
ファイル: views.py プロジェクト: daaku/weekend
def places(request):
    if 'lat' in request.GET and 'lon' in request.GET:
        lat = request.GET['lat']     # 37.4248085022
        lon = request.GET['lon']     # -122.074012756

        params = {
            'q': "select * from xml where url='http://api.boorah.com/restaurants/WebServices/RestaurantSearch?radius=15&sort=distance&start=0&lat=%s&long=%s&auth=%s' and itemPath = 'Response.ResultSet.Result'" % (lat, lon, settings.BOORAH_API_KEY),
            'format': 'json',
        }

        response = json.loads(unicode(yahoo_oauth.make_signed_req(YQL_PUBLIC_URL, content=params).read(), 'utf-8'))

        if 'query' in response:
            restaurants = response['query']['results']['Result']
        else:
            restaurants = []

        return HttpResponse(render('common/places.html', { 'places': restaurants }))

    else:
        return HttpResponseRedirect('/')
コード例 #5
0
ファイル: yosdk.py プロジェクト: daaku/weekend
def updates(request, descr, title, link):
    access_token = yahoo_oauth.get_access_token(request)
    guid = access_token['xoauth_yahoo_guid']
    source = "APP.JUqAuh5g"
    suid = random.randrange(0, 101)
    body = '''
    { "updates":
        [
            {
                "class": "app",
                "collectionType": "guid",
                "description": "%s",
                "suid": "%s",
                "link": "%s",
                "source": "%s",
                "pubDate": "%s",
                "title": "%s",
                "type": "appActivity",
                "collectionID": "%s"
            }
        ]
    }''' % (descr, suid, link, source, int(time.time()), title, guid)
    response = yahoo_oauth.make_signed_req("%s/user/%s/updates/%s/%s" % (YOS_URL, guid, source, suid), method='PUT', content=body, token=access_token, request=request)
    return response.status