Exemple #1
0
    async def fetch(id: str, channel: TextChannel) -> List[Game]:
        url = f"https://docs.google.com/spreadsheets/d/{id}"
        try:
            sheets_fetcher = Sheets.from_files(
                "client_secrets.json",
                "oath_cache.json",
            )
            sheets = sheets_fetcher.get(url)
            games: List[Game] = []
            # Must be the first sheet
            # Skip headers
            for row in sheets._sheets[0]._values[1:]:
                try:
                    games.append(
                        Game(
                            datetime.strptime(row[4], "%m/%d/%Y"),
                            Team(json.loads(row[0]), row[1]),
                            Team(json.loads(row[2]), row[3]),
                        ))
                except BaseException as exception:
                    await handle(None, exception)

            return games
        except BaseException as exception:
            await handle(None, exception)
            raise UsageException.game_sheet_not_loaded(channel, url)
Exemple #2
0
    async def fetch(channel: TextChannel):
        try:
            url = GameData.__get_url(channel)
        except BaseException as exception:
            await handle(None, exception)
            raise UsageException.directive_missing(channel, "games")

        try:
            sheets_fetcher = Sheets.from_files(
                "client_secrets.json",
                "oath_cache.json",
            )
            sheets = sheets_fetcher.get(url)
            games: List[Game] = []
            # Must be the first sheet
            # Skip headers
            for row in sheets._sheets[0]._values[1:]:
                try:
                    games.append(
                        Game(
                            datetime.strptime(row[4], "%m/%d/%Y"),
                            Team(json.loads(row[0]), row[1]),
                            Team(json.loads(row[2]), row[3]),
                        ))
                except BaseException as exception:
                    await handle(None, exception)

            return GameData(games)
        except BaseException as exception:
            await handle(None, exception)
            raise UsageException.game_sheet_not_loaded(channel, url)