-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_lens.py
477 lines (429 loc) · 12.1 KB
/
streamlit_lens.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
import json
import requests as re
import streamlit as st
import streamlit.components.v1 as components
url = "https://api.lens.dev/"
headers = {"content-type": "application/json"}
# json flatten helper function
def flatten_json(y):
out = {}
def flatten(x, name=""):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + "_")
elif type(x) is list:
i = 0
for a in x:
flatten(a, name + str(i) + "_")
i += 1
else:
out[name[:-1]] = x
flatten(y)
return out
# Header
def header():
st.set_page_config(page_title="Lens Data", page_icon="🌱")
st.markdown("# Lens Data")
# Sidebar defined here
def sideBar():
with st.sidebar:
st.markdown("### Socials")
st.markdown("* [ngmisl.lens](https://lenster.xyz/u/ngmisl.lens)")
st.markdown("* [ngmisl.twitter](https://twitter.com/ngmisl)")
st.markdown("* [ngmisl.github](https://github.com/ngmisl/)")
# Total Protocol stats
def totalProtocol():
query = """ query globalProtocolStats { globalProtocolStats {
totalProfiles
totalPosts
totalComments
totalCollects
totalMirrors }
} """
r = re.post(url, json={"query": query}, headers=headers)
json_data = json.loads(r.text)
flat = flatten_json(json_data)
# Layout Start columns
# Layout references: https://docs.streamlit.io/library/api-reference/layout
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
col1.write("Total Profiles")
col1.write(flat["data_globalProtocolStats_totalProfiles"])
with col2:
col2.write("Total Posts")
col2.write(flat["data_globalProtocolStats_totalPosts"])
with col3:
col3.write("Total Comments")
col3.write(flat["data_globalProtocolStats_totalComments"])
with col4:
col4.write("Total Collects")
col4.write(flat["data_globalProtocolStats_totalCollects"])
with col5:
col5.write("Total Mirrors")
col5.write(flat["data_globalProtocolStats_totalMirrors"])
def topStats():
# Top Followers
query_followers = """ query ExploreProfiles {
exploreProfiles(request: { sortCriteria: MOST_FOLLOWERS }) {
items {
id
name
bio
isDefault
attributes {
displayType
traitType
key
value
}
followNftAddress
metadata
handle
picture {
... on NftImage {
contractAddress
tokenId
uri
chainId
verified
}
... on MediaSet {
original {
url
mimeType
}
}
}
coverPicture {
... on NftImage {
contractAddress
tokenId
uri
chainId
verified
}
... on MediaSet {
original {
url
mimeType
}
}
}
ownedBy
dispatcher {
address
canUseRelay
}
stats {
totalFollowers
totalFollowing
totalPosts
totalComments
totalMirrors
totalPublications
totalCollects
}
followModule {
... on FeeFollowModuleSettings {
type
contractAddress
amount {
asset {
name
symbol
decimals
address
}
value
}
recipient
}
... on ProfileFollowModuleSettings {
type
}
... on RevertFollowModuleSettings {
type
}
}
}
pageInfo {
prev
next
totalCount
}
}
} """
r_followers = re.post(url, json={"query": query_followers}, headers=headers)
json_data_followers = json.loads(r_followers.text)
flat_followers = flatten_json(json_data_followers)
# Top Posts
query_posts = """ query ExploreProfiles {
exploreProfiles(request: { sortCriteria: MOST_POSTS}) {
items {
id
name
bio
isDefault
attributes {
displayType
traitType
key
value
}
followNftAddress
metadata
handle
picture {
... on NftImage {
contractAddress
tokenId
uri
chainId
verified
}
... on MediaSet {
original {
url
mimeType
}
}
}
coverPicture {
... on NftImage {
contractAddress
tokenId
uri
chainId
verified
}
... on MediaSet {
original {
url
mimeType
}
}
}
ownedBy
dispatcher {
address
canUseRelay
}
stats {
totalFollowers
totalFollowing
totalPosts
totalComments
totalMirrors
totalPublications
totalCollects
}
followModule {
... on FeeFollowModuleSettings {
type
contractAddress
amount {
asset {
name
symbol
decimals
address
}
value
}
recipient
}
... on ProfileFollowModuleSettings {
type
}
... on RevertFollowModuleSettings {
type
}
}
}
pageInfo {
prev
next
totalCount
}
}
} """
r_posts = re.post(url, json={"query": query_posts}, headers=headers)
json_data_posts = json.loads(r_posts.text)
flat_posts = flatten_json(json_data_posts)
# Most Comments
query_comments = """ query ExploreProfiles {
exploreProfiles(request: { sortCriteria: MOST_COMMENTS}) {
items {
id
name
bio
isDefault
attributes {
displayType
traitType
key
value
}
followNftAddress
metadata
handle
picture {
... on NftImage {
contractAddress
tokenId
uri
chainId
verified
}
... on MediaSet {
original {
url
mimeType
}
}
}
coverPicture {
... on NftImage {
contractAddress
tokenId
uri
chainId
verified
}
... on MediaSet {
original {
url
mimeType
}
}
}
ownedBy
dispatcher {
address
canUseRelay
}
stats {
totalFollowers
totalFollowing
totalPosts
totalComments
totalMirrors
totalPublications
totalCollects
}
followModule {
... on FeeFollowModuleSettings {
type
contractAddress
amount {
asset {
name
symbol
decimals
address
}
value
}
recipient
}
... on ProfileFollowModuleSettings {
type
}
... on RevertFollowModuleSettings {
type
}
}
}
pageInfo {
prev
next
totalCount
}
}
} """
r_comments = re.post(url, json={"query": query_comments}, headers=headers)
json_data_comments = json.loads(r_comments.text)
flat_comments = flatten_json(json_data_comments)
# helper:
# st.write(flat_comments)
# Layout Start columns
# Layout references: https://docs.streamlit.io/library/api-reference/layout
st.markdown("---")
# UI
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
col1.write("Top Followed")
col1.write(
f'1. [{flat_followers["data_exploreProfiles_items_0_handle"]}](https://lenster.xyz/u/{flat_followers["data_exploreProfiles_items_0_handle"]}) {flat_followers["data_exploreProfiles_items_0_stats_totalFollowers"]}'
)
col1.write(
f'2. [{flat_followers["data_exploreProfiles_items_1_handle"]}](https://lenster.xyz/u/{flat_followers["data_exploreProfiles_items_1_handle"]}) {flat_followers["data_exploreProfiles_items_1_stats_totalFollowers"]}'
)
col1.write(
f'3. [{flat_followers["data_exploreProfiles_items_2_handle"]}](https://lenster.xyz/u/{flat_followers["data_exploreProfiles_items_2_handle"]}) {flat_followers["data_exploreProfiles_items_2_stats_totalFollowers"]}'
)
col1.write(
f'4. [{flat_followers["data_exploreProfiles_items_3_handle"]}](https://lenster.xyz/u/{flat_followers["data_exploreProfiles_items_3_handle"]}) {flat_followers["data_exploreProfiles_items_3_stats_totalFollowers"]}'
)
col1.write(
f'5. [{flat_followers["data_exploreProfiles_items_4_handle"]}](https://lenster.xyz/u/{flat_followers["data_exploreProfiles_items_4_handle"]}) {flat_followers["data_exploreProfiles_items_4_stats_totalFollowers"]}'
)
with col3:
col3.write("Top Posts")
col3.write(
f'1. [{flat_posts["data_exploreProfiles_items_0_handle"]}](https://lenster.xyz/u/{flat_posts["data_exploreProfiles_items_0_handle"]}) {flat_posts["data_exploreProfiles_items_0_stats_totalPosts"]}'
)
col3.write(
f'2. [{flat_posts["data_exploreProfiles_items_1_handle"]}](https://lenster.xyz/u/{flat_posts["data_exploreProfiles_items_1_handle"]}) {flat_posts["data_exploreProfiles_items_1_stats_totalPosts"]}'
)
col3.write(
f'3. [{flat_posts["data_exploreProfiles_items_2_handle"]}](https://lenster.xyz/u/{flat_posts["data_exploreProfiles_items_2_handle"]}) {flat_posts["data_exploreProfiles_items_2_stats_totalPosts"]}'
)
col3.write(
f'4. [{flat_posts["data_exploreProfiles_items_3_handle"]}](https://lenster.xyz/u/{flat_posts["data_exploreProfiles_items_3_handle"]}) {flat_posts["data_exploreProfiles_items_3_stats_totalPosts"]}'
)
col3.write(
f'5. [{flat_posts["data_exploreProfiles_items_4_handle"]}](https://lenster.xyz/u/{flat_posts["data_exploreProfiles_items_4_handle"]}) {flat_posts["data_exploreProfiles_items_4_stats_totalPosts"]}'
)
with col5:
col5.write("Top Comments")
col5.write(
f'1. [{flat_comments["data_exploreProfiles_items_0_handle"]}](https://lenster.xyz/u/{flat_comments["data_exploreProfiles_items_0_handle"]}) {flat_comments["data_exploreProfiles_items_0_stats_totalComments"]}'
)
col5.write(
f'2. [{flat_comments["data_exploreProfiles_items_1_handle"]}](https://lenster.xyz/u/{flat_comments["data_exploreProfiles_items_1_handle"]}) {flat_comments["data_exploreProfiles_items_1_stats_totalComments"]}'
)
col5.write(
f'3. [{flat_comments["data_exploreProfiles_items_2_handle"]}](https://lenster.xyz/u/{flat_comments["data_exploreProfiles_items_2_handle"]}) {flat_comments["data_exploreProfiles_items_2_stats_totalComments"]}'
)
col5.write(
f'4. [{flat_comments["data_exploreProfiles_items_3_handle"]}](https://lenster.xyz/u/{flat_comments["data_exploreProfiles_items_3_handle"]}) {flat_comments["data_exploreProfiles_items_3_stats_totalComments"]}'
)
col5.write(
f'5. [{flat_comments["data_exploreProfiles_items_4_handle"]}](https://lenster.xyz/u/{flat_comments["data_exploreProfiles_items_4_handle"]}) {flat_comments["data_exploreProfiles_items_4_stats_totalComments"]}'
)
def dune():
st.markdown("---")
st.markdown("## Some Cool Dune Stats")
# TODO: find a way to set style="background: #FFFFFF;"
components.iframe(
"https://dune.com/embeds/891346/1557954/d23c8e22-1616-4370-8b9b-cc0e847de099"
)
components.iframe(
"https://dune.com/embeds/891428/1558143/6ccff924-0622-4f8d-a5ae-78b42e9399fa"
)
components.iframe(
"https://dune.com/embeds/891273/1557779/ddf3a367-ecf9-4177-9d00-a6b7fe22c8f4"
)
components.iframe(
"https://dune.com/embeds/891266/1557768/eba8c66e-e293-4d1b-bf9b-6eb44602e92d"
)
# App Layout
def main():
header()
sideBar()
totalProtocol()
topStats()
dune()
if __name__ == "__main__":
main()