Esempio n. 1
0
    def _convert_feed(self, json, since):
        """Take the raw json from the feed and convert it to ServiceItems.
        """

        items = []
        if json and json['response'].has_key('checkins'):
            for checkin in json['response']['checkins']['items']:
                created = datetime.fromtimestamp(checkin['createdAt'])

                if created.date() >= since:
                    item = ServiceItem()
                    item.location = {}
                    item.link_back = 'http://foursquare.com/venue/%s' % (checkin['venue']['id'],)
                    item.title = checkin['venue']['name']

                    if checkin.has_key('shout') and checkin['shout']:
                        item.body = checkin['shout']
                    else:
                        if len(checkin['venue']['categories']) > 0 and checkin['venue']['location'].has_key('city'):
                            item.body = "A %s in %s" % (checkin['venue']['categories'][0]['name'], checkin['venue']['location']['city'])
                        elif checkin['venue'].has_key('city'):
                            item.body = "In %s" % (checkin['venue']['location']['city'])
                        else:
                            item.body = "%s" % (checkin['venue']['name'])

                    if checkin['venue']['location'].has_key('lat') and checkin['venue']['location']['lng']:
                        item.location['lat'] = checkin['venue']['location']['lat']
                        item.location['long'] = checkin['venue']['location']['lng']

                    item.created = created
                    item.service = self.service
                    
                    if checkin.has_key('isMayor'):
                        item.is_mayor = checkin['isMayor']
                    else:
                        pass

                    if checkin['venue'].has_key('categories') and len(checkin['venue']['categories']) > 0:
                        item.icon = checkin['venue']['categories'][0]['icon']
                        item.categories = checkin['venue']['categories']

                    items.append(item)
                    del(item)

        return items
Esempio n. 2
0
    def _create_checkin(self, checkin):
        """Convert a raw checkin into a service item"""
        
        item = ServiceItem()
        created = None
        if checkin.has_key('createdAt'):
            created = datetime.fromtimestamp(checkin['createdAt'])
        item.location = {}
        item.link_back = 'http://foursquare.com/venue/%s' % (checkin['venue']['id'],)
        item.title = checkin['venue']['name']
        
        if checkin['venue'].has_key('location') and checkin['venue']['location'].has_key('city'):
            item.city = checkin['venue']['location']['city']

        if checkin.has_key('shout') and checkin['shout']:
            item.body = checkin['shout']
        else:
            if len(checkin['venue']['categories']) > 0 and checkin['venue']['location'].has_key('city'):
                item.body = "A %s in %s" % (checkin['venue']['categories'][0]['name'], checkin['venue']['location']['city'])
            elif checkin['venue'].has_key('city'):
                item.body = "In %s" % (checkin['venue']['location']['city'])
            else:
                item.body = "%s" % (checkin['venue']['name'])

        if checkin['venue']['location'].has_key('lat') and checkin['venue']['location']['lng']:
            item.location['lat'] = checkin['venue']['location']['lat']
            item.location['long'] = checkin['venue']['location']['lng']

        if created:
            item.created = created
        item.service = self.service
        
        if checkin.has_key('isMayor'):
            item.is_mayor = checkin['isMayor']
        else:
            pass

        if checkin['venue'].has_key('categories') and len(checkin['venue']['categories']) > 0:
            item.icon = checkin['venue']['categories'][0]['icon']
            item.categories = checkin['venue']['categories']
        
        return item
Esempio n. 3
0
def _convert_feed(serv, user, json, since):
    """Take the raw json from the feed and convert it to
    ServiceItems."""
    
    items = []
    
    if json and json.has_key('checkins'):
        for checkin in json['checkins']:

            # grab the +0000 bit on the end of the date and use it make the time right
            offset = checkin['created'].rsplit(' ')[-1]
            offset = offset[1:]
            offset = offset[:2]

            time_offset = timedelta(hours=int(offset))
            
            created = datetime.strptime(checkin['created'].replace(' +0000', ''), '%a, %d %b %y %H:%M:%S') #'Fri, 04 Feb 11 12:42:38 +0000'
            created = created + time_offset
            
            if created.date() >= since:
                item = ServiceItem()
                item.location = {}
                item.link_back = 'http://foursquare.com/venue/%s' % checkin['venue']['id']
                item.title = checkin['venue']['name']
                if checkin.has_key('shout') and checkin['shout']:
                    item.body = checkin['shout']
                else:
                    item.body = checkin['venue']['city']
                if checkin['venue'].has_key('geolat') and checkin['venue']['geolat']:
                    item.location['lat'] = checkin['venue']['geolat']
                    item.location['long'] = checkin['venue']['geolong']
                item.created = created
                item.service = serv
                if checkin['venue'].has_key('primarycategory'):
                    item.icon = checkin['venue']['primarycategory']['iconurl']
                item.user = user
                items.append(item)
                del(item)
    
    return items