Skip to content
Merged
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
1 change: 0 additions & 1 deletion pauperformance_bot/constant/arena/twitch.py

This file was deleted.

43 changes: 0 additions & 43 deletions pauperformance_bot/entity/arena/indexable_video.py

This file was deleted.

5 changes: 2 additions & 3 deletions pauperformance_bot/entity/arena/youtube_video.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from pauperformance_bot.entity.arena.indexable_video import IndexableVideo
from pauperformance_bot.util.decorators import auto_repr, auto_str


@auto_repr
@auto_str
class YouTubeVideo(IndexableVideo):
class YouTubeVideo:
def __init__(
self,
video_id, # YouTube internals
Expand All @@ -23,13 +22,13 @@ def __init__(
language,
is_short,
):
super().__init__(description)
self.video_id = video_id
self.etag = etag
self.content_video_id = content_video_id
self.published_at = published_at
self.channel_id = channel_id
self.channel_title = channel_title
self.description = description
self.playlist_id = playlist_id
self.position = position
self.created_at = created_at
Expand Down
1 change: 1 addition & 0 deletions pauperformance_bot/service/academy/data_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(

def export_all(self):
# TODO: remove each (relevant) folder before re-exporting to avoid stale files
# TODO: figure out what is the right order of export operations
# self.export_miscellanea()
# self.export_creator_sheets()
# self.export_archetypes()
Expand Down
39 changes: 0 additions & 39 deletions pauperformance_bot/service/arena/twitch.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(
# So, let's just fix this shit ourselves with some caching mechanism.
self.storage = storage # will be the source of truth to detect missing decks
self._decks_cache: list[AbstractArchivedDeck] = [] # will act as a cache
self.list_decks() # forces caching

@staticmethod
def _parse_login_authenticity_token(response):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from pauperformance_bot.constant.arena.youtube import YOUTUBE_CONNECTION_POOL_SIZE_API
from pauperformance_bot.entity.config.creator import CreatorConfig
from pauperformance_bot.service.arena.twitch import TwitchService
from pauperformance_bot.service.arena.youtube import YouTubeService
from pauperformance_bot.service.mtg.scryfall import ScryfallService
from pauperformance_bot.service.nexus.async_discord_service import AsyncDiscordService
Expand All @@ -22,15 +21,13 @@ def __init__(
storage,
archive,
scryfall=ScryfallService(),
twitch=TwitchService(),
youtube=YouTubeService(),
config_reader=ConfigReader(),
):
super().__init__(
storage,
archive,
scryfall,
twitch,
youtube,
config_reader,
)
Expand Down
33 changes: 1 addition & 32 deletions pauperformance_bot/service/pauperformance/pauperformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from requests.exceptions import HTTPError

import pauperformance_bot
from pauperformance_bot.constant.arena.twitch import TWITCH_VIDEO_URL
from pauperformance_bot.constant.arena.youtube import YOUTUBE_VIDEO_URL
from pauperformance_bot.constant.mtg.scryfall import REQUESTS_SLEEP_SECONDS
from pauperformance_bot.constant.pauperformance.myr import (
Expand All @@ -28,7 +27,6 @@
from pauperformance_bot.entity.deck.archive.abstract import AbstractArchivedDeck
from pauperformance_bot.entity.deck.playable import PlayableDeck
from pauperformance_bot.exceptions import PauperformanceException
from pauperformance_bot.service.arena.twitch import TwitchService
from pauperformance_bot.service.arena.youtube import YouTubeService
from pauperformance_bot.service.mtg.deckstats import DeckstatsService
from pauperformance_bot.service.mtg.scryfall import ScryfallService
Expand All @@ -55,14 +53,12 @@ def __init__(
storage,
archive,
scryfall=ScryfallService(),
twitch=TwitchService(),
youtube=YouTubeService(),
config_reader=ConfigReader(),
):
self.storage: AbstractStorageService = storage
self.archive: AbstractArchiveService = archive
self.scryfall = scryfall
self.twitch = twitch
self.youtube = youtube
self.config_reader = config_reader
self.players = config_reader.list_creators()
Expand Down Expand Up @@ -313,33 +309,6 @@ def delete_deck(self, deck_name):
discord_logger = DiscordMessagesSenderSyncService([message])
discord_logger.run_task()

def _list_twitch_videos(self):
logger.debug("Retrieving stored Twitch videos...")
academy_videos = []
for video in self.storage.list_imported_twitch_videos():
video_id, user_name, language, date, key = video.split(">")
video_path = posix_path(
self.storage.youtube_video_path,
video + ".txt", # TODO: get rid of this
)
indexable_video = self.storage.get_file(video_path)
academy_videos.append(
AcademyVideo(
video_id,
user_name,
indexable_video["title"],
language,
date,
indexable_video["deck_name"],
indexable_video["archetype"],
indexable_video["creator"],
f"{TWITCH_VIDEO_URL}{video_id}",
"twitch",
)
)
logger.debug("Retrieved stored Twitch videos.")
return academy_videos

def _list_youtube_videos(self):
logger.debug("Retrieving stored YouTube videos...")
academy_videos = []
Expand Down Expand Up @@ -368,7 +337,7 @@ def _list_youtube_videos(self):
return academy_videos

def list_videos(self) -> list[AcademyVideo]:
return self._list_twitch_videos() + self._list_youtube_videos()
return self._list_youtube_videos()

def print_stats(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from collections import defaultdict
from typing import DefaultDict, Optional, Tuple

from entity.deck.playable import PlayedCard

from pauperformance_bot.constant.mtg.game import BASIC_LANDS
from pauperformance_bot.constant.pauperformance.academy import AcademyFileSystem
from pauperformance_bot.constant.pauperformance.silver import (
Expand All @@ -21,6 +19,7 @@
from pauperformance_bot.entity.config.archetype import ArchetypeConfig
from pauperformance_bot.entity.deck.playable import (
PlayableDeck,
PlayedCard,
parse_playable_deck_from_lines,
)
from pauperformance_bot.service.mtg.mtggoldfish import MTGGoldfish
Expand Down
10 changes: 8 additions & 2 deletions pauperformance_bot/task/async_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
)
from pauperformance_bot.service.pauperformance.storage.dropbox_ import DropboxService
from pauperformance_bot.util.log import get_application_logger
from pauperformance_bot.util.time import last_week # noqa: F401
from pauperformance_bot.util.time import ( # noqa: F401
last_n_hours,
last_n_weeks,
last_week,
)

logger = get_application_logger()

Expand Down Expand Up @@ -59,8 +63,10 @@ async def scrape(since=None):
)
def main():
try:
asyncio.run(scrape(last_n_hours(1)))
# asyncio.run(scrape(last_n_weeks(1)))
# asyncio.run(scrape(last_week()))
asyncio.run(scrape())
# asyncio.run(scrape())
except RuntimeError as exc:
logger.exception(exc)

Expand Down
42 changes: 41 additions & 1 deletion pauperformance_bot/task/silver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jsonpickle

from pauperformance_bot.constant.pauperformance.academy import ACADEMY_FILE_SYSTEM
from pauperformance_bot.constant.pauperformance.myr import TOP_PATH
from pauperformance_bot.service.pauperformance.archive.mtggoldfish import (
MTGGoldfishArchiveService,
)
Expand All @@ -17,6 +18,7 @@
from pauperformance_bot.service.pauperformance.storage.dropbox_ import DropboxService
from pauperformance_bot.util.log import get_application_logger
from pauperformance_bot.util.path import (
posix_path,
safe_dump_json_to_file,
)

Expand Down Expand Up @@ -83,6 +85,43 @@ def dpl_classifier(environ, start_response):
return [json.dumps({"error": str(e)}).encode("utf-8")]


def apl_classifier(environ, start_response):
try:
method = environ["REQUEST_METHOD"]
if method != "POST":
start_response(
"405 Method Not Allowed", [("Content-Type", "application/json")]
)
return [json.dumps({"error": "Method not allowed"}).encode("utf-8")]
try:
request_length = int(environ.get("CONTENT_LENGTH", 0))
except (ValueError, TypeError):
request_length = 0
request_body = environ["wsgi.input"].read(request_length)
raw_data = json.loads(request_body.decode("utf-8"))
data = []
for d in raw_data["decks"]:
data.append(
{
"id": d["id"],
"cards": {
"mainboard": d["mainDeck"],
"sideboard": d["sideboard"],
},
}
)
response = generate_dpl_meta(data)
response = {d.identifier: d.archetype for d in response.dpl_decks}
response = json.loads(jsonpickle.encode(response, make_refs=False, warn=True))
start_response("200 OK", [("Content-Type", "application/json")])
return [json.dumps(response).encode("utf-8")]
except Exception as e:
start_response(
"500 Internal Server Error", [("Content-Type", "application/json")]
)
return [json.dumps({"error": str(e)}).encode("utf-8")]


def classify():
storage = DropboxService()
archive = MTGGoldfishArchiveService(storage)
Expand All @@ -97,4 +136,5 @@ def classify():
# posix_path(TOP_PATH, "dev", "decks-all-tournaments.json"),
# posix_path(TOP_PATH, "dev", "decks-all-tournaments-classified.json"),
# )
classify()
# classify()
generate_dpl_meta(posix_path(TOP_PATH, "dev", "decks-all-tournaments-mini.json"))
9 changes: 7 additions & 2 deletions pauperformance_bot/task/sync_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
from pauperformance_bot.constant.pauperformance.academy import AcademyFileSystem
from pauperformance_bot.entity.api.tournament import Tournament
from pauperformance_bot.service.mtg.mtggoldfish import MTGGoldfish
from pauperformance_bot.service.pauperformance.silver.sideboard_scraper import (
update_sideboard_guides,
)
from pauperformance_bot.util.log import get_application_logger
from pauperformance_bot.util.time import last_week
from pauperformance_bot.util.time import last_n_weeks

logger = get_application_logger()
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -48,7 +51,9 @@ def download_mtggoldfish(since):

def scrape(since):
download_mtggoldfish(since)
update_sideboard_guides()


if __name__ == "__main__":
scrape(last_week())
# scrape(last_week())
scrape(last_n_weeks(4 * 12))
Loading
Loading