|
10 | 10 | "<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>" |
11 | 11 | ] |
12 | 12 | }, |
| 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 | + }, |
13 | 36 | { |
14 | 37 | "cell_type": "code", |
15 | 38 | "execution_count": null, |
|
18 | 41 | }, |
19 | 42 | "outputs": [], |
20 | 43 | "source": [ |
21 | | - "from google.colab import auth\n", |
22 | 44 | "from googleapiclient.discovery import build\n", |
23 | 45 | "\n", |
| 46 | + "sheets_service = build('sheets', 'v4', cache_discovery=False, credentials=credentials)\n", |
| 47 | + "\n", |
24 | 48 | "def update_chart_size(spreadsheet_id, is_dry_run=False, target_width=600, target_height=371):\n", |
25 | 49 | " response = sheets_service.spreadsheets().get(spreadsheetId=spreadsheet_id, includeGridData=False).execute()\n", |
26 | 50 | " sheets = response.get('sheets', [])\n", |
|
54 | 78 | " print(f\"\"\"sheet: {sheet['properties']['title']},\n", |
55 | 79 | "chart: {chart['spec']['title']},\n", |
56 | 80 | "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 | + " \"\"\")" |
62 | 82 | ] |
63 | 83 | }, |
64 | 84 | { |
65 | 85 | "cell_type": "code", |
66 | | - "execution_count": null, |
| 86 | + "execution_count": 4, |
67 | 87 | "metadata": { |
68 | 88 | "id": "vp1izUBSLxp9" |
69 | 89 | }, |
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 | + ], |
71 | 134 | "source": [ |
72 | 135 | "# Replace this with the ID of your Google Sheets file\n", |
73 | | - "SPREADSHEET_ID = '18r8cT6x9lPdM-rXvXjsqx84W7ZDdTDYGD59xr0UGOwg'\n", |
| 136 | + "SPREADSHEET_ID = '1Svyw40Th7VbigX6lpR1lb1WXwTUVKZWrK7O2YELrml4'\n", |
74 | 137 | "\n", |
75 | 138 | "# 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)" |
77 | 140 | ] |
78 | 141 | } |
79 | 142 | ], |
|
85 | 148 | "provenance": [] |
86 | 149 | }, |
87 | 150 | "kernelspec": { |
88 | | - "display_name": "Python 3", |
| 151 | + "display_name": ".venv", |
| 152 | + "language": "python", |
89 | 153 | "name": "python3" |
90 | 154 | }, |
91 | 155 | "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" |
93 | 166 | } |
94 | 167 | }, |
95 | 168 | "nbformat": 4, |
|
0 commit comments