Crontabed PyDrive uploader
I am preparing small data science-y project, where I will be collecting a bunch of logs on a network connected Raspberry Pi. I want to upload the logs to an online cloud storage automatically. As I have a lot of storage on my Google Drive and it has a great API with a nice python wrapper for, so I decided to use it. The setup is quite simple and I decided to write it up for my future reference and the intertubes.
Enable the drive API with your google account. Only follow the Step 1 and download the client secret file and name it client_secrets.json.
To install PyDrive run:
I used python 2.
Copy the following code into uploader.py and store it in the same location as the client_secrets.json.
Pick a folder in Google Drive and store its id under the PARENT_ID variable in uploader.py. The id is the string in the URL of your folder, e.g.: https://drive.google.com/drive/folders/LONG_FOLDER_ID_STRING.
Run
and follow the initial authentication instructions. Trough the prompt you will be given an URL, similar to this one. Replace the {ID_STRING} with the one you were given and open the link in a browser. You will be asked to confirm an authorisation request and receive an authorisation code. Enter the code into the prompt, your uploader is now authenticated. Delete client_secrets.json.
You can now upload files to the selected Google Drive folder by running:
To create a crontab script, run:
and add the fillowing line to it:
In my case I am uploading a log of transponder signals of nearby planes. I am using Flightradar24 packaged dump1090 to decode and record transponder signals.
We now have an automated uploader to the cloud. Log uploading is only one of the many options available. Motion detection triggered videos, regular file backups and more could be uploaded like this.