Lovely broken more portable code. More PHW exercises.
This commit is contained in:
parent
091bd47256
commit
c75ec75627
|
@ -1,4 +1,4 @@
|
|||
# Sermon Upload v1.1 Alpha
|
||||
# Sermon Upload v1.2 Alpha
|
||||
|
||||
from subprocess import call # We can do BASH in Python if needed.
|
||||
import os # Lots of system stuff
|
||||
|
@ -7,21 +7,27 @@ 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("/mnt/52265C99265C8041/Users/Berean-Sound/sermons") # Go to sermon directory.
|
||||
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 = "/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.
|
||||
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("/home/berean/sermons/2018/") # Go to the directory where the sermon has been copied to
|
||||
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(sermons=$("ssh -i /home/berean/sermons/.tempssh/temp sermons@bereanbibleutah.org 'ls /home/josh/sermons/2018'") # Grab a list of uploaded sermons.
|
||||
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.
|
||||
|
@ -42,3 +48,5 @@ else: # Otherwise, something went wrong.
|
|||
mostrecent
|
||||
)
|
||||
n.show()
|
||||
|
||||
upload("/mnt/52265C99265C8041/Users/Berean-Sound/sermons", "/home/josh/sermons/2018", "/home/berean/sermons/.tempssh/temp")
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
from sys import argv
|
||||
from os.path import exists
|
||||
|
||||
script, from_file, to_file = argv
|
||||
|
||||
print(f"Copying from {from_file} to {to_file}")
|
||||
|
||||
# we could do these two on one line, how?
|
||||
in_file = open(from_file)
|
||||
indata = in_file.read()
|
||||
|
||||
#print(f"The input file is {len(indata)} bytes long")
|
||||
|
||||
#print(f"Does the output file exist? {exists(to_file)}")
|
||||
#print("Ready, hit RETURN to continue, CRTL-C to abort.")
|
||||
#input()
|
||||
|
||||
out_file = open(to_file, 'w')
|
||||
out_file.write(indata)
|
||||
|
||||
print("Alright, all done.")
|
||||
|
||||
out_file.close() # Close file to save resources.
|
||||
in_file.close()
|
||||
|
||||
# 1, 3, 4, 5 Done.
|
||||
# 2. nah
|
|
@ -0,0 +1,22 @@
|
|||
# this one is like your scripts with argv
|
||||
def print_two(*args):
|
||||
arg1, arg2 = args
|
||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||
|
||||
# ok, that *args is actually pointless, we can just do this
|
||||
def print_two_again(arg1, arg2):
|
||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||
|
||||
# this just takes one argument
|
||||
def print_one(arg1):
|
||||
print(f"arg1: {arg1}")
|
||||
|
||||
# this one takes no arguments
|
||||
|
||||
def print_none():
|
||||
print("I got nothin'.")
|
||||
|
||||
print_two("Zed", "Shaw")
|
||||
print_two_again("Zed", "Shaw")
|
||||
print_one("First!")
|
||||
print_none()
|
|
@ -4,3 +4,5 @@
|
|||
pip install notify2
|
||||
sudo apt-get install libgtk2.0-dev libdbus-1-dev
|
||||
pip install dbus-python
|
||||
|
||||
#Put pip in $PATH by editing .bashrc and adding $PATH=PATH:/opt/python3.6/bin/
|
||||
|
|
Loading…
Reference in New Issue