コード例 #1
0
    def access_force(self, timeout=3):
        url = self.url_for_access
        if url.startswith('http'):
            super(LegacyPlace, self).access_force(timeout=timeout)
            return

        result = None
        if url.startswith('4square'):
            from foursquare import Foursquare
            client = Foursquare(client_id=FOURSQUARE_CLIENT_ID,
                                client_secret=FOURSQUARE_CLIENT_SECRET)
            result = client.venues(url.split('//')[1])
        elif url.startswith('google'):
            result = self.access_force_google(url)
        else:
            raise NotImplementedError

        if result:
            result = json_dumps(result, ensure_ascii=False)
            file = Path(self.path_accessed)
            if not file.parent.exists():
                file.parent.mkdir(parents=True)
            summary = Path(self.path_summarized)
            if not Path(self.path_summarized).parent.exists():
                summary.parent.mkdir(parents=True)
            file.write_text(result)
            self._cache_accessed = result.replace('\r', '')
コード例 #2
0
def popular_hashtags(lat, long):
    hashtags = {}
    fs = Foursquare()
    venues = fs.venues(lat, long, 10)
    for v in venues:
        #print "Venue: ", v.name
        results = twitter_call(v.name, (lat,long,radius))
        for s in results:
            ht = parse_hashtags(s.text)
            for h in ht:
                if hashtags.has_key(h):
                    hashtags[h] = hashtags[h]+1
                else:
                    hashtags[h] = 1
    return hashtags