diff --git a/runfromcron b/runfromcron deleted file mode 100755 index 094f1ff..0000000 --- a/runfromcron +++ /dev/null @@ -1,2 +0,0 @@ -export DISPLAY=:1 -python3 pyclock.py -b -f file.json -et 5 -e diff --git a/redundancy/LaunchInterrupt b/scripts/redundancy/LaunchInterrupt similarity index 100% rename from redundancy/LaunchInterrupt rename to scripts/redundancy/LaunchInterrupt diff --git a/redundancy/ProcessExists b/scripts/redundancy/ProcessExists similarity index 100% rename from redundancy/ProcessExists rename to scripts/redundancy/ProcessExists diff --git a/redundancy/restart.py b/scripts/redundancy/restart.py similarity index 100% rename from redundancy/restart.py rename to scripts/redundancy/restart.py diff --git a/scripts/runfromcron b/scripts/runfromcron new file mode 100644 index 0000000..efda721 --- /dev/null +++ b/scripts/runfromcron @@ -0,0 +1,4 @@ +export DISPLAY=:1 +export PATH=$PATH:/usr/local/bin +cd /home/bchu/pyclock +python3 src/pyclock.py -b -f config/file.json -e config/email.json -et 5 diff --git a/scripts/runfromcrontime b/scripts/runfromcrontime new file mode 100644 index 0000000..003018b --- /dev/null +++ b/scripts/runfromcrontime @@ -0,0 +1,4 @@ +export DISPLAY=:1 +export PATH=$PATH:/usr/local/bin +cd /home/bchu/pyclock +python3 src/pyclock.py -b -f config/file.json -e config/email.json -t $1 diff --git a/mail.py b/src/mail.py similarity index 83% rename from mail.py rename to src/mail.py index dd281e4..c0c0e27 100755 --- a/mail.py +++ b/src/mail.py @@ -21,6 +21,7 @@ def send_email(login_file): data = json.loads(json_data) fromaddr = toaddr = data["email_address"] password = data["password"] + smtpserver = data["smtpserver"] msg = MIMEMultipart() @@ -45,7 +46,7 @@ def send_email(login_file): image = MIMEImage(picture.read(), name=os.path.basename(picture_name)) msg.attach(image) - server = smtplib.SMTP('smtp.gmail.com', 587) + server = smtplib.SMTP(smtpserver, 587) server.starttls() server.login(fromaddr, password) text = msg.as_string() @@ -53,3 +54,9 @@ def send_email(login_file): server.quit() os.remove(picture_name) + +if __name__ == "__main__": + script_path = os.path.realpath(__file__) + directory = os.path.dirname(script_path) + config_path = os.path.join(directory,"../config/email.json") + send_email(config_path) diff --git a/pyclock.py b/src/pyclock.py similarity index 94% rename from pyclock.py rename to src/pyclock.py index 6f9a4b7..ba4b44c 100644 --- a/pyclock.py +++ b/src/pyclock.py @@ -65,8 +65,8 @@ def clock(action, username, password, email_status): time.sleep(3) - if email_status: - send_email("./email.json") + if email_status is not None: + send_email(email_status) time.sleep(3) driver.quit() @@ -87,8 +87,8 @@ def clockAt(action, username, password, end_time, quiet, email_status): time.sleep(3) - if email_status: - send_email("./email.json") + if email_status is not None: + send_email(email_status) time.sleep(3) driver.quit() @@ -119,7 +119,7 @@ def main(): parser.add_argument("-m", "--minutes", action="store_true", help="Use minutes instead of hours") parser.add_argument("-q", "--quiet", action="store_true") - parser.add_argument("-e", "--email", action="store_true", help="Specify if you want to send an email with a screenshot") + parser.add_argument("-e", "--email", help="Specify email config file") (args, extra) = parser.parse_known_args() @@ -136,7 +136,7 @@ def main(): password = args.password if args.clock is not None: - clock(args.clock, username, password) + clock(args.clock, username, password, args.email) elif args.navigate: login(webdriver.Firefox(), username, password) else: diff --git a/selen_help.py b/src/selen_help.py similarity index 100% rename from selen_help.py rename to src/selen_help.py