From 8bab73f984a00746a69aceb25a30fcb6eca4684e Mon Sep 17 00:00:00 2001 From: Rami Janini <> Date: Fri, 1 Oct 2021 08:42:35 +0300 Subject: [PATCH 1/3] Added a motivational quote notifier. --- motivational_quotes_automation/README.md | 6 +++ motivational_quotes_automation/motivate.py | 52 +++++++++++++++++++ .../requirements.txt | 2 + 3 files changed, 60 insertions(+) create mode 100644 motivational_quotes_automation/README.md create mode 100644 motivational_quotes_automation/motivate.py create mode 100644 motivational_quotes_automation/requirements.txt diff --git a/motivational_quotes_automation/README.md b/motivational_quotes_automation/README.md new file mode 100644 index 000000000..8909d52d7 --- /dev/null +++ b/motivational_quotes_automation/README.md @@ -0,0 +1,6 @@ +#Motivational Quotes +A simple script that will automatically send a windows notification containing a motivational quote to keep you motivated during your work or study sessions. + +#How to use +`pip install requirements.txt` +`python motivate.py` diff --git a/motivational_quotes_automation/motivate.py b/motivational_quotes_automation/motivate.py new file mode 100644 index 000000000..7702974eb --- /dev/null +++ b/motivational_quotes_automation/motivate.py @@ -0,0 +1,52 @@ +import os +import sys +import json +import time +import requests +from win10toast import ToastNotifier + + +def check_availability(): + # check if the running device is windows + if os.name == 'nt': + pass + else: + print('This script only runs on windows.') + sys.exit(0) + + +def get_quote(): + # access api to get a quote + url = 'https://zenquotes.io/api/random' + req = requests.request('GET', url) + + if req.status_code != 200: + print('Connot reach api.') + sys.exit(0) + else: + pass + + data = json.loads(req.content) + # pprint(data) + return data + + +def create_notifier(data): + quote = data[0]['q'] + author = data[0]['a'] + toast = ToastNotifier() + toast.show_toast(f"By {author}", quote) + + +def main_app(): + while True: + + check_availability() + data = get_quote() + create_notifier(data) + print('Sent notification.') + time.sleep(2 * 3600) + + +if __name__ == '__main__': + main_app() diff --git a/motivational_quotes_automation/requirements.txt b/motivational_quotes_automation/requirements.txt new file mode 100644 index 000000000..c8605081c --- /dev/null +++ b/motivational_quotes_automation/requirements.txt @@ -0,0 +1,2 @@ +win10toast +requests==2.25.1 From ee66a0ecb8ce1de3254ac6a3411ad2744dd6fd6f Mon Sep 17 00:00:00 2001 From: Rami Janini <> Date: Fri, 1 Oct 2021 09:05:53 +0300 Subject: [PATCH 2/3] Added a way to take user input for number of hours. --- motivational_quotes_automation/motivate.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/motivational_quotes_automation/motivate.py b/motivational_quotes_automation/motivate.py index 7702974eb..dacea7a41 100644 --- a/motivational_quotes_automation/motivate.py +++ b/motivational_quotes_automation/motivate.py @@ -39,13 +39,18 @@ def create_notifier(data): def main_app(): + try: + time_ = int(input('Repeat notification after (hours): ')) + except: + print('''There was an error in the user input, + make sure that ur input is only numbers''') + sys.exit(0) while True: - check_availability() data = get_quote() create_notifier(data) print('Sent notification.') - time.sleep(2 * 3600) + time.sleep(time_ * 3600) if __name__ == '__main__': From 8502dbb64653a37647880132c99e49168896d16f Mon Sep 17 00:00:00 2001 From: Rami Janini <> Date: Fri, 1 Oct 2021 09:07:43 +0300 Subject: [PATCH 3/3] Edited PEP8 error. --- motivational_quotes_automation/motivate.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/motivational_quotes_automation/motivate.py b/motivational_quotes_automation/motivate.py index dacea7a41..864567c51 100644 --- a/motivational_quotes_automation/motivate.py +++ b/motivational_quotes_automation/motivate.py @@ -39,12 +39,7 @@ def create_notifier(data): def main_app(): - try: - time_ = int(input('Repeat notification after (hours): ')) - except: - print('''There was an error in the user input, - make sure that ur input is only numbers''') - sys.exit(0) + time_ = int(input('Repeat notification after (hours): ')) while True: check_availability() data = get_quote()