Ivan Kudryakov commited on
Commit ·
803e597
1
Parent(s): e14ccff
commit 1
Browse files6 unmodified lines7891011121314152 unmodified lines181920212223241 unmodified line262728293031327 unmodified lines40414243444546474822 unmodified lines717273747576777879808182834 unmodified lines88899091929394959697989910010110210310446 unmodified lines1511521531541551561571581591601611621 unmodified line1641651661671681691706 unmodified linesaccess_token = '24001214633baa923e4caf1fba8da62847aa8df94b3b041d40b54186eabd6a16a81962c9bbbd02f52082a'#x = st.slider('Select a value')#st.write(x, 'squared is', x * x)api_version = '5.131'2 unmodified linesif read_id != '0':my_id = read_idst.write("my_id changed", my_id)friend_num = int(st.text_input("Type how many friends you want to show or write \"0\" show all: "))st.write("wait about a minute we could do only 3 request per second")params_for_users_get = {'user_ids': my_id,1 unmodified line'v': api_version}myFirstAndLastName = requests.get('https://api.vk.com/method/users.get', params=params_for_users_get)#print(myFirstAndLastName.text)params_for_friends_get = {'user_id': my_id,'order': 'hints',7 unmodified linesexit()print(r.text)AllMyFriends = r.json()['response']['items']#print(AllMyFriends[0]['id'])#print(AllMyFriends[0]['is_closed'])#print(AllMyFriends)AllMyFriendsWithoutClosed = [i for i in AllMyFriends if 'is_closed' in i and i['is_closed'] == False]if friend_num == 0:friend_num = len(AllMyFriendsWithoutClosed)22 unmodified linesreturn [], FalseMyFriends = AllMyFriendsWithoutClosed[:friend_num-1]#MyFriends.append(myFirstAndLastName.json()['response'][0])MyFriendsSet = set([i['id'] for i in MyFriends])MyFriendsDict = dict([(i['id'], i) for i in MyFriends])MyFriendsDict[int(my_id)] = myFirstAndLastName.json()['response'][0]#print(MyFriends)#print(G.nodes())for friend_id in MyFriends:friendFriendList, Flag = GetFriendListById(friend_id['id'])if not Flag:4 unmodified linesG.add_edge(friend_id['id'], friendFriend_id)G_nodes_list = list(G.nodes)#print(G_nodes_list)pos = nx.spring_layout(G)#print(pos)nx.draw_networkx_nodes(G, pos, node_size=50)nx.draw_networkx_edges(G, pos, edge_color='b')# plt.show()#st.pyplot(plt)edge_x = []46 unmodified linesnode_adjacencies = []node_text = []#print(MyFriendsDict)# print(G_nodes_list[1])# print(MyFriendsDict[G_nodes_list[1]]['first_name'])for node, adjacencies in enumerate(G.adjacency()):node_adjacencies.append(len(adjacencies[1]))node_text.append(MyFriendsDict[G_nodes_list[node]]['first_name'] + ' ' + MyFriendsDict[G_nodes_list[node]]['last_name'] + ' ' + str(len(adjacencies[1])) + ' edges')# print(node)node_trace.marker.color = node_adjacencies1 unmodified linefig = go.Figure(data=[edge_trace, node_trace],layout=go.Layout(title='<br>Social graph to ' + myFirstAndLastName.json()['response'][0]['first_name'] + ' ' + myFirstAndLastName.json()['response'][0]['last_name'],titlefont_size=16,showlegend=False,hovermode='closest',6 unmodified lines78910111213142 unmodified lines171819202122232425262728291 unmodified line313233343536377 unmodified lines45464748495051525322 unmodified lines767778798081828384858687884 unmodified lines9394959697989910010110210310410510610710846 unmodified lines1551561571581591601611621631641651661671 unmodified line1691701711721731741751766 unmodified linesaccess_token = '24001214633baa923e4caf1fba8da62847aa8df94b3b041d40b54186eabd6a16a81962c9bbbd02f52082a'# x = st.slider('Select a value')# st.write(x, 'squared is', x * x)api_version = '5.131'2 unmodified linesif read_id != '0':my_id = read_idst.write("my_id changed", my_id)friend_num_text = st.text_input("Type how many friends you want to show or write \"0\" show all: ")friend_num = 0try:friend_num_c = int(friend_num_text)except:friend_num_c = 15st.write("wait about a minute we could do only 3 request per second")params_for_users_get = {'user_ids': my_id,1 unmodified line'v': api_version}myFirstAndLastName = requests.get('https://api.vk.com/method/users.get', params=params_for_users_get)# print(myFirstAndLastName.text)params_for_friends_get = {'user_id': my_id,'order': 'hints',7 unmodified linesexit()print(r.text)AllMyFriends = r.json()['response']['items']# print(AllMyFriends[0]['id'])# print(AllMyFriends[0]['is_closed'])# print(AllMyFriends)AllMyFriendsWithoutClosed = [i for i in AllMyFriends if 'is_closed' in i and i['is_closed'] == False]if friend_num == 0:friend_num = len(AllMyFriendsWithoutClosed)22 unmodified linesreturn [], FalseMyFriends = AllMyFriendsWithoutClosed[:friend_num - 1]# MyFriends.append(myFirstAndLastName.json()['response'][0])MyFriendsSet = set([i['id'] for i in MyFriends])MyFriendsDict = dict([(i['id'], i) for i in MyFriends])MyFriendsDict[int(my_id)] = myFirstAndLastName.json()['response'][0]# print(MyFriends)# print(G.nodes())for friend_id in MyFriends:friendFriendList, Flag = GetFriendListById(friend_id['id'])if not Flag:4 unmodified linesG.add_edge(friend_id['id'], friendFriend_id)G_nodes_list = list(G.nodes)# print(G_nodes_list)pos = nx.spring_layout(G)# print(pos)nx.draw_networkx_nodes(G, pos, node_size=50)nx.draw_networkx_edges(G, pos, edge_color='b')# plt.show()# st.pyplot(plt)edge_x = []46 unmodified linesnode_adjacencies = []node_text = []# print(MyFriendsDict)# print(G_nodes_list[1])# print(MyFriendsDict[G_nodes_list[1]]['first_name'])for node, adjacencies in enumerate(G.adjacency()):node_adjacencies.append(len(adjacencies[1]))node_text.append(MyFriendsDict[G_nodes_list[node]]['first_name'] + ' ' + MyFriendsDict[G_nodes_list[node]]['last_name'] + ' ' + str(len(adjacencies[1])) + ' edges')# print(node)node_trace.marker.color = node_adjacencies1 unmodified linefig = go.Figure(data=[edge_trace, node_trace],layout=go.Layout(title='<br>Social graph to ' + myFirstAndLastName.json()['response'][0]['first_name'] + ' ' +myFirstAndLastName.json()['response'][0]['last_name'],titlefont_size=16,showlegend=False,hovermode='closest',
app.py+25-19