From d44fd0b9abafd5972ae5c084d67a5256f80d6612 Mon Sep 17 00:00:00 2001
From: Rami Janini <>
Date: Fri, 1 Oct 2021 07:46:19 +0300
Subject: [PATCH 1/2] Added a motivational quote notifier.
---
motivational_quotes_automation/README.md | 6 ++
motivational_quotes_automation/motivate.py | 82 +++++++++++++++++++
.../requirements.txt | 2 +
3 files changed, 90 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..3a635d6e2
--- /dev/null
+++ b/motivational_quotes_automation/motivate.py
@@ -0,0 +1,82 @@
+import os
+import sys
+import json
+import time
+import requests
+from pprint import pprint
+import winrt.windows.data.xml.dom as dom
+import winrt.windows.ui.notifications as notifications
+
+
+repeat_time = 2 #in hours
+
+
+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']
+ app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe'
+
+ nManager = notifications.ToastNotificationManager
+ notifier = nManager.create_toast_notifier(app)
+ tString = f"""
+
+
+
+ Motivational Quote
+ By {author},
+ {quote}
+
+
+
+
+
+
+
+ """
+
+ xDoc = dom.XmlDocument()
+ xDoc.load_xml(tString)
+
+ notifier.show(notifications.ToastNotification(xDoc))
+
+
+def main_app():
+ while True:
+ check_availability()
+ data = get_quote()
+ create_notifier(data)
+ print('Sent notification.')
+ time.sleep(repeat_time * 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..f7b37d2af
--- /dev/null
+++ b/motivational_quotes_automation/requirements.txt
@@ -0,0 +1,2 @@
+winrt==1.0.21033.1
+requests==2.25.1
From 3e2fa376bf8e750a185bd3f464c24f5cbcedfc55 Mon Sep 17 00:00:00 2001
From: Rami
Date: Fri, 1 Oct 2021 07:54:58 +0300
Subject: [PATCH 2/2] Update motivate.py
---
motivational_quotes_automation/motivate.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/motivational_quotes_automation/motivate.py b/motivational_quotes_automation/motivate.py
index 3a635d6e2..0441f143b 100644
--- a/motivational_quotes_automation/motivate.py
+++ b/motivational_quotes_automation/motivate.py
@@ -8,9 +8,6 @@
import winrt.windows.ui.notifications as notifications
-repeat_time = 2 #in hours
-
-
def check_availability():
# check if the running device is windows
if os.name == 'nt':
@@ -39,7 +36,9 @@ def get_quote():
def create_notifier(data):
quote = data[0]['q']
author = data[0]['a']
- app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe'
+ app = '''
+ {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe
+ '''
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(app)
@@ -75,7 +74,7 @@ def main_app():
data = get_quote()
create_notifier(data)
print('Sent notification.')
- time.sleep(repeat_time * 3600)
+ time.sleep(2 * 3600)
if __name__ == '__main__':