Update, after so many years

This commit is contained in:
Benson Chu 2024-03-19 08:29:02 -05:00
parent b0e0a7e78d
commit 461e9e7b7b
9 changed files with 22 additions and 9 deletions

View file

@ -1,2 +0,0 @@
export DISPLAY=:1
python3 pyclock.py -b -f file.json -et 5 -e

4
scripts/runfromcron Normal file
View file

@ -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

4
scripts/runfromcrontime Normal file
View file

@ -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

View file

@ -21,6 +21,7 @@ def send_email(login_file):
data = json.loads(json_data) data = json.loads(json_data)
fromaddr = toaddr = data["email_address"] fromaddr = toaddr = data["email_address"]
password = data["password"] password = data["password"]
smtpserver = data["smtpserver"]
msg = MIMEMultipart() msg = MIMEMultipart()
@ -45,7 +46,7 @@ def send_email(login_file):
image = MIMEImage(picture.read(), name=os.path.basename(picture_name)) image = MIMEImage(picture.read(), name=os.path.basename(picture_name))
msg.attach(image) msg.attach(image)
server = smtplib.SMTP('smtp.gmail.com', 587) server = smtplib.SMTP(smtpserver, 587)
server.starttls() server.starttls()
server.login(fromaddr, password) server.login(fromaddr, password)
text = msg.as_string() text = msg.as_string()
@ -53,3 +54,9 @@ def send_email(login_file):
server.quit() server.quit()
os.remove(picture_name) 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)

View file

@ -65,8 +65,8 @@ def clock(action, username, password, email_status):
time.sleep(3) time.sleep(3)
if email_status: if email_status is not None:
send_email("./email.json") send_email(email_status)
time.sleep(3) time.sleep(3)
driver.quit() driver.quit()
@ -87,8 +87,8 @@ def clockAt(action, username, password, end_time, quiet, email_status):
time.sleep(3) time.sleep(3)
if email_status: if email_status is not None:
send_email("./email.json") send_email(email_status)
time.sleep(3) time.sleep(3)
driver.quit() 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("-m", "--minutes", action="store_true", help="Use minutes instead of hours")
parser.add_argument("-q", "--quiet", action="store_true") 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() (args, extra) = parser.parse_known_args()
@ -136,7 +136,7 @@ def main():
password = args.password password = args.password
if args.clock is not None: if args.clock is not None:
clock(args.clock, username, password) clock(args.clock, username, password, args.email)
elif args.navigate: elif args.navigate:
login(webdriver.Firefox(), username, password) login(webdriver.Firefox(), username, password)
else: else: