Example #1
0
    def fetch(self, location):
                
        session = requests.Session()
        response = session.get('http://sis.jtcx.sh.cn/sisserver?highLight=false'\
                               '&srctype=USERPOI&eid=9070&extId=&agentId=&tempid=52&config=BESN'\
                               '&searchName=&cityCode=021&searchType=&number=100&batch=1'\
                               '&a_k=cb02363e90e02da4b5f3cc9dcc7f5cd0881012bd4ec0dbe0f2b5a87cea3602ad70431a4938633d15'\
                               '&resType=JSON&enc=utf-8&sr=0&ctx=1&a_nocache=')
    
        data = response2json(response.text)
        
        ret = list()

        for poi in data['poilist']:
#             if poi['uxml']['INTELLIGTYPE'] != u'高架':
#                 continue 

            loc = decode_lonlat(poi['x']), decode_lonlat(poi['y'])
            
                                            
            panel = HighwayPanel(name=poi['uxml']['INFORMATION'],
                                 location=loc,
                                 image_url='http://vms.jtcx.sh.cn:8089/VmsPic/vms/%s.gif' % poi['uxml']['INTELLIGID'],
                                 distance=distance(location, loc)
                                 )
            ret.append(panel)
            
        ret.sort(key=lambda p:p.distance)
            
        return ret[:10]
Example #2
0
    def fetch(self, location):
        """ Parking space information

        Note the offical site don't use location based query but their Mapabc
        provider supports actually supports it...

        location_encode = (encode_lonlat(location[0]), encode_lonlat(location[1]))

        session = requests.Session()
        response = session.get('http://sis.jtcx.sh.cn/sisserver?highLight=false'\
                               '&srctype=USERPOI&eid=9070&extId=&agentId=&tempid=8&config=BESN'\
                               '&cityCode=021&cenName=&searchType=&number=10&batch=1'\
                               '&a_k=cb02363e90e02da4b5f3cc9dcc7f5cd0881012bd4ec0dbe0f2b5a87cea3602ad70431a4938633d15'\
                               '&resType=JSON&enc=utf-8&sr=0&range=800&naviflag=0'\
                               '&ctx=1&a_nocache=&cenX=%s&cenY=%s' \
                               % location_encode
                               )


        data = response2json(response.text)
        """
        parking_center = ParkingInfoCenter()
        parking_center.update()
        
        available = list()
        for poi in self._data.itervalues():
            try:
                info = parking_center.get_parking_info(poi['extid'])
            except KeyError:
                continue
            baidu_loc = poi['baidu_loc']
            parkinglot = ParkingLot(name=poi['name'],
                                    location=baidu_loc,
                                    address=poi['address'],
                                    available=info['available'],
                                    total=info['total'],
                                    distance=int(distance(location, poi['location'])),
                                    image_url='http://api.map.baidu.com/staticimage?width=320&height=240&center=%(lon)s,%(lat)s&scale=1&zoom=18&markers=%(lon)s,%(lat)s&markerStyles=l,P,0x00CCFF' \
                                        % dict(lon=baidu_loc[0], lat=baidu_loc[1]),
                                    timestamp=info['timestamp']
                                    )
            
            available.append(parkinglot)
        available.sort(key=lambda p:p.distance)
        ret = list()
        count = 0
        for r in available:
            if count > 10:
                break
            if r.available <= 1 or r.total == 0:
                continue
            ret.append(r)
            count += 1

        return ret