From 03bd589c8d99c9abc5f95d735be44a431de8a10f Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Mon, 23 May 2022 11:34:17 +0000 Subject: [PATCH] - cron script: update local databases and csv files --- data/update_database_files_cron.py | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 data/update_database_files_cron.py diff --git a/data/update_database_files_cron.py b/data/update_database_files_cron.py new file mode 100644 index 0000000..9d1f09c --- /dev/null +++ b/data/update_database_files_cron.py @@ -0,0 +1,48 @@ +''' +download daily database files +Python version: 3.10 +''' +import os +import requests +# import uuid +# import json +# from dotenv import load_dotenv, find_dotenv + + +def main(): + """ + Main function. + """ + ######### download firebird db #################################################### + + # efine the remote file to retrieve + firebird_url = 'https://rhea.geologie.ac.at/index.php/s/Uqkvso33Vp7nUTn/download' + # Define the local filename to save data + local_firebird_file = '/home/administrator/databases/67.Fdb' + # Make http request for remote file data + data = requests.get(firebird_url) + # Save file data to local copy + with open(local_firebird_file, 'wb')as file: + file.write(data.content) + os.chmod(local_firebird_file, 0o777) + print(f"firebird db file {local_firebird_file} has been succesfully updated!") + + ######### downlod Voegelsber data.txt #################################################### + voegelsberg_data_url = 'https://rhea.geologie.ac.at/index.php/s/esMBbekhrjIebkH/download' + # Define the local filename to save data + local_voegelsberg_file = '/home/administrator/databases/data.txt' + # Make http request for remote file data + data = requests.get(voegelsberg_data_url) + # Save file data to local copy + with open(local_voegelsberg_file, 'wb')as file: + file.write(data.content) + print(f"voegelsberg data file {local_voegelsberg_file} has been succesfully updated!") + + # add cron job: + # sudo crontab -e + # add the following line: + # 0 * * * * /etc/geomon/.venv/bin/python /etc/geomon/data/update_database_files_cron.py + + +if __name__ == "__main__": + main()