Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit b5235b6

Browse files
authored
Merge pull request #179 from Rogue-Halo/master
Random Quote Desktop Notification
2 parents 86a236c + 09645e8 commit b5235b6

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Random Quote Notification
2+
A simple program presenting the use of an API, the plyer notification module and Scheduling tasks in Python.
3+
4+
### Prerequisites
5+
- These are located in requirements.txt
6+
- You can run `pip install -r requirements.txt` to install these
7+
8+
### How to run the script
9+
- Just run `main.py`
10+
11+
### Result
12+
![Expected Output](result.png)
13+
14+
## *Author Name*
15+
[Rogue Halo](https://github.com/rogue-halo)
422 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Random Quote Desktop Notification
2+
# Author: Rogue Halo
3+
# Date: 1st October 2020
4+
#---------------------------------
5+
# Imports
6+
import requests
7+
from plyer import notification
8+
from apscheduler.schedulers.blocking import BlockingScheduler
9+
10+
# Sub-Routines
11+
def fetch(): # This gets the quote from the API and turns it into the quote to be displayed
12+
quoteSite = requests.get("http://api.quotable.io/random")
13+
quoteJson = quoteSite.json()
14+
quote = quoteJson["content"] + "\n- " + quoteJson["author"]
15+
if len(quote) > 256:
16+
fetch()
17+
else:
18+
return quote
19+
20+
def display(quote): # Uses the plyer module to display the quote
21+
notification.notify(title="Random Quote",message=quote,app_name="Random Quote",app_icon="icon.ico", timeout=10,toast=False)
22+
23+
# Main Program
24+
def task(): # This puts it all together
25+
quote = fetch()
26+
display(quote)
27+
28+
if __name__ == "__main__":
29+
task() # So that it prints a quote without waiting for the interval
30+
scheduler = BlockingScheduler() # Creates a scheduler
31+
scheduler.add_job(task, 'interval', hours=1) # Sets the interval, you may change this to your preferences
32+
scheduler.start() # Starts scheduler
102 Bytes
Binary file not shown.
166 KB
Loading

0 commit comments

Comments
 (0)