You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
908 B
Python
34 lines
908 B
Python
9 months ago
|
from __future__ import annotations
|
||
|
from aiohttp import web
|
||
|
from utils.server import register_server_module
|
||
|
|
||
|
from lib.config import Config
|
||
|
from service.mediawiki_api import MediaWikiApi
|
||
|
|
||
|
|
||
|
async def init_mw_api(app: web.Application):
|
||
|
mw_api = MediaWikiApi.create()
|
||
|
|
||
|
bot_username = Config.get("mediawiki.bot_username", "", str)
|
||
|
bot_password = Config.get("mediawiki.bot_password", "", str)
|
||
|
|
||
|
if bot_username and bot_password:
|
||
|
try:
|
||
|
await mw_api.robot_login(bot_username, bot_password)
|
||
|
except Exception as e:
|
||
|
print("Cannot login to Robot account, please check config.")
|
||
|
|
||
|
site_meta = await mw_api.get_site_meta()
|
||
|
|
||
|
print(
|
||
|
"Connected to Wiki %s, Robot username: %s"
|
||
|
% (site_meta["sitename"], site_meta["user"])
|
||
|
)
|
||
|
|
||
|
|
||
|
def init(app: web.Application):
|
||
|
app.on_startup.append(init_mw_api)
|
||
|
|
||
|
|
||
|
register_server_module("mediawiki_api", init)
|