コード例 #1
0
ファイル: sprawl.py プロジェクト: JeffAMcGee/friendloc
def find_contacts(user_ds):
    """
    for each target user, fetch edges and tweets, pick 100 located contact ids
    """
    gis = gisgraphy.GisgraphyResource()
    twit = twitter.TwitterResource()
    for user_d in itertools.islice(user_ds,2600):
        user = User.get_id(user_d['id'])
        if user:
            logging.warn("not revisiting %d",user._id)
        else:
            user = User(user_d)
            user.geonames_place = gis.twitter_loc(user.location)
            _save_user_contacts(twit, user, _pick_random_contacts, limit=100)
        for mod_nebr in _my_contacts(user):
            yield mod_nebr
コード例 #2
0
ファイル: full.py プロジェクト: JeffAMcGee/friendloc
    def predict(self, user_d, steps=0):
        """
        Attept to locate a Twitter user.
            user_d should be a Twitter-style user dictionary
            steps is the number of steps on the social graph to crawl. It should
                be 0, 1, or 2. If 0, predict makes no Twitter API calls, 1 uses
                4 calls, and 2 uses around 80 API calls.
        returns (longitude, latitude) or None if no location can be found
        """
        user = User(user_d)
        if steps == 0 and not user.location:
            return None

        gnp = self.gis.twitter_loc(user.location)

        if steps == 0:
            return gnp.to_tup() if gnp else None

        if gnp and gnp.mdist < MAX_GNP_MDIST:
            user.geonames_place = gnp
            return gnp.to_tup()

        _crawl_pred_one(user, self.twit, self.gis, self.pred, fast=(steps == 1))
        return user.pred_loc