-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.py
81 lines (57 loc) · 1.79 KB
/
helper.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from datetime import datetime, date, timedelta
import pytz
import requests
import credentials
# Set timezone for all datetime.now() requests
tz = pytz.timezone('Pacific/Auckland')
def get_ordinal_suffix(day: int) -> str:
"""
Returns the ordinal suffix for a given day.
Parameters:
day (int): The day for which the ordinal suffix is needed.
Returns:
str: The ordinal suffix for the given day.
"""
return {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th') if day not in (11, 12, 13) else 'th'
def getDateReadable() -> str:
"""
Get the current date in the format Monday, 3rd January 2023.
Returns:
str: The formatted date string.
"""
day_of_week = datetime.now(tz).strftime("%A")
day = int(datetime.now(tz).strftime("%d"))
ordinal_suffix = get_ordinal_suffix(day)
month_year = datetime.now(tz).strftime("%B %Y")
date = f"{day_of_week}, {day}{ordinal_suffix} {month_year}"
return date
def getDateToday() -> date:
"""
Get the current date. in correct timezone.
Format as a datetime.date object.
Returns:
date: The current date.
"""
return datetime.now(tz).date()
def getQuote() -> tuple[str, str]:
"""
Retrieves a random quote from an API.
Returns:
A tuple containing the quote and the author.
"""
# Get quote
response = requests.get(credentials.quote_url)
data = response.json()
quote = data[0]["q"]
author = data[0]["a"]
return quote, author
def decide_day_check() -> date:
"""
Helper function that decides what date to check for events.
"""
# Get today's date
check_date = datetime.now(tz).date()
# If past 8pm, check tomorrow's events
if datetime.now(tz).hour >= 20:
check_date += timedelta(1)
return check_date