-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (59 loc) · 1.6 KB
/
main.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
from pypresence import Presence
import time
from dotenv import load_dotenv
import os
import time
from jpdb import jpdbSession
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
# Load variables
load_dotenv()
SID = os.getenv('SID')
CLIENT_ID = os.getenv('CLIENT_ID')
start_epoch = int(time.time())
# Load jpdb session
jpdb = jpdbSession(SID)
assert jpdb.logged, 'SID not valid !'
# Load pypresence
RPC = Presence(CLIENT_ID)
RPC.connect()
def update(details: str, state: str) -> None:
# Function to make the code a bit lighter
RPC.update(
large_image='logo',
large_text='\\( ̄︶ ̄*\\))',
start=start_epoch,
state=state,
details=details
)
logging.info('Rich presence is active !')
while True:
jpdb.refresh()
due = jpdb.get_due()
known = jpdb.get_known_words()
logging.info(f'Known words: {known}, Due cards: {due}')
if due:
update(
f'Reviewing | {due} Cards remaining',
f'{known} Known words',
)
else:
stats: dict = jpdb.get_stats()
new_today = stats['new'][-1]
remaining_new = jpdb.new_cards_limit - new_today
logging.info(msg=f'New cards remaining: {remaining_new}')
if remaining_new > 0:
update(
f'Learning | {remaining_new} New cards remaining',
f'{known} Known words'
)
else:
update(
f'Learning new words !',
f'{known} Known words'
)
time.sleep(10)