This repository was archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (37 loc) · 1.23 KB
/
main.py
File metadata and controls
45 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Random Quote Desktop Notification
# Author: Rogue Halo
# Date: 1st October 2020
# ---------------------------------
# Imports
import requests
from apscheduler.schedulers.blocking import BlockingScheduler
from plyer import notification
# 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