Example #1
0
def graphOut(DG):
    writer=gf.GEXFWriter(encoding='utf-8',prettyprint=True,version='1.1draft')
    writer.add_graph(DG)
    print tostring(writer.xml)
    #that is, for each unique recent user of the search term...
    if debug: print 'getting friends of',user
    #grab the friends of the current user
    friends=tweepy.Cursor(tweepy.api.friends_ids,id=user).items()
    #we're now going to look through the friends list to see if any friends are recent searchterm users themselves
    for friend in friends:
        if friend in sender_ids:
            #if they are, add them to the graph with an edge from user to friend
            DG.add_edge(user,friend)


#networkx has a variety of file export filters available, such as GEXF
#gexf files can be imported directly into a tool such as Gephi (gephi.org)
import networkx.readwrite.gexf as gf

writer=gf.GEXFWriter(encoding='utf-8',prettyprint=True,version='1.1draft')
writer.add_graph(DG)

try:
    import scraperwiki
    scraperwiki.utils.httpresponseheader("Content-Type", "text/xml")
except:
    pass

try:
    from xml.etree.cElementTree import tostring
    print tostring(writer.xml)
except:
    print 'You need to find a way of printing out the XML object...'

#If you run/preview this view in scraperwiki, assuming you haven't maxed out on the Twitter API,