Skip to content

Commit

Permalink
Merge pull request #22 from EverythingSuckz/main
Browse files Browse the repository at this point in the history
feat: use anilist for schedule command
  • Loading branch information
lostb053 committed Oct 11, 2022
2 parents 12e4f7d + 93a60e8 commit 8ae1f58
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 67 deletions.
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

*.session*
.vscode/
24 changes: 23 additions & 1 deletion anibot/plugins/anilist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pyrogram.errors import UserNotParticipant
from .. import ANILIST_CLIENT, ANILIST_REDIRECT_URL, ANILIST_SECRET, OWNER, TRIGGERS as trg, BOT_NAME, anibot
from ..utils.data_parser import (
get_all_genres, get_all_tags, get_top_animes, get_user_activity, get_user_favourites, toggle_favourites,
get_all_genres, get_all_tags, get_scheduled, get_top_animes, get_user_activity, get_user_favourites, toggle_favourites,
get_anime, get_airing, get_anilist, get_character, get_additional_info, get_manga, browse_,
get_featured_in_lists, update_anilist, get_user, ANIME_DB, MANGA_DB, CHAR_DB, AIRING_DB, GUI
)
Expand Down Expand Up @@ -300,6 +300,28 @@ async def airing_cmd(client: Client, message: Message, mdata: dict):
if update:
PIC_LS.append(coverImg)

@anibot.on_message(filters.command(["schedule", f"schedule{BOT_NAME}"], prefixes=trg))
@control_user
async def get_schuled(client: anibot, message: Message, mdata: dict):
"""Get List of Scheduled Anime"""
gid = mdata['chat']['id']
find_gc = await DC.find_one({'_id': gid})
if find_gc is not None and 'schedule' in find_gc['cmd_list'].split():
return
x = await client.send_message(gid, "<code>Fetching Scheduled Animes</code>")
user = mdata['from_user']['id']
msg = await get_scheduled()
buttons = get_btns("SCHEDULED", result=[0], user=user)
await x.edit_text(msg, reply_markup=buttons)


@anibot.on_callback_query(filters.regex(pattern=r"sched_(.*)"))
@check_user
async def ns_(client: anibot, cq: CallbackQuery, cdata: dict):
kek, day, user = cdata['data'].split("_")
msg = await get_scheduled(int(day))
buttons = get_btns("SCHEDULED", result=[int(day)], user=user)
await cq.edit_message_text(msg, reply_markup=buttons)

@anibot.on_message(filters.command(["auth", f"auth{BOT_NAME}"], prefixes=trg))
@control_user
Expand Down
33 changes: 0 additions & 33 deletions anibot/plugins/jikan.py

This file was deleted.

83 changes: 70 additions & 13 deletions anibot/utils/data_parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytz
import requests
import time
import os
from bs4 import BeautifulSoup
from .db import get_collection
from .google_trans_new import google_translator
from .helper import cflag, make_it_rw, pos_no, return_json_senpai, day_, season_
from .helper import cflag, make_it_rw, pos_no, return_json_senpai, season_, timestamp_today
from .. import BOT_NAME
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from jikanpy import AioJikan
from datetime import datetime

tr = google_translator()
Expand Down Expand Up @@ -673,7 +673,44 @@ async def get_ui_text(case):
}
}
'''

SCHEDULE_QUERY = """
query ($page: Int, $gt: Int, $lt: Int) {
Page(page: $page, perPage: 100) {
pageInfo {
total
currentPage
hasNextPage
}
airingSchedules(airingAt_greater: $gt, airingAt_lesser: $lt) {
id
airingAt
timeUntilAiring
episode
mediaId
media {
id
title {
romaji
english
native
}
countryOfOrigin
duration
coverImage {
extraLarge
}
nextAiringEpisode {
airingAt
timeUntilAiring
episode
}
bannerImage
averageScore
siteUrl
}
}
}
}"""

async def get_studios(qry, page, user, auth):
vars_ = {'search': STUDIO_DB[qry], 'page': int(page)}
Expand Down Expand Up @@ -1383,16 +1420,36 @@ async def check_if_adult(id_):

#### END ####

#### Jikanpy part ####

async def get_scheduled(x: int = 9):
day = str(day_(x if x!=9 else datetime.now().weekday())).lower()
out = f"Scheduled animes for {day.capitalize()}\n\n"
async with AioJikan() as session:
sched_ls = (await session.schedule(day=day)).get(day)
for i in sched_ls:
out += f"• `{i['title']}`\n"
return out, x if x!=9 else datetime.now().weekday()
#### RIP Jikanpy ####


async def get_scheduled(day_id: int = 0):
# variables = {'page': 1, 'gt': timestamp_today(), 'lt': timestamp_today(1)}
that_day = timestamp_today(day_id)
day_inc = timestamp_today(day_id + 1)
variables = {'page': 1, 'gt': that_day, 'lt': day_inc}
result = await return_json_senpai(SCHEDULE_QUERY, variables, auth=False, user=None)
today = datetime.now(pytz.timezone("Asia/Kolkata"))
schedule_data = result["data"]['Page'].get("airingSchedules")
if not schedule_data:
return f"No more data"
msg = f"**Schedule for {datetime.fromtimestamp(that_day).strftime('%A')}**\n`{datetime.fromtimestamp(that_day).strftime('%d %B, %Y')}`\n\n"
for anime_data in schedule_data:
if anime_data.get("media", {}).get("countryOfOrigin") != "JP":
continue
if today.timestamp() > anime_data['airingAt']:
msg += "● "
else:
msg += "○ "
msg += f"`{datetime.fromtimestamp(anime_data['airingAt']).strftime('%H:%M')}` "
anime_title = anime_data.get('media', {}).get("title", {}).get('romaji')
anime_id = anime_data.get('media', {}).get("id")
deeplink = f"https://t.me/{BOT_NAME.replace('@', '')}/?start=anime_{anime_id}"
if len(anime_title) > 30:
msg += f"[{anime_title[:26]}]({deeplink})...</a>\n"
else:
msg += f"[{anime_title}]({deeplink})\n"
return msg

#### END ####

Expand Down
Loading

0 comments on commit 8ae1f58

Please sign in to comment.