Skip to content

Commit 73efcee

Browse files
committed
update chart formatting script
1 parent 05c2be5 commit 73efcee

2 files changed

Lines changed: 88 additions & 12 deletions

File tree

src/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ sqlfluff==3.5.0
1010
pandas==2.3.3
1111
google-cloud-bigquery==3.40.0
1212
requests==2.32.5
13+
14+
# src/tools/scripts/*
15+
google-api-python-client==2.188.0

src/tools/scripts/chart-adjustments.ipynb

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@
1010
"<a href=\"https://colab.research.google.com/github/HTTPArchive/almanac.httparchive.org/blob/main/src/tools/scripts/chart-adjustments.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
1111
]
1212
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"# Authenticate the user\n",
20+
"import sys\n",
21+
"\n",
22+
"if 'google.colab' in sys.modules:\n",
23+
" from google.colab import auth\n",
24+
"\n",
25+
" auth.authenticate_user()\n",
26+
" credentials = auth.get_user_credentials()\n",
27+
"else:\n",
28+
" import google.auth\n",
29+
"\n",
30+
" SCOPES = [\n",
31+
" 'https://www.googleapis.com/auth/spreadsheets'\n",
32+
" ]\n",
33+
" credentials, project = google.auth.default(scopes=SCOPES)"
34+
]
35+
},
1336
{
1437
"cell_type": "code",
1538
"execution_count": null,
@@ -18,9 +41,10 @@
1841
},
1942
"outputs": [],
2043
"source": [
21-
"from google.colab import auth\n",
2244
"from googleapiclient.discovery import build\n",
2345
"\n",
46+
"sheets_service = build('sheets', 'v4', cache_discovery=False, credentials=credentials)\n",
47+
"\n",
2448
"def update_chart_size(spreadsheet_id, is_dry_run=False, target_width=600, target_height=371):\n",
2549
" response = sheets_service.spreadsheets().get(spreadsheetId=spreadsheet_id, includeGridData=False).execute()\n",
2650
" sheets = response.get('sheets', [])\n",
@@ -54,26 +78,65 @@
5478
" print(f\"\"\"sheet: {sheet['properties']['title']},\n",
5579
"chart: {chart['spec']['title']},\n",
5680
"dimensions: {chart['position']['overlayPosition']['widthPixels']} x {chart['position']['overlayPosition'].get('heightPixels', 'N/A')}\n",
57-
" \"\"\")\n",
58-
"\n",
59-
"# Authenticate the user\n",
60-
"auth.authenticate_user()\n",
61-
"sheets_service = build('sheets', 'v4', cache_discovery=False)"
81+
" \"\"\")"
6282
]
6383
},
6484
{
6585
"cell_type": "code",
66-
"execution_count": null,
86+
"execution_count": 4,
6787
"metadata": {
6888
"id": "vp1izUBSLxp9"
6989
},
70-
"outputs": [],
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"sheet: Cookies Third Party Top,\n",
96+
"chart: Most common third-party cookies,\n",
97+
"dimensions: 700 x 371\n",
98+
" \n",
99+
"sheet: Cookie Domains Third Party Top,\n",
100+
"chart: Most common third-party cookie domains,\n",
101+
"dimensions: 538 x 371\n",
102+
" \n",
103+
"sheet: Client Hints Top,\n",
104+
"chart: Top client hints,\n",
105+
"dimensions: 581 x 371\n",
106+
" \n",
107+
"sheet: Referrer Policy Top,\n",
108+
"chart: Most common referrer policies,\n",
109+
"dimensions: 581 x 371\n",
110+
" \n",
111+
"sheet: Referrer Policy Usage,\n",
112+
"chart: Referrer policy usage,\n",
113+
"dimensions: 581 x 371\n",
114+
" \n",
115+
"sheet: Iab Tcf V2 Countries Top,\n",
116+
"chart: IAB TCF v2, top publisher countries,\n",
117+
"dimensions: 581 x 376\n",
118+
" \n",
119+
"sheet: Dnt Usage,\n",
120+
"chart: DoNotTrack usage,\n",
121+
"dimensions: 581 x 376\n",
122+
" \n",
123+
"sheet: Iab Usp Strings Top,\n",
124+
"chart: Most common IAB USP string values,\n",
125+
"dimensions: 581 x 459\n",
126+
" \n",
127+
"sheet: Related Origin Trials Top,\n",
128+
"chart: Most common privacy related Origin Trials,\n",
129+
"dimensions: 581 x 459\n",
130+
" \n"
131+
]
132+
}
133+
],
71134
"source": [
72135
"# Replace this with the ID of your Google Sheets file\n",
73-
"SPREADSHEET_ID = '18r8cT6x9lPdM-rXvXjsqx84W7ZDdTDYGD59xr0UGOwg'\n",
136+
"SPREADSHEET_ID = '1Svyw40Th7VbigX6lpR1lb1WXwTUVKZWrK7O2YELrml4'\n",
74137
"\n",
75138
"# Call the function to update the chart width\n",
76-
"update_chart_size(SPREADSHEET_ID, target_height=None, is_dry_run=True)"
139+
"update_chart_size(SPREADSHEET_ID, target_height=None, is_dry_run=False)"
77140
]
78141
}
79142
],
@@ -85,11 +148,21 @@
85148
"provenance": []
86149
},
87150
"kernelspec": {
88-
"display_name": "Python 3",
151+
"display_name": ".venv",
152+
"language": "python",
89153
"name": "python3"
90154
},
91155
"language_info": {
92-
"name": "python"
156+
"codemirror_mode": {
157+
"name": "ipython",
158+
"version": 3
159+
},
160+
"file_extension": ".py",
161+
"mimetype": "text/x-python",
162+
"name": "python",
163+
"nbconvert_exporter": "python",
164+
"pygments_lexer": "ipython3",
165+
"version": "3.14.2"
93166
}
94167
},
95168
"nbformat": 4,

0 commit comments

Comments
 (0)