diff --git a/Scripts/API/Random_Quote_Notification/README.md b/Scripts/API/Random_Quote_Notification/README.md new file mode 100644 index 000000000..05129c711 --- /dev/null +++ b/Scripts/API/Random_Quote_Notification/README.md @@ -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) diff --git a/Scripts/API/Random_Quote_Notification/icon.ico b/Scripts/API/Random_Quote_Notification/icon.ico new file mode 100644 index 000000000..1d1dfdd9c Binary files /dev/null and b/Scripts/API/Random_Quote_Notification/icon.ico differ diff --git a/Scripts/API/Random_Quote_Notification/main.py b/Scripts/API/Random_Quote_Notification/main.py new file mode 100644 index 000000000..ca8f05be3 --- /dev/null +++ b/Scripts/API/Random_Quote_Notification/main.py @@ -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 diff --git a/Scripts/API/Random_Quote_Notification/requirements.txt b/Scripts/API/Random_Quote_Notification/requirements.txt new file mode 100644 index 000000000..c3378bad2 Binary files /dev/null and b/Scripts/API/Random_Quote_Notification/requirements.txt differ diff --git a/Scripts/API/Random_Quote_Notification/result.PNG b/Scripts/API/Random_Quote_Notification/result.PNG new file mode 100644 index 000000000..d834d39bf Binary files /dev/null and b/Scripts/API/Random_Quote_Notification/result.PNG differ