{"id":22,"date":"2023-01-20T06:13:00","date_gmt":"2023-01-20T06:13:00","guid":{"rendered":"https:\/\/editor.mediahack.co.za\/databites\/?p=22"},"modified":"2025-11-17T17:42:19","modified_gmt":"2025-11-17T17:42:19","slug":"automating-data-downloads-from-a-google-spreadsheet","status":"publish","type":"post","link":"https:\/\/outliereditor.co.za\/index.php\/2023\/01\/20\/automating-data-downloads-from-a-google-spreadsheet\/","title":{"rendered":"Automating data downloads from a Google spreadsheet"},"content":{"rendered":"\n<p>Downloading data from a Google Spreadsheet is usually as easy as clicking File-&gt;Download-&gt;CSV<\/p>\n\n\n\n<p>But sometimes you need to automate the download.<\/p>\n\n\n\n<p>If you have editing access to the file, you can do this by publishing a CSV version of the file (File\u2192Share\u2192Publish to the web)<\/p>\n\n\n\n<p>If you don\u2019t have editing access, you can still access the data on public documents by using a URL like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;docs.google.com\/spreadsheets\/d\/KEY\/export?format=csv<\/code><\/pre>\n\n\n\n<p>The&nbsp;<strong>KEY&nbsp;<\/strong>in the URL above would be a long alphanumeric string that looks something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1ZpX_twP8sFBOAU6t--Vvh1pWMYSvs60UXINuD5n-K08<\/code><\/pre>\n\n\n\n<p>Replace the word &#8216;KEY&#8217; with the matching alphanumeric key string that you find in the URL for a spreadsheet.<\/p>\n\n\n\n<p>For example, this is the URL for a public spreadsheet with loadshedding data for South Africa. The KEY is the portion in bold:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:\/\/docs.google.com\/spreadsheets\/d\/<strong>1ZpX_twP8sFBOAU6t--Vvh1pWMYSvs60UXINuD5n-K08<\/strong>\/edit#gid=863218371<\/code><\/pre>\n\n\n\n<p>To construct the CSV URL, remove everything after the forward-slash that follows the KEY and replace it with&nbsp;<strong>export?format=csv<\/strong><\/p>\n\n\n\n<p>The new URL will look like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;docs.google.com\/spreadsheets\/d\/1ZpX_twP8sFBOAU6t--Vvh1pWMYSvs60UXINuD5n-K08\/export?format=csv<\/code><\/pre>\n\n\n\n<p>If you open this URL you will have a CSV-format file downloaded to your computer.<\/p>\n\n\n\n<p>Note: The spreadsheet URL used in the example above is for the <a href=\"https:\/\/esp.info\/\">Eskom Se Push loadshedding dataset<\/a>. (Loadshedding is the South African term for rolling blackouts, which have been in effect since 2014.) We use this technique to download a daily copy of the data into DataDesk, which we then publish as in both CSV and JSON format. The end result is the loadshedding calendar we&nbsp;publish on&nbsp;The Outlier.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update: The Outlier&#8217;s latest version of the <a href=\"https:\/\/loadshed.theoutlier.co.za\/\">loadshedding calendar can be found here<\/a><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"702\" src=\"https:\/\/outliereditor.co.za\/wp-content\/uploads\/2023\/01\/Screenshot-2024-12-17-at-21.19.41-1024x702.png\" alt=\"\" class=\"wp-image-89998\" srcset=\"https:\/\/outliereditor.co.za\/wp-content\/uploads\/2023\/01\/Screenshot-2024-12-17-at-21.19.41-1024x702.png 1024w, https:\/\/outliereditor.co.za\/wp-content\/uploads\/2023\/01\/Screenshot-2024-12-17-at-21.19.41-300x206.png 300w, https:\/\/outliereditor.co.za\/wp-content\/uploads\/2023\/01\/Screenshot-2024-12-17-at-21.19.41-768x526.png 768w, https:\/\/outliereditor.co.za\/wp-content\/uploads\/2023\/01\/Screenshot-2024-12-17-at-21.19.41.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Downloading data from a Google Sheets is usually as easy as clicking file->Download->CSV. But sometimes you need to automate the download. Here&#8217;s how.<\/p>\n","protected":false},"author":1,"featured_media":86688,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[447,448,1387],"tags":[453,454,449,455,1317],"newsletter-post":[],"site":[],"class_list":["post-22","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databites","category-how-to","category-the-outlier","tag-csv","tag-google-sheets","tag-how-to","tag-json","tag-workflow"],"acf":{"big_number":"","big_number_caption":"","big_number_link":"","big_number_background":"","big_number_text_colour":"#000000","big_number_icon":false,"big_number_wide":"yes","featured_chart":false,"flourish_chart_id":"","flourish_sub_title":"","flourish_chart_width":"medium","is_newsletter_post":"No","post_style":"bc","show_on_front":"Yes","link_through":"Yes","chart_url":"","background_colour":"#0089AA","text_colour":"#FFFFFF"},"_links":{"self":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":4,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":90003,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/posts\/22\/revisions\/90003"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/media\/86688"}],"wp:attachment":[{"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=22"},{"taxonomy":"newsletter-post","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/newsletter-post?post=22"},{"taxonomy":"site","embeddable":true,"href":"https:\/\/outliereditor.co.za\/index.php\/wp-json\/wp\/v2\/site?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}