Exemplo n.º 1
0
def rfr_triads(user_d):
    """
    find a target users with a social triangle and a recip friend not in that
    triangle. Return info about all four users.
    """
    # We are looking for this structure in the social graph:
    # my  you---our
    #   \  |  /
    #      me
    # me is a target user, the other users are contacts, and the edges are all
    # reciprocal.
    me = User(user_d)
    me_rfr = set(me.rfriends or []).intersection(me.neighbors or [])
    if len(me_rfr)<3:
        return []
    for you_id in me_rfr:
        you_ed = Edges.get_id(you_id)
        if not you_ed:
            continue #There are no edges for this neighbor.
        ours = me_rfr.intersection(you_ed.friends,you_ed.followers)
        mine = me_rfr.difference(you_ed.friends,you_ed.followers)
        if ours and mine:
            d = dict(
                me = dict(_id=me._id,loc=me.median_loc),
                you = dict(_id=you_id),
                my = dict(_id=random.choice(list(mine))),
                our = dict(_id=random.choice(list(ours))),
                )
            for k,v in d.iteritems():
                if k=='me': continue
                gnp = User.get_id(v['_id'],fields=['gnp']).geonames_place.to_d()
                gnp.pop('zipcode',None)
                v['loc'] = gnp
            return [d]
    return []
Exemplo n.º 2
0
 def test_find_contacts_errors(self):
     self.FS["mloc_users.04"] = [dict(id=404)]
     self.FS["mloc_users.03"] = [dict(id=503)]
     with _patch_twitter():
         self.gob.run_job("find_contacts")
     for uid in (404, 503):
         missing = User.get_id(uid)
         self.assertEqual(missing.error_status, uid)
         self.assertEqual(missing.neighbors, None)
         self.assertEqual(missing.rfriends, None)
         self.assertEqual(Edges.get_id(uid), None)
         self.assertEqual(Tweets.get_id(uid), None)
Exemplo n.º 3
0
def total_contacts(user_ds):
    """
    count the total number of contacts (to include in the paper)
    """
    for user_d in itertools.islice(user_ds,2600):
        user = User.get_id(user_d['id'])

        if not user:
            yield "no user"
        elif user.error_status:
            yield str(user.error_status)
        else:
            edges = Edges.get_id(user._id)
            tweets = Tweets.get_id(user._id)
            if not edges or not tweets:
                yield "no contacts"
            else:
                sets = _contact_sets(tweets,edges)
                yield [len(sets[k]) for k in User.NEBR_KEYS]
Exemplo n.º 4
0
def _fetch_edges(twit,uid):
    edges = Edges.get_id(uid)
    if not edges:
        edges = twit.get_edges(uid)
        edges.save()
    return edges