python-hard-way/Sermon-Upload/sermon-upload.py

45 lines
1.9 KiB
Python
Raw Normal View History

# Sermon Upload v1.1 Alpha
2018-09-30 01:06:38 +00:00
from subprocess import call # We can do BASH in Python if needed.
import os # Lots of system stuff
from shutil import copyfile # Allow copying of files
import glob # Import glob tools for file listings.
import notify2 # Notification utility.
import time # Import time into the galaxy
time.sleep(10) # Wait 10 seconds.
os.chdir("/mnt/52265C99265C8041/Users/Berean-Sound/sermons") # Go to sermon directory.
list = sorted(glob.glob('*.mp3')) # Sort files alphabetically.
mostrecent = list[-1] # Find most recent sermon
secondrecent = list[-2] # Find second most recent sermon
sermonsrc = "/mnt/52265C99265C8041/Users/Berean-Sound/sermons/" + mostrecent # Grab the most recent sermon to copy.
sermondst = "/home/berean/sermons/2018/" + mostrecent # Destination for most recent sermon.
copyfile(sermonsrc, sermondst) # Copy the sermon
os.chdir("/home/berean/sermons/2018/") # Go to the directory where the sermon has been copied to
os.system("rsync --update --progress -e 'ssh -i /home/berean/sermons/.tempssh/temp' *.mp3 sermons@bereanbibleutah.org:/home/josh/sermons/2018/") # Upload the sermon.
call(sermons=$("ssh -i /home/berean/sermons/.tempssh/temp sermons@bereanbibleutah.org 'ls /home/josh/sermons/2018'") # Grab a list of uploaded sermons.
call("export sermons") # Export the list to Python
recentsermon = os.environ["sermons"] # Set it to a variable
recentsermon = recentsermon[-1] # Try to grab most recent sermon.
print(recentsermon) # Print most recent sermon.
if mostrecent == recentsermon: # If the most recent sermon uploaded matches the most recent sermon locally, we're good.
notify2.init('Sermon Script')
n = notify2.Notification("Sermon Uploaded",
mostrecent
)
n.show()
else: # Otherwise, something went wrong.
notify2.init('Sermon Script')
n = notify2.Notification("Sermon Upload Failed",
mostrecent
)
n.show()