Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Scripts/API/Random_Quote_Notification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Random Quote Notification
A simple program presenting the use of an API, the plyer notification module and Scheduling tasks in Python.

### Prerequisites
- These are located in requirements.txt
- You can run `pip install -r requirements.txt` to install these

### How to run the script
- Just run `main.py`

### Result
![Expected Output](result.png)

## *Author Name*
[Rogue Halo](https://github.com/rogue-halo)
Binary file added Scripts/API/Random_Quote_Notification/icon.ico
Binary file not shown.
32 changes: 32 additions & 0 deletions Scripts/API/Random_Quote_Notification/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Random Quote Desktop Notification
# Author: Rogue Halo
# Date: 1st October 2020
#---------------------------------
# Imports
import requests
from plyer import notification
from apscheduler.schedulers.blocking import BlockingScheduler

# Sub-Routines
def fetch(): # This gets the quote from the API and turns it into the quote to be displayed
quoteSite = requests.get("http://api.quotable.io/random")
quoteJson = quoteSite.json()
quote = quoteJson["content"] + "\n- " + quoteJson["author"]
if len(quote) > 256:
fetch()
else:
return quote

def display(quote): # Uses the plyer module to display the quote
notification.notify(title="Random Quote",message=quote,app_name="Random Quote",app_icon="icon.ico", timeout=10,toast=False)

# Main Program
def task(): # This puts it all together
quote = fetch()
display(quote)

if __name__ == "__main__":
task() # So that it prints a quote without waiting for the interval
scheduler = BlockingScheduler() # Creates a scheduler
scheduler.add_job(task, 'interval', hours=1) # Sets the interval, you may change this to your preferences
scheduler.start() # Starts scheduler
Binary file not shown.
Binary file added Scripts/API/Random_Quote_Notification/result.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.