示例#1
0
文件: default.py 项目: kailu/GrouponX
    def bidder():
        #get ip from parms
        ip_str = params.get('ip',None)
        d = baidu.getAddressByIP(ip_str)
        try:
            d = json.loads(d)
            city = d['content']['address_detail']['city']

            if city.endswith(u"市"):
                city = city[:-1]
            city = city.encode('utf-8')
            #call dianping API
            gpons = dianping.getGrouponByCity(city)
            gpons = utils.filter_deals(gpons,conf)
            return gpons
        except Exception as ex:
            print ex
            return None
示例#2
0
    def bidder():
        #get ip from parms
        ip_str = params.get('ip',None)
        d = baidu.getAddressByIP(ip_str)
        try:
            d = json.loads(d)
            city = d['content']['address_detail']['city']

            if city.endswith(u"市"):
                city = city[:-1]
            city = city.encode('utf-8')
            #call dianping API
            gpons = dianping.getGrouponByCity(city)
            gpons = utils.filter_deals(gpons,conf)
            #sort result based on discount
            gpons = sorted(gpons, key = lambda record : record['current_price'], reverse=True)
            return gpons
        except Exception as ex:
            print ex
            return None