Repository navigation
Expand file tree
/
Copy pathget_featured_authors.py
More file actions
76 lines (59 loc) · 2.68 KB
/
Copy pathget_featured_authors.py
File metadata and controls
76 lines (59 loc) · 2.68 KB
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
import json
import urllib3
import pandas as pd
import math
http = urllib3.PoolManager()
fa_call = 'https://public.tableau.com/public/apis/bff/discover/v3/authors/tableau-visionaries?startIndex=0&limit=12'
fa_json = json.loads(http.request('GET',fa_call).data)
featured_authors = pd.json_normalize(fa_json['contents'], max_level=0)
n_featured_authors = len(featured_authors)
author_loops = range(n_featured_authors)
# initialise dataframes
profile_df =[]
websites_df =[]
workbook_df =[]
for i in range(n_featured_authors):
your_username = featured_authors['profileName'][i]
print("Working on " + featured_authors['profileName'][i] +"'s profile")
profile_call = "https://public.tableau.com/profile/api/" + your_username
tableau_profile = json.loads(http.request('GET',profile_call).data)
profile = pd.json_normalize(tableau_profile, max_level=0)
profile['author_description'] = featured_authors['bio'][i]
del profile['websites']
if 'address' in profile.columns:
del profile['address']
profile_df.append(profile)
websites = pd.json_normalize(tableau_profile['websites'], max_level=0)
websites['profileName'] = your_username
websites_df.append(websites)
n_workbooks = profile['visibleWorkbookCount']
workbook_loops = math.ceil(n_workbooks / 50)
for j in range(workbook_loops):
print('Getting workbooks page: ' + str(j))
start = j * 50
workbook_call = 'https://public.tableau.com/public/apis/workbooks?profileName=' + your_username + '&start='+str(start)+'&count=50&visibility=NON_HIDDEN'
tableau_workbooks = json.loads(http.request('GET',workbook_call).data)
workbooks = pd.json_normalize(tableau_workbooks['contents'], max_level=0)
workbooks['profileName'] = your_username
workbook_df.append(workbooks)
# Combine data frames from loop
profile_df = pd.concat(profile_df)
workbook_df = pd.concat(workbook_df)
websites_df = pd.concat(websites_df)
# Get VOTD data
votd_df =[]
start = 0
while start != -1:
print('Getting VOTDs from index: ' + str(start))
votd = json.loads(http.request('GET',"https://public.tableau.com/public/apis/bff/discover/v2/vizzes/viz-of-the-day?startIndex=" + str(start) + "&limit=12").data)
votd_df.append(pd.json_normalize(votd['contents'], max_level=1))
start = votd['next']
# Combine data frames from loop
votd_df = pd.concat(votd_df)
votd_df['VOTD_flag'] = 'VOTD'
votd_lookup = votd_df[['workbookRepoUrl','VOTD_flag']]
workbook_df = pd.merge(workbook_df,votd_lookup,how='left',on='workbookRepoUrl')
# Save locally
profile_df.to_csv('fa_profiles.csv', index=False)
workbook_df.to_csv('fa_workbooks.csv', index=False)
websites_df.to_csv('fa_websites.csv', index=False)