Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions pauperformance_bot/cli/group/academy.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,92 @@
#!/usr/bin/env python3
from pauperformance_bot.cli.builder.command import CLICommand
from pauperformance_bot.cli.builder.group import CLIGroup
from pauperformance_bot.cli.builder.options import FlagCLIOption
from pauperformance_bot.constant.cli import (
ACADEMY_CLI_GROUP,
UPDATE2_ACADEMY_CMD,
UPDATE_ACADEMY_CMD,
)
from pauperformance_bot.task.academy import main as main_v1
from pauperformance_bot.task.academy import (
run_coroutine_in_event_loop,
async_import_players_videos_from_twitch,
async_import_players_videos_from_youtube,
async_import_decks_from_deckstats,
async_import_decks_from_discord
)
from pauperformance_bot.task.academy2 import main as main_v2
from pauperformance_bot.util.log import get_application_logger

logger = get_application_logger(ACADEMY_CLI_GROUP)


class TwitchCLIOption(FlagCLIOption):
def __init__(self):
super().__init__("twitch", "Import players' videos from Twitch.")


class YouTubeCLIOption(FlagCLIOption):
def __init__(self):
super().__init__("youtube", "Import players' videos from YouTube.")


class DeckstatsCLIOption(FlagCLIOption):
def __init__(self):
super().__init__("deckstats", "Import decks from DeckStats.")


class DiscordCLIOption(FlagCLIOption):
def __init__(self):
super().__init__("discord", "Import decks from Discord.")


class UpdateCommand(CLICommand):
def __init__(self):
super().__init__(
UPDATE_ACADEMY_CMD,
"Update Academy web site (old version).",
[],
[
TwitchCLIOption(),
YouTubeCLIOption(),
DeckstatsCLIOption(),
DiscordCLIOption()
],
)

def dispatch_cmd(self, *args, **kwargs):
super().dispatch_cmd(*args, **kwargs)
main_v1()
default = True
if kwargs.pop(TwitchCLIOption().dest_var, False):
default = False
run_coroutine_in_event_loop(
async_import_players_videos_from_twitch,
send_notification=True,
update_dev=False
)
if kwargs.pop(YouTubeCLIOption().dest_var, False):
default = False
run_coroutine_in_event_loop(
async_import_players_videos_from_youtube,
send_notification=True,
update_dev=False
)
if kwargs.pop(DeckstatsCLIOption().dest_var, False):
default = False
run_coroutine_in_event_loop(
async_import_decks_from_deckstats,
send_notification=True,
update_dev=False
)
if kwargs.pop(DiscordCLIOption().dest_var, False):
default = False
run_coroutine_in_event_loop(
async_import_decks_from_discord,
send_notification=True,
update_dev=False
)
if default:
main_v1()


class UpdateCommand2(CLICommand):
Expand Down
43 changes: 40 additions & 3 deletions pauperformance_bot/task/academy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,45 @@
from pauperformance_bot.service.pauperformance.storage.dropbox_ import DropboxService


async def async_academy_update():
async def async_setup_pauperformance_service():
storage = DropboxService()
archive = MTGGoldfishArchiveService(storage)
discord = AsyncDiscordService()
pauperformance = AsyncPauperformanceService(discord, storage, archive)
await pauperformance.discord.wait_until_ready()
return pauperformance


async def async_import_players_videos_from_twitch(send_notification=True, update_dev=True):
pauperformance = await async_setup_pauperformance_service()
await pauperformance.import_players_videos_from_twitch(send_notification)
academy = AcademyService(pauperformance)
academy.update_all(update_dev)


async def async_import_players_videos_from_youtube(send_notification=True, update_dev=True):
pauperformance = await async_setup_pauperformance_service()
await pauperformance.import_players_videos_from_youtube(send_notification)
academy = AcademyService(pauperformance)
academy.update_all(update_dev)


async def async_import_decks_from_deckstats(send_notification=True, update_dev=True):
pauperformance = await async_setup_pauperformance_service()
await pauperformance.import_decks_from_deckstats(send_notification)
academy = AcademyService(pauperformance)
academy.update_all(update_dev)


async def async_import_decks_from_discord(send_notification=True, update_dev=True):
pauperformance = await async_setup_pauperformance_service()
await pauperformance.import_decks_from_discord(send_notification)
academy = AcademyService(pauperformance)
academy.update_all(update_dev)


async def async_academy_update():
pauperformance = await async_setup_pauperformance_service()

# import new content
await pauperformance.import_players_videos_from_twitch(send_notification=True)
Expand All @@ -29,13 +62,17 @@ async def async_academy_update():
academy.update_all(update_dev=False) # avoid unnecessary changes


def main():
def run_coroutine_in_event_loop(coroutine, **kwargs):
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(async_academy_update())
loop.run_until_complete(coroutine(**kwargs))
finally:
loop.close()


def main():
run_coroutine_in_event_loop(async_academy_update)


if __name__ == "__main__":
main()