-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlemmy_manager.py
More file actions
35 lines (30 loc) · 839 Bytes
/
lemmy_manager.py
File metadata and controls
35 lines (30 loc) · 839 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
34
35
from pythorhead import Lemmy
from config import settings
import sys
import time
import logging
# Global variable
LEMMY = None
def login():
global LEMMY
try:
LEMMY = Lemmy("https://" + settings.INSTANCE, request_timeout=10)
LEMMY.log_in(settings.USERNAME, settings.PASSWORD)
logging.info("Successfully logged in to Lemmy instance")
return LEMMY
except Exception as e:
logging.error(f"Failed to login to Lemmy: {e}")
raise
def get_lemmy_instance():
global LEMMY
try:
if LEMMY is None:
login()
return LEMMY
except Exception as e:
logging.error(f"Failed to get Lemmy instance: {e}")
raise
def restart_bot():
logging.info("Bot restart requested, shutting down in 15 seconds...")
time.sleep(15)
sys.exit(1)