Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Set deps to fixed version, run config.py correctly, combine file and …
Browse files Browse the repository at this point in the history
…folder correctly, raise WrongPasswordError
  • Loading branch information
michadenheijer committed Oct 14, 2019
1 parent ace94b7 commit 42101ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
webuntis
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
webuntis==0.1.11
google-api-python-client==1.6.3
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.0
PyInquirer==1.0.3
31 changes: 18 additions & 13 deletions schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@
from os import path

import sys
import threading
import datetime
import json
import subprocess
import webuntis

import config

CURRENT = os.path.dirname(sys.argv[0])
TODAY = datetime.date.today()
END = TODAY + datetime.timedelta(days=14)
SCHEDULE = os.path.join(CURRENT, "config.json")
WRONG_PASS = os.path.join(CURRENT, "wrong_pass")

class WrongPasswordError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)

if not path.exists(CURRENT + 'config.json'):
CONFIG = ['python3', 'config.py']
subprocess.Popen(CONFIG).wait()
if not path.exists(SCHEDULE):
config.config()

from google_cal import add_event, delete_events

with open(CURRENT + "config.json") as FILE:
with open(SCHEDULE) as FILE:
DATA = json.load(FILE)
global USERNAME, PASSWORD, SERVER, SCHOOL, STUDENTID
USERNAME = DATA["username"]
Expand All @@ -31,9 +39,8 @@
STUDENTID = DATA["webuntis_id"]

try:
if path.exists(CURRENT + "wrong_pass"):
print("Last time wrong password, not trying again")
exit()
if path.exists(WRONG_PASS):
raise WrongPasswordError("Before you've entered a wrong password, run config.py to fix the error.")
with webuntis.Session(
username=USERNAME,
password=PASSWORD,
Expand All @@ -49,10 +56,8 @@
lesson.rooms = str(lesson.rooms).replace("]", "")
lesson.subjects = str(lesson.subjects).replace("[", "")
lesson.subjects = str(lesson.subjects).replace("]", "")
thread = threading.Thread(target=add_event, \
args=(lesson.start, lesson.end, lesson.subjects, lesson.rooms,))
thread.start()
add_event(lesson.start, lesson.end, lesson.subjects, lesson.rooms)
except webuntis.errors.BadCredentialsError:
print("Wrong password")
FILE = open(CURRENT + "wrong_pass", "w+")
FILE = open(WRONG_PASS, "w+")
FILE.close()
raise WrongPasswordError("The password you entered appears to be wrong.")

0 comments on commit 42101ac

Please sign in to comment.