2018-10-06 17:48:39 +00:00
|
|
|
# Sermon Upload v1.1 Alpha
|
2018-10-06 17:38:44 +00:00
|
|
|
|
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
|
|
|
|
|
2018-10-06 17:38:44 +00:00
|
|
|
time.sleep(10) # Wait 10 seconds.
|
2018-10-06 17:48:39 +00:00
|
|
|
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
|
2018-10-06 17:38:44 +00:00
|
|
|
)
|
2018-10-06 17:48:39 +00:00
|
|
|
n.show()
|