Example #1
0
def getSecondaryInfo(client, term):
    if 'sec'+term in cache:
        return cache['sec'+term]    
    
    dConns = getDirectInfo(client, term)
    locations = getSecondaryFollowerLocations(client, dConns)
    dloc = {}
    for k, val in locations.iteritems():
        vv=[]
        for i in dConns:
            if i['userid']==k:
                v1,v2 = i['lat'], i['long']
                break
        for elem in val:
            url = "http://dev.virtualearth.net/REST/v1/Locations?query="+urllib.quote(elem.encode('ascii','ignore'))+"&output=json&key=Ar31XPc8UKrmZMDPsEVNjdAcz4yyfLtrqAkSKrNnd-RQVpFUqz4xZH1UqqTOraQI"
            r = st.connect(url)
            try:
                d = json.loads(r)
            except:
                d=r
        try:
            lt = d['resourceSets'][0]['resources'][0]['point']['coordinates'][0]
        except: lt = ""
        try:
            lng = d['resourceSets'][0]['resources'][0]['point']['coordinates'][1]
        except: lng = ""

        vv.append([lt,lng])

        dloc[str(v1,v2)]=vv

    cache['sec'+term] = dloc
    return dloc
Example #2
0
def getDirectConnections(statuses, term):
    directConnections = []
    for status in statuses:
        if term in status.user.name:
            continue
        if status.user.location:    
            url = "http://dev.virtualearth.net/REST/v1/Locations?query="+urllib.quote(status.user.location.encode('ascii','ignore'))+"&output=json&key=Ar31XPc8UKrmZMDPsEVNjdAcz4yyfLtrqAkSKrNnd-RQVpFUqz4xZH1UqqTOraQI"
            r=st.connect(url)
            try:
                d = json.loads(r)
            except:
                d=r
        try:
            lt = d['resourceSets'][0]['resources'][0]['point']['coordinates'][0]
        except: lt = ""

        try:
            lng = d['resourceSets'][0]['resources'][0]['point']['coordinates'][1]
        except:
            lng = ""
        
        dConn = dict(text=status.text, name=status.user.name, lat=lt, long=lng, location=status.user.location, userid=status.user.id_str, sentiment=st.sentiment(status.text, term), weight=status.user.followers_count)
        directConnections.append(dConn)
    return directConnections