-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
33 lines (25 loc) · 702 Bytes
/
example.py
File metadata and controls
33 lines (25 loc) · 702 Bytes
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
from onthisday import Today
SUPPORTED_LOCALES = ["it", "en", "es", "pt", "de", "fr"]
# Wikipedia source
wiki = Today("wiki", SUPPORTED_LOCALES[0])
# or
# wiki = Today()
# as the wikipedia event is the default one
# Retrieve all the events
print(wiki.all())
# Retrieve the last n events
print(wiki.last(5))
# Retrieve the last event
print(wiki.last()[0])
# Retrieve a random event
print(wiki.random())
# Same, but with year range
try:
print(wiki.random(from_year=1980, to_year=2005))
except IndexError:
print("No event for specified range")
# Same, but with BC years
try:
print(wiki.random(to_year=-5)) # i.e. until 5 BC
except IndexError:
print("No event for specified range")