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