Last active
February 24, 2022 20:53
-
-
Save mkeneqa/d4975f1c6434f7b6129e0032ab4c0303 to your computer and use it in GitHub Desktop.
sample python script to upload website files to dropbbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
# !IMPORTANT: Make sure this is installed already: https://github.com/andreafabrizi/Dropbox-Uploader | |
import subprocess | |
import time | |
from datetime import datetime as dt | |
import os | |
if __name__ == "__main__": | |
_start_time = float(time.perf_counter()) | |
now = dt.now() | |
dt_string = now.strftime("%H%M%S_%m_%d_%Y") | |
home_dir = "/home/cabox/workspace" | |
arch_file_name = "WesternReload_wpcontent_" + dt_string + ".zip" | |
wp_cli_cmd = subprocess.run(["wp", "db", "export"]) | |
print("wp db export: %d" % wp_cli_cmd.returncode) | |
# # zip up the wp-content dir | |
zip_cmd = subprocess.run(["zip", "-r", arch_file_name, "wp-content/"]) | |
print("zip wpcontent dir: %d" % zip_cmd.returncode) | |
# # add the exported sql file to the zip archive | |
zip_cmd = subprocess.run(["zip", "-g", arch_file_name, "*.sql"]) | |
print("add sql file: %d" % zip_cmd.returncode) | |
# # add wp-config file to the zip archive | |
zip_cmd = subprocess.run(["zip", "-g", arch_file_name, "wp-config.php"]) | |
print("add config file: %d" % zip_cmd.returncode) | |
# # bash dropbox_uploader.sh upload ../WesternReload_wpcontent_bkup_114810_10_29_2021.zip WRC | |
upload_cmd_cmd = subprocess.run(["bash", "dropboxup/dropbox_uploader.sh", "upload", arch_file_name, arch_file_name]) | |
print("uploading file: %d" % upload_cmd_cmd.returncode) | |
# remove the sql and archive files | |
print("Cleanup ... ") | |
files_in_directory = os.listdir(home_dir) | |
filtered_files = [file for file in files_in_directory if file.endswith(".zip") or file.endswith(".sql")] | |
for file in filtered_files: | |
path_to_file = os.path.join(home_dir, file) | |
print("\t deleting ", path_to_file) | |
os.remove(path_to_file) | |
_end_time = float(time.perf_counter()) | |
_total_time = round(_end_time - _start_time, 2) | |
print("Finished in " + str(_total_time) + " second(s)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment