53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
# Sermon Upload v1.2 Alpha
|
|
|
|
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
|
|
|
|
def upload(sermonsrc, sermondst, key): # Input has to end in /
|
|
|
|
time.sleep(10) # Wait 10 seconds.
|
|
os.chdir(sermonsrc) # 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 = sermonsrc + mostrecent # Grab the most recent sermon to copy.
|
|
sermondst = sermondst + mostrecent # Destination for most recent sermon.
|
|
|
|
copyfile(sermonsrc, sermondst) # Copy the sermon
|
|
|
|
os.chdir(sermondst) # Go to the directory where the sermon has been copied to
|
|
call(sermondst=sermondst)
|
|
call("export sermondst")
|
|
print(call("echo sermondst"))
|
|
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("findsermon='ls $sermondst'")
|
|
call("export findsermon")
|
|
call('sermons=$("ssh -i $key sermons@bereanbibleutah.org $findsermon")')
|
|
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()
|
|
|
|
upload("/mnt/52265C99265C8041/Users/Berean-Sound/sermons", "/home/josh/sermons/2018", "/home/berean/sermons/.tempssh/temp")
|