Ivan Kudryakov commited on
Commit
803e597
·
1 Parent(s): e14ccff
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -7,9 +7,8 @@ import matplotlib.pyplot as plt
7
 
8
  access_token = '24001214633baa923e4caf1fba8da62847aa8df94b3b041d40b54186eabd6a16a81962c9bbbd02f52082a'
9
 
10
-
11
- #x = st.slider('Select a value')
12
- #st.write(x, 'squared is', x * x)
13
 
14
 
15
  api_version = '5.131'
@@ -18,7 +17,13 @@ read_id = st.text_input("Type interested vk id or write \"0\" to use default: ")
18
  if read_id != '0':
19
  my_id = read_id
20
  st.write("my_id changed", my_id)
21
- friend_num = int(st.text_input("Type how many friends you want to show or write \"0\" show all: "))
 
 
 
 
 
 
22
  st.write("wait about a minute we could do only 3 request per second")
23
 
24
  params_for_users_get = {'user_ids': my_id,
@@ -26,7 +31,7 @@ params_for_users_get = {'user_ids': my_id,
26
  'v': api_version}
27
 
28
  myFirstAndLastName = requests.get('https://api.vk.com/method/users.get', params=params_for_users_get)
29
- #print(myFirstAndLastName.text)
30
 
31
  params_for_friends_get = {'user_id': my_id,
32
  'order': 'hints',
@@ -40,9 +45,9 @@ if 'error' in r.json() and r.json()['error']['error_code'] == 30:
40
  exit()
41
  print(r.text)
42
  AllMyFriends = r.json()['response']['items']
43
- #print(AllMyFriends[0]['id'])
44
- #print(AllMyFriends[0]['is_closed'])
45
- #print(AllMyFriends)
46
  AllMyFriendsWithoutClosed = [i for i in AllMyFriends if 'is_closed' in i and i['is_closed'] == False]
47
  if friend_num == 0:
48
  friend_num = len(AllMyFriendsWithoutClosed)
@@ -71,13 +76,13 @@ def GetFriendListById(friend_id):
71
  return [], False
72
 
73
 
74
- MyFriends = AllMyFriendsWithoutClosed[:friend_num-1]
75
- #MyFriends.append(myFirstAndLastName.json()['response'][0])
76
  MyFriendsSet = set([i['id'] for i in MyFriends])
77
  MyFriendsDict = dict([(i['id'], i) for i in MyFriends])
78
  MyFriendsDict[int(my_id)] = myFirstAndLastName.json()['response'][0]
79
- #print(MyFriends)
80
- #print(G.nodes())
81
  for friend_id in MyFriends:
82
  friendFriendList, Flag = GetFriendListById(friend_id['id'])
83
  if not Flag:
@@ -88,17 +93,16 @@ for friend_id in MyFriends:
88
  G.add_edge(friend_id['id'], friendFriend_id)
89
 
90
  G_nodes_list = list(G.nodes)
91
- #print(G_nodes_list)
92
 
93
  pos = nx.spring_layout(G)
94
- #print(pos)
95
 
96
  nx.draw_networkx_nodes(G, pos, node_size=50)
97
  nx.draw_networkx_edges(G, pos, edge_color='b')
98
  # plt.show()
99
 
100
- #st.pyplot(plt)
101
-
102
 
103
 
104
  edge_x = []
@@ -151,12 +155,13 @@ node_trace = go.Scatter(
151
 
152
  node_adjacencies = []
153
  node_text = []
154
- #print(MyFriendsDict)
155
  # print(G_nodes_list[1])
156
  # print(MyFriendsDict[G_nodes_list[1]]['first_name'])
157
  for node, adjacencies in enumerate(G.adjacency()):
158
  node_adjacencies.append(len(adjacencies[1]))
159
- node_text.append(MyFriendsDict[G_nodes_list[node]]['first_name'] + ' ' + MyFriendsDict[G_nodes_list[node]]['last_name'] + ' ' + str(len(adjacencies[1])) + ' edges')
 
160
  # print(node)
161
 
162
  node_trace.marker.color = node_adjacencies
@@ -164,7 +169,8 @@ node_trace.text = node_text
164
 
165
  fig = go.Figure(data=[edge_trace, node_trace],
166
  layout=go.Layout(
167
- title='<br>Social graph to ' + myFirstAndLastName.json()['response'][0]['first_name'] + ' ' + myFirstAndLastName.json()['response'][0]['last_name'],
 
168
  titlefont_size=16,
169
  showlegend=False,
170
  hovermode='closest',
 
7
 
8
  access_token = '24001214633baa923e4caf1fba8da62847aa8df94b3b041d40b54186eabd6a16a81962c9bbbd02f52082a'
9
 
10
+ # x = st.slider('Select a value')
11
+ # st.write(x, 'squared is', x * x)
 
12
 
13
 
14
  api_version = '5.131'
 
17
  if read_id != '0':
18
  my_id = read_id
19
  st.write("my_id changed", my_id)
20
+ friend_num_text = st.text_input("Type how many friends you want to show or write \"0\" show all: ")
21
+ friend_num = 0
22
+ try:
23
+ friend_num_c = int(friend_num_text)
24
+ except:
25
+ friend_num_c = 15
26
+
27
  st.write("wait about a minute we could do only 3 request per second")
28
 
29
  params_for_users_get = {'user_ids': my_id,
 
31
  'v': api_version}
32
 
33
  myFirstAndLastName = requests.get('https://api.vk.com/method/users.get', params=params_for_users_get)
34
+ # print(myFirstAndLastName.text)
35
 
36
  params_for_friends_get = {'user_id': my_id,
37
  'order': 'hints',
 
45
  exit()
46
  print(r.text)
47
  AllMyFriends = r.json()['response']['items']
48
+ # print(AllMyFriends[0]['id'])
49
+ # print(AllMyFriends[0]['is_closed'])
50
+ # print(AllMyFriends)
51
  AllMyFriendsWithoutClosed = [i for i in AllMyFriends if 'is_closed' in i and i['is_closed'] == False]
52
  if friend_num == 0:
53
  friend_num = len(AllMyFriendsWithoutClosed)
 
76
  return [], False
77
 
78
 
79
+ MyFriends = AllMyFriendsWithoutClosed[:friend_num - 1]
80
+ # MyFriends.append(myFirstAndLastName.json()['response'][0])
81
  MyFriendsSet = set([i['id'] for i in MyFriends])
82
  MyFriendsDict = dict([(i['id'], i) for i in MyFriends])
83
  MyFriendsDict[int(my_id)] = myFirstAndLastName.json()['response'][0]
84
+ # print(MyFriends)
85
+ # print(G.nodes())
86
  for friend_id in MyFriends:
87
  friendFriendList, Flag = GetFriendListById(friend_id['id'])
88
  if not Flag:
 
93
  G.add_edge(friend_id['id'], friendFriend_id)
94
 
95
  G_nodes_list = list(G.nodes)
96
+ # print(G_nodes_list)
97
 
98
  pos = nx.spring_layout(G)
99
+ # print(pos)
100
 
101
  nx.draw_networkx_nodes(G, pos, node_size=50)
102
  nx.draw_networkx_edges(G, pos, edge_color='b')
103
  # plt.show()
104
 
105
+ # st.pyplot(plt)
 
106
 
107
 
108
  edge_x = []
 
155
 
156
  node_adjacencies = []
157
  node_text = []
158
+ # print(MyFriendsDict)
159
  # print(G_nodes_list[1])
160
  # print(MyFriendsDict[G_nodes_list[1]]['first_name'])
161
  for node, adjacencies in enumerate(G.adjacency()):
162
  node_adjacencies.append(len(adjacencies[1]))
163
+ node_text.append(MyFriendsDict[G_nodes_list[node]]['first_name'] + ' ' + MyFriendsDict[G_nodes_list[node]][
164
+ 'last_name'] + ' ' + str(len(adjacencies[1])) + ' edges')
165
  # print(node)
166
 
167
  node_trace.marker.color = node_adjacencies
 
169
 
170
  fig = go.Figure(data=[edge_trace, node_trace],
171
  layout=go.Layout(
172
+ title='<br>Social graph to ' + myFirstAndLastName.json()['response'][0]['first_name'] + ' ' +
173
+ myFirstAndLastName.json()['response'][0]['last_name'],
174
  titlefont_size=16,
175
  showlegend=False,
176
  hovermode='closest',