-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal_stuff.py
51 lines (45 loc) · 1.69 KB
/
global_stuff.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
import asyncio
import logging
import dotenv
dotenv.load_dotenv("config.env")
def assert_getenv(name: str) -> str:
from os import getenv
value = getenv(name)
assert value is not None, f"missing \"{name}\" in config.env"
return value
# Google Sheets stuff
gs_client = None
leaderboard_ss = None
registry = None
raw_scores = None
registry_lock = asyncio.Lock()
raw_scores_lock = asyncio.Lock()
async def connect_to_google_sheets():
logging.info("Opening connection to gsheets...")
global gs_client
global leaderboard_ss
global registry
global raw_scores
import gspread
await asyncio.sleep(0) # yield thread
gs_client = gspread.service_account(filename='gs_service_account.json')
await asyncio.sleep(0) # yield thread
leaderboard_ss = gs_client.open_by_url(assert_getenv("spreadsheet_url"))
registry = leaderboard_ss.worksheet("Registry")
raw_scores = leaderboard_ss.worksheet("Raw Scores")
logging.info("Opened connection to gsheets!")
account_manager = None
async def load_mjs_account_manager():
# initialize an account manager to be shared with all extensions.
# login must happen in `setup_hook()`, before loading extensions
logging.info("Opening connection to mjs...")
global account_manager
from modules.mahjongsoul.account_manager import AccountManager
account_manager = AccountManager(
mjs_uid=assert_getenv("mjs_sh_uid"),
mjs_token=assert_getenv("mjs_sh_token"))
await asyncio.sleep(0) # yield thread
account_manager_login = asyncio.create_task(account_manager.connect_and_login())
await asyncio.sleep(0) # yield thread
await account_manager_login
logging.info("Opened connection to mjs!")