-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.py
53 lines (42 loc) · 1.4 KB
/
example.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
from pathlib import Path
from minoshiro import Medium, Minoshiro, Site
async def postgres():
postgres_config = {
"host": "localhost",
"port": "5432",
"user": "postgres",
"database": "postgres"
}
robo = await Minoshiro.from_postgres(
postgres_config,
cache_pages=1,
)
# get_data eagerly evaluates all the data and return them in a dict
saekano = await robo.get_data(
'Saenai Heroine no Sodatekata', Medium.ANIME
)
for site, data in saekano.items():
print(site, data)
# yield_data lazily evaluates the data and you can iterate over them
async for site, data in robo.yield_data('New Game!', Medium.MANGA):
print(site, data)
async def sqlite():
# from_sqlite method accepts both a string or a Pathlib Path object.
sqlite_path = 'path/to/sqlite/database'
another_path = Path('another/sqlite/path')
robo = await Minoshiro.from_sqlite(
sqlite_path
)
# We only want the results from those 2 sites.
sites = (Site.LNDB, Site.MAL)
async for site, data in robo.get_data('overlord', Medium.LN, sites):
print(site, data)
another_robo = await Minoshiro.from_sqlite(
another_path
)
# Specify the seconds for HTTP request timeout.
print(
await another_robo.get_data(
'Love Live Sunshine!', Medium.ANIME, timeout=10
)
)