Skip to content

Instantly share code, notes, and snippets.

@PaladhiDinesh
Last active April 8, 2020 11:53
Show Gist options
  • Save PaladhiDinesh/56e1843c31960ecfe919 to your computer and use it in GitHub Desktop.
Save PaladhiDinesh/56e1843c31960ecfe919 to your computer and use it in GitHub Desktop.
Webscience Assignment 6 - 1

Use D3 to visualize your Twitter followers. Use my twitter account ("@phonedude_mln") if you do not have >= 50 followers. For example, @hvdsomp follows me, as does @mart1nkle1n. They also follow each other, so they would both have links to me and links to each other.

To see if two users follow each other, see: https://dev.twitter.com/rest/reference/get/friendships/show

Attractiveness of the graph counts! Nodes should be labeled (avatar images are even better), and edge types (follows, following) should be marked.

Note: for getting GitHub to serve HTML (and other media types), see: http://stackoverflow.com/questions/6551446/can-i-run-html-files-directly-from-github-instead-of-just-viewing-their-source

Be sure to include the URI(s) for your D3 graph in your report.

{
"nodes": [
{"id": 0, "image_url": "https://github.com/favicon.ico", "screen_name": "dineshpaladhi", "name": "dinesh"},
{"id": 1, "image_url": "https://pbs.twimg.com/profile_images/707802054643863552/0qY4GvI9_normal.jpg", "screen_name": "erikaris", "name": "erika siregar"},
{"id": 2, "image_url": "https://pbs.twimg.com/profile_images/3072439773/6ba21420364b003029dd9746bc4d313f_normal.jpeg", "screen_name": "doddavarunreddy", "name": "varun reddy dodda"},
{"id": 3, "image_url": "https://pbs.twimg.com/profile_images/471096249655889920/_w8DZcce_normal.jpeg", "screen_name": "9ulovesu", "name": "Naina Sai Tipparti"},
{"id": 4, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "screen_name": "kolanuvamshi", "name": "vamshi"},
{"id": 5, "image_url": "https://pbs.twimg.com/profile_images/1568577538/DSC03674_normal.JPG", "screen_name": "raviyyaahhoo", "name": "Ravi Teja"},
{"id": 6, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "ShivaniBima", "name": "Shivani Bimavarapu"},
{"id": 7, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_6_normal.png", "screen_name": "ManthenaBhavani", "name": "BhavaniManthena"},
{"id": 8, "image_url": "https://pbs.twimg.com/profile_images/709387424477155328/HTm2wPZN_normal.jpg", "screen_name": "Manoj_Chandra11", "name": "manoj Kompalli"},
{"id": 9, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "RithikaR9", "name": "Rithika Reddy"},
{"id": 10, "image_url": "https://pbs.twimg.com/profile_images/709832107959427073/P1uUGaHA_normal.jpg", "screen_name": "majetisiri", "name": "majetisiri"},
{"id": 11, "image_url": "https://pbs.twimg.com/profile_images/538505543938105344/nF7d6NLK_normal.jpeg", "screen_name": "KumarPaladhi", "name": "Manish Kumar"},
{"id": 12, "image_url": "https://pbs.twimg.com/profile_images/586118547832606722/BMXftlUa_normal.jpg", "screen_name": "Skumars317", "name": "Kumaraswamy S"},
{"id": 13, "image_url": "https://pbs.twimg.com/profile_images/579165791725039617/4tcQEqIC_normal.jpg", "screen_name": "papu100030", "name": "Prashanth Pappu"},
{"id": 14, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_6_normal.png", "screen_name": "CsUdaykumar", "name": "Uday kumar reddy cs"},
{"id": 15, "image_url": "https://pbs.twimg.com/profile_images/571888799542550528/XgGqg_Lp_normal.jpeg", "screen_name": "RithvikKranti", "name": "Rithvik"},
{"id": 16, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "screen_name": "bill_owns24x7", "name": "ashwin srinivas"},
{"id": 17, "image_url": "https://pbs.twimg.com/profile_images/544566255353483264/tjO_EMDF_normal.png", "screen_name": "TCATIndia", "name": "TCAT"},
{"id": 18, "image_url": "https://pbs.twimg.com/profile_images/1463314857/050511-1816_1__normal.jpg", "screen_name": "rlnsrlns", "name": "R.NaveenKumar"},
{"id": 19, "image_url": "https://pbs.twimg.com/profile_images/638678432264536064/gaD3MDwy_normal.jpg", "screen_name": "alokraj68", "name": "Alok Rajasukumaran"},
{"id": 20, "image_url": "https://pbs.twimg.com/profile_images/465518209760645120/abAPYUJE_normal.jpeg", "screen_name": "JPravallika", "name": "pravallika.J"},
{"id": 21, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "vamsikrishna657", "name": "vamsi krishna"},
{"id": 22, "image_url": "https://pbs.twimg.com/profile_images/3044832360/292017715cdb976fb8beadc914e59a7f_normal.jpeg", "screen_name": "maithri3", "name": "maithri devi"},
{"id": 23, "image_url": "https://pbs.twimg.com/profile_images/421993629624705025/OV-NDgmb_normal.jpeg", "screen_name": "KlaraAdrinson", "name": "KlaraAdrinson"},
{"id": 24, "image_url": "https://pbs.twimg.com/profile_images/421872619487367168/ujlz_KZH_normal.jpeg", "screen_name": "DeonneLivingsto", "name": "DeonneLivingsto"},
{"id": 25, "image_url": "https://pbs.twimg.com/profile_images/421115536521453570/aV64XZsT_normal.jpeg", "screen_name": "LatrinaMcRattig", "name": "LatrinaMcRattig"},
{"id": 26, "image_url": "https://pbs.twimg.com/profile_images/425537087308189696/rigRr-s2_normal.jpeg", "screen_name": "MommyOddenino", "name": "MommyOddenino"},
{"id": 27, "image_url": "https://pbs.twimg.com/profile_images/705051081043095552/3N6XTVIO_normal.jpg", "screen_name": "triskadieka", "name": "Nikilesh Reddy"},
{"id": 28, "image_url": "https://pbs.twimg.com/profile_images/660792009444102144/2IYlsKl-_normal.jpg", "screen_name": "urs_dineshj", "name": "Dinesh Kumar"},
{"id": 29, "image_url": "https://pbs.twimg.com/profile_images/542726155736870912/JiDjH1zA_normal.jpeg", "screen_name": "joseph_udithraj", "name": "Joseph Udith Raj"},
{"id": 30, "image_url": "https://pbs.twimg.com/profile_images/710522881050943488/pmiNj_Hz_normal.jpg", "screen_name": "mohanchandranp", "name": "Mohan Chandran. P"},
{"id": 31, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_0_normal.png", "screen_name": "VasaviMIC", "name": "Vasavi MIC"},
{"id": 32, "image_url": "https://pbs.twimg.com/profile_images/3632034965/7132e84c6af54683b61ac3016dbc9950_normal.jpeg", "screen_name": "vineethchandr12", "name": "vineeth chandra"},
{"id": 33, "image_url": "https://pbs.twimg.com/profile_images/3621303814/342611943f691b50d20c9d214da3d655_normal.jpeg", "screen_name": "Harishkumar1772", "name": "harish kumar"},
{"id": 34, "image_url": "https://pbs.twimg.com/profile_images/659075025987858432/hd_SGIYy_normal.jpg", "screen_name": "pranay2012", "name": "y.pranay reddy"},
{"id": 35, "image_url": "https://pbs.twimg.com/profile_images/574895026829832194/pX_ZKmxU_normal.jpeg", "screen_name": "Paladhi", "name": "Sandeep Paladhi"},
{"id": 36, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "BvriteceA10", "name": "vani"},
{"id": 37, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "reddy1516", "name": "madhukar reddy"},
{"id": 38, "image_url": "https://pbs.twimg.com/profile_images/3026610631/24d30a177b4a1e3d36608f0c7b1b9293_normal.jpeg", "screen_name": "Harish0123Te", "name": "Harish kumar"},
{"id": 39, "image_url": "https://pbs.twimg.com/profile_images/3017730711/0a7caf481d223a244c43c8a1d9f2b04d_normal.jpeg", "screen_name": "Bharathmotha", "name": "bharath motha"},
{"id": 40, "image_url": "https://pbs.twimg.com/profile_images/2818970364/bfed1152c1611fd70a647ae314dda6e7_normal.jpeg", "screen_name": "sunny24051018", "name": "sunny"},
{"id": 41, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "Rajitha1829", "name": "Rajitha"},
{"id": 42, "image_url": "https://pbs.twimg.com/profile_images/2648759119/84c20aa2aa6323786cfb8ad7e53134ce_normal.jpeg", "screen_name": "bhanupradeep1", "name": "bhanu pradeep"},
{"id": 43, "image_url": "https://pbs.twimg.com/profile_images/2260531874/Vetrimaaran-Siddharth_normal.jpg", "screen_name": "amrutpatil3210", "name": "@mrut P@til"},
{"id": 44, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png", "screen_name": "AkkineniAkshay", "name": "Akkineni Akshay"},
{"id": 45, "image_url": "https://pbs.twimg.com/profile_images/702385100558897156/hT1Ry8mw_normal.jpg", "screen_name": "vaisham92", "name": "Vaishampayan Reddy"},
{"id": 46, "image_url": "https://pbs.twimg.com/profile_images/877387796/Appu_jm_normal.JPG", "screen_name": "apoorvadasari16", "name": "Apoorva Dasari"},
{"id": 47, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_0_normal.png", "screen_name": "freinds4u2002", "name": "paladhi pramodh"},
{"id": 48, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "screen_name": "aruna_teluguone", "name": "aruna"},
{"id": 49, "image_url": "https://pbs.twimg.com/profile_images/567043481311256577/Di4NYmjG_normal.png", "screen_name": "telugufirst", "name": "telugupopular"},
{"id": 50, "image_url": "https://pbs.twimg.com/profile_images/1102796321/PhotoFunia-a2682e_normal.jpg", "screen_name": "satvikgadam", "name": "satvikgadam"},
{"id": 51, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_4_normal.png", "screen_name": "destroyinangel", "name": "sudha"},
{"id": 52, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png", "screen_name": "babisandeep", "name": "Sandeep"},
{"id": 53, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", "screen_name": "RamyaMattey", "name": "Ramya Mattey"},
{"id": 54, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_4_normal.png", "screen_name": "vineeth_sps", "name": "vineeth"},
{"id": 55, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_6_normal.png", "screen_name": "IA5194", "name": "Isaac Samuel"},
{"id": 56, "image_url": "https://pbs.twimg.com/profile_images/552928112426491904/Y74yoiU9_normal.jpeg", "screen_name": "oncemanivamsi", "name": "Manivamsi Sunkula"},
{"id": 57, "image_url": "https://abs.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "screen_name": "santoshlagisety", "name": "santosh"},
{"id": 58, "image_url": "https://pbs.twimg.com/profile_images/224835851/girl-w-pink-hair-ties-1_normal.jpg", "screen_name": "OvalsSusie", "name": "Addie Ayala"},
{"id": 59, "image_url": "https://pbs.twimg.com/profile_images/553265160161218560/T8Z23mXY_normal.jpeg", "screen_name": "maruthip25", "name": "Maruthi Sharma"},
{"id": 60, "image_url": "https://pbs.twimg.com/profile_images/685750015994806272/NQIG1DUP_normal.jpg", "screen_name": "hellboy8tg", "name": "Abhijeet Sai Dasari"},
{"id": 61, "image_url": "https://pbs.twimg.com/profile_images/1876827960/419881_2745270110659_1224709823_32412429_1535463051_n_normal.jpg", "screen_name": "likhit_kakollu", "name": "likhit"}
],
"links": [
{"source": 1, "target": 0},
{"source": 2, "target": 0},
{"source": 3, "target": 0},
{"source": 4, "target": 0},
{"source": 5, "target": 0},
{"source": 6, "target": 0},
{"source": 7, "target": 0},
{"source": 8, "target": 0},
{"source": 9, "target": 0},
{"source": 10, "target": 0},
{"source": 11, "target": 0},
{"source": 12, "target": 0},
{"source": 13, "target": 0},
{"source": 14, "target": 0},
{"source": 15, "target": 0},
{"source": 16, "target": 0},
{"source": 17, "target": 0},
{"source": 18, "target": 0},
{"source": 19, "target": 0},
{"source": 20, "target": 0},
{"source": 21, "target": 0},
{"source": 22, "target": 0},
{"source": 23, "target": 0},
{"source": 24, "target": 0},
{"source": 25, "target": 0},
{"source": 26, "target": 0},
{"source": 27, "target": 0},
{"source": 28, "target": 0},
{"source": 29, "target": 0},
{"source": 30, "target": 0},
{"source": 31, "target": 0},
{"source": 32, "target": 0},
{"source": 33, "target": 0},
{"source": 34, "target": 0},
{"source": 35, "target": 0},
{"source": 36, "target": 0},
{"source": 37, "target": 0},
{"source": 38, "target": 0},
{"source": 39, "target": 0},
{"source": 40, "target": 0},
{"source": 41, "target": 0},
{"source": 42, "target": 0},
{"source": 43, "target": 0},
{"source": 44, "target": 0},
{"source": 45, "target": 0},
{"source": 46, "target": 0},
{"source": 47, "target": 0},
{"source": 48, "target": 0},
{"source": 49, "target": 0},
{"source": 50, "target": 0},
{"source": 51, "target": 0},
{"source": 52, "target": 0},
{"source": 53, "target": 0},
{"source": 54, "target": 0},
{"source": 55, "target": 0},
{"source": 56, "target": 0},
{"source": 57, "target": 0},
{"source": 58, "target": 0},
{"source": 59, "target": 0},
{"source": 60, "target": 0},
{"source": 61, "target": 0},
{"source": 10, "target": 1},
{"source": 1, "target": 10},
{"source": 8, "target": 2},
{"source": 2, "target": 8},
{"source": 2, "target": 10},
{"source": 6, "target": 3},
{"source": 8, "target": 3},
{"source": 3, "target": 8},
{"source": 9, "target": 3},
{"source": 3, "target": 9},
{"source": 10, "target": 3},
{"source": 3, "target": 10},
{"source": 4, "target": 10},
{"source": 8, "target": 5},
{"source": 5, "target": 8},
{"source": 5, "target": 10},
{"source": 6, "target": 7},
{"source": 8, "target": 6},
{"source": 6, "target": 8},
{"source": 6, "target": 10},
{"source": 7, "target": 9},
{"source": 7, "target": 10},
{"source": 9, "target": 8},
{"source": 8, "target": 9},
{"source": 10, "target": 8},
{"source": 8, "target": 10},
{"source": 10, "target": 9},
{"source": 9, "target": 10},
{"source": 10, "target": 11},
{"source": 10, "target": 29},
{"source": 10, "target": 45},
{"source": 50, "target": 10},
{"source": 51, "target": 10},
{"source": 10, "target": 51},
{"source": 10, "target": 61},
{"source": 11, "target": 35},
{"source": 12, "target": 30},
{"source": 35, "target": 12},
{"source": 12, "target": 35},
{"source": 12, "target": 49},
{"source": 12, "target": 59},
{"source": 59, "target": 13},
{"source": 13, "target": 59},
{"source": 13, "target": 60},
{"source": 29, "target": 15},
{"source": 15, "target": 29},
{"source": 32, "target": 15},
{"source": 15, "target": 32},
{"source": 34, "target": 15},
{"source": 15, "target": 34},
{"source": 15, "target": 44},
{"source": 59, "target": 15},
{"source": 15, "target": 59},
{"source": 15, "target": 60},
{"source": 15, "target": 61},
{"source": 16, "target": 19},
{"source": 19, "target": 17},
{"source": 17, "target": 19},
{"source": 29, "target": 15},
{"source": 15, "target": 29},
{"source": 32, "target": 15},
{"source": 15, "target": 32},
{"source": 34, "target": 15},
{"source": 15, "target": 34},
{"source": 15, "target": 44},
{"source": 59, "target": 15},
{"source": 15, "target": 59},
{"source": 15, "target": 60},
{"source": 15, "target": 61},
{"source": 16, "target": 19},
{"source": 19, "target": 17},
{"source": 17, "target": 19},
{"source": 22, "target": 20},
{"source": 20, "target": 22},
{"source": 31, "target": 21},
{"source": 21, "target": 31},
{"source": 28, "target": 22},
{"source": 22, "target": 28},
{"source": 33, "target": 22},
{"source": 22, "target": 33},
{"source": 39, "target": 22},
{"source": 22, "target": 39},
{"source": 27, "target": 60},
{"source": 28, "target": 37},
{"source": 28, "target": 38},
{"source": 39, "target": 28},
{"source": 28, "target": 39},
{"source": 35, "target": 30},
{"source": 30, "target": 35},
{"source": 31, "target": 45},
{"source": 31, "target": 53},
{"source": 31, "target": 61},
{"source": 32, "target": 54},
{"source": 59, "target": 32},
{"source": 32, "target": 59},
{"source": 32, "target": 60},
{"source": 33, "target": 37},
{"source": 34, "target": 44},
{"source": 59, "target": 34},
{"source": 34, "target": 59},
{"source": 34, "target": 60},
{"source": 34, "target": 61},
{"source": 47, "target": 35},
{"source": 35, "target": 47},
{"source": 47, "target": 39},
{"source": 37, "target": 38},
{"source": 39, "target": 38},
{"source": 38, "target": 39},
{"source": 40, "target": 51},
{"source": 40, "target": 52},
{"source": 36, "target": 39}
]
}
import tweepy
import json
ACCESS_TOKEN = '118623489-QsSuqItzx8cnReRHI67ylffqpOPNs7z4Qp8hcOiI' # Variables that contains the user credentials to access Twitter API
ACCESS_SECRET = 'PAPovgDO6QPy9QV8BbllM8p2MGWrcLLD8pesMHjXxTEMl'
CONSUMER_KEY = 'wxSZ8GSC7aRC7dAsM3m7UqgIg'
CONSUMER_SECRET = 'HuauQk780HuKWyQky9e4J6QM1DlwVxHXuvrLbgHGWhkmRXlvE4'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) #Authentication is handled by the tweepy.AuthHandler class
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
dict1={}
#f2 = open('f2.json','a')
#f3= open ('trues.json','w')
f5=open('follower_links','r+')
def function():
edge_elements ={}
my_foll = open('followers.json','r')
f1 = open('f1.json','w')
count=0
# for user in tweepy.Cursor(api.followers, screen_name="dineshpaladhi").items():
# count=count+1
each_line = json.load(my_foll)
dict={}
for i in range(1,61):
source_name= each_line["nodes"][i]["screen_name"]
#print source_name
for j in range(i,61):
# try:
target_name=each_line["nodes"][j+1]["screen_name"]
dict['source']=source_name
dict['target']=target_name
f1.write(json.dumps(dict)+',\n')
# print source_name+','+target_name
def func():
a=open('f1.json','r')
each_line1 = json.load(a)
for user in each_line1:
source_name=user["source"]
target_name=user["target"]
frndshp = api.show_friendship(source_screen_name=source_name, target_screen_name=target_name,count=180)
# #print type(frndshp)
#if (frndshp[0].following == True):
dict1['source1']=frndshp[0].screen_name
dict1['following']=frndshp[0].following
dict1['target1']=frndshp[1].screen_name
dict1['followed_by']=frndshp[0].followed_by
f2.write(json.dumps(dict1)+',\n')
dict3={}
def get_trues():
f2 = open('f2.json','r')
each_line2 = json.load(f2)
for user in each_line2:
if(user["followed_by"]== True):
dict3['source']=user["target1"]
dict3['target']=user["source1"]
f3.write(json.dumps(dict3)+',\n')
if(user["following"]== True):
dict3['source']=user["source1"]
dict3['target']=user["target1"]
f3.write(json.dumps(dict3)+',\n')
dict5={}
set=()
def getids():
f4 = open('followers.json','r')
each_line4 = json.load(f4)
f3 = open('trues.json','r')
each_line3 = json.load(f3)
for user in each_line3:
src_name=user['source']
tar_name=user['target']
#print src_name+','+tar_name
for i in range(1,61):
source_n= each_line4["nodes"][i]["screen_name"]
# if(src_name==source_n):
# dict5['source']=each_line4["nodes"][i]["id"]
# f5.write(json.dumps(dict5)+',\n')
if(tar_name==source_n):
dict5['target']=each_line4["nodes"][i]["id"]
f5.write(json.dumps(dict5)+',\n')
getids()
#get_trues()
#function()
#func()
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.link {
stroke: #ccc;
}
.node text {
pointer-events: none;
font: 10px sans-serif;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var width =1000,
height = 1000
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.gravity(0.05)
.distance(300)
.charge(-100)
.size([width, height]);
d3.json("followers.json", function(error, json) {
if (error) throw error;
svg.append("defs").selectAll("marker")
.data(["suit", "licensing", "resolved"])
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 25)
.attr("refY", 0)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-5L10,0L0,5 L10,0 L0, -5")
.style("stroke", "#4679BD")
.style("opacity", "0.6");
force
.nodes(json.nodes)
.links(json.links)
.start();
var link = svg.selectAll(".link")
.data(json.links)
.enter().append("line")
.attr("class", "link")
.style("marker-end", "url(#suit)"); // Modified line
var node = svg.selectAll(".node")
.data(json.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
node.append("image")
.attr("xlink:href", function(d) { return d.image_url;})
.attr("x", -8)
.attr("y", -8)
.attr("width", 25)
.attr("height", 25);
node.append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name });
force.on("tick", function() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
});
});
</script>
import tweepy
import json
import time
output_file = open("followers.json", "w")
ACCESS_TOKEN = '118623489-QsSuqItzx8cnReRHI67ylffqpOPNs7z4Qp8hcOiI' # Variables that contains the user credentials to access Twitter API
ACCESS_SECRET = 'PAPovgDO6QPy9QV8BbllM8p2MGWrcLLD8pesMHjXxTEMl'
CONSUMER_KEY = 'wxSZ8GSC7aRC7dAsM3m7UqgIg'
CONSUMER_SECRET = 'HuauQk780HuKWyQky9e4J6QM1DlwVxHXuvrLbgHGWhkmRXlvE4'
count = 0
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) #Authentication is handled by the tweepy.AuthHandler class
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
elements={}
edge_elements ={}
count =0
output_file.write('{\n "nodes": [\n')
#try:
api = tweepy.API(auth) # Construct the API instance
elements['screen_name']="dineshpaladhi"
elements['name']="dinesh"
elements['image_url']="https://github.com/favicon.ico"
elements['id']=0
output_file.write(json.dumps(elements)+',\n')
for user in tweepy.Cursor(api.followers, screen_name="dineshpaladhi").items():
count=count+1
elements['screen_name']=user.screen_name
elements['name']=user.name
elements['id']=count
elements['image_url']=user.profile_image_url_https
output_file.write(json.dumps(elements)+',\n')
output_file.write('],\n')
output_file.write('"links": [\n')
count=0
for user in tweepy.Cursor(api.followers, screen_name="dineshpaladhi").items():
count=count+1
edge_elements['source']= count
edge_elements['target']=0
output_file.write(json.dumps(edge_elements)+',\n')
output_file.write(']\n}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment