Exemplo n.º 1
0
 def get_cached_or_create_item(self, uid, it):
     from .models import ProxyMileItem
     itemid = 'item#' + uid
     if settings.USE_CACHE:
         if cache.has_key(itemid):
             item = cache.get(itemid)
             print 'hit item'
     else:
         ext = BaiduMap.search_detail_verbose(uid)['content']['ext']
         lng, lat = self.convert_BD09_to_GCJ02((it['location']['lng'], it['location']['lat']))
         locstr = self.to_loc_str(lng, lat)
         pic = self.pick_image_From_ext_info(ext)
         author = Author.objects.get(user__username='******')
         item = ProxyMileItem(title=it['name'],
                              uid=uid,
                              publishTime=datetime.now(pytz.utc),
                              category=it['category'],
                              address=it['address'],
                              POIName=it['category'] + '(' + it['address'] + ')',
                              picOne=pic, #'http://apis.map.qq.com/ws/streetview/v1/image?size=600x480&location=%s&pitch=0&heading=0&key=LF2BZ-5WHWR-ZONWQ-WBMHI-VUPOQ-JNBSA' % locstr,
                              coordinate=Point(it['location']['lng'], it['location']['lat']),
                              author=author,
                              )
         if 'distance' in it['detail_info']: item.distance = it['detail_info']['distance']   
         cache.set(itemid, item, timeout=3600*24)
     return item
Exemplo n.º 2
0
 def search(self, q, loc, radius=1000):
    from .serializers import POISerializer
    pois = BaiduMap.search_distance(q, loc, radius)
    for item in pois['results']:
        # print item
        # print item['name']
        # print item['location']
        uid = item.get('uid')
        # print uid
        info = super(BaiduPOIManager, self).get_queryset().filter(bdpoi_id=uid)
        if info:
            info = info[0]
            item.update(POISerializer(info).data)
    return pois
Exemplo n.º 3
0
 def search(self, q, loc, radius):
     from .models import Voting
     """ 融合百度POI数据和自有数据
         point: 中心点坐标 tuple (lat, png)
         dist: 到中心点距离
     """
     loc = self.convert_GCJ02_to_BD09(loc)
     items = []
     res = BaiduMap.search_around(q=q, loc=reversed(loc), radius=radius)
     if res['message'] == 'ok':
         for it in res['results']:
             it['category'] = q
             item = self.get_cached_or_create_item(it['uid'], it)
             try:
                 voting = Voting.objects.get(item_id=item.pk)
                 item.voting = voting 
             except: 
                 item.voting = Voting(vote=0, unvote=0)
             items.append(item)
         return sorted(items, key=lambda x: x.voting.vote, reverse=True)
Exemplo n.º 4
0
 def search(self, q, loc, radius):
     """ 融合百度POI数据和自有数据
         point: 中心点坐标 tuple (lat, png)
         dist: 到中心点距离
     """
     if not isinstance(loc, Point):
         point = Point(loc)
     base = super(AroundManager, self)
     local = base.get_queryset().filter(coordinate__distance_lte=(point, radius))
     remote  = []
     pois = BaiduMap.search_distance(q, reversed(loc), radius)
     for res in pois['results']:
       item = RecommendItem(title=res['name']+'(test)', summary=u'推荐理由:xxxxxx')
       item.publishTime = datetime.now(pytz.utc)
       item.id = None
       item.uid = res['uid']
       item.category = q
       item.picOne = 'http://res.cloudinary.com/filesbed/image/upload/v1445245936/sample.jpg'
       item.picTwo = 'http://res.cloudinary.com/filesbed/image/upload/v1445245936/sample.jpg'
       item.picThr = 'http://res.cloudinary.com/filesbed/image/upload/v1445245936/sample.jpg'
       item.coordinate = Point(res['location']['lng'], res['location']['lat'])
       item.isLarge = random.choice([True, False])
       remote.append(item)
     return list(local) +  remote
Exemplo n.º 5
0
 def search_detail(self, uid):
     from .models import ProxyMileItem
     it = BaiduMap.search_detail_official(uid)['result']
     it['category'] = it['detail_info']['tag'].split(';')[0]
     item = self.get_cached_or_create_item(uid, it)
     return item