def weibotools(request): #get url that need to be searched if request.GET.has_key('searchurl'): url = request.GET['searchurl'] try: path = WeiboSpreadPath(get_pincode(), url) id = path.get_weiboid_from_url() #generate gexf file filename = os.getcwd() + '/weibo/gexf/' + str(id) + '_' + url.split('/')[-2] gexfURI = '/themes/gexf/' + str(id) + '_' + url.split('/')[-2] + '.gexf' #judge whether the gexf file is already existed if os.path.exists(filename+'.gexf') is not True: path.generate_gexf(filename, path.get_edges(post_id=id)) return render_to_response('weibotools.html', {'gexfURI':gexfURI}) except: errormsg = "Invalid url." return render_to_response('weibotools.html', {'error':errormsg}) return render_to_response('weibotools.html')
twolnodes[0] = twolnodes[0] + 1 if rootnode != edge[1] and onelnodes[1].count(edge[1]) == 0 and twolnodes[1].count(edge[1]) == 0: twolnodes[1].append(edge[1]) nodes.pop(nodes.index(edge[1])) # third level threelnodes = [0, []] for edge in edges: if twolnodes[1].count(edge[0]) == 1: threelnodes[0] = threelnodes[0] + 1 if ( rootnode != edge[1] and onelnodes[1].count(edge[1]) == 0 and twolnodes[1].count(edge[1]) == 0 and threelnodes[1].count(edge[1]) == 0 ): threelnodes[1].append(edge[1]) nodes.pop(nodes.index(edge[1])) # fourth+ level fourlnodes = [len(nodes), nodes] print onelnodes, twolnodes, threelnodes, fourlnodes if __name__ == "__main__": path = WeiboSpreadPath(get_pincode(), "http://weibo.com/1733745982/z4BcwqmBa") # path = WeiboSpreadPath('2.00sWc1tBRbe3eC1c3a09166cP6fhRE', 'http://weibo.com/1400229064/zdwGs7kqZ') id = path.get_weiboid_from_url() # path.generate_dot('example', path.get_edges(post_id=id)) nodes, edges = path.generate_gexf("gexf/example", path.get_edges(post_id=id)) path.analysis(nodes, edges)