-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Idea] Random manga/anime suggestion function #96
Comments
Theres a cache of anime IDs I maintain here In [11]: import random, requests, jikanpy
In [12]: cache = requests.get("https://raw.githubusercontent.com/seanbreckenridge/mal-id-cache/master/cache/anime_cache.json").json()["sfw"]
In [13]: resp = jikanpy.Jikan().anime(random.choice(cache))
In [14]: print(resp["title"], resp["url"])
Mijikamon https://myanimelist.net/anime/25045/Mijikamon You should still probably handle 404s, since theres a small chance old IDs might still be there, but should be much more accurate than picking randomly |
Hey. Thanks for your mal_cache. It working perfectly. Just one thing, does mal_cache will be update automatic? |
Uh, you can check the commits here it updates itself every few hours You'd still have to redownload that file periodically, random code from discord I wrote a while back, which keeps track of when it was last requested for a discord bot; import datetime, json
data = None
last_requested_at = None
async def update_data():
global data
global last_requested_at
# request if hasnt been requested or its been 6 hours
if last_requested_at is None or datetime.datetime.now() - last_requested_at > datetime.timedelta(hours=6):
async with aiohttp.ClientSession() as session:
async with session.get("https://raw.githubusercontent.com/seanbreckenridge/mal-id-cache/master/cache/anime_cache.json") as s:
if s.status == 200:
text = await s.text()
data = json.loads(text)["sfw"]
last_updated_at = datetime.datetime.now()
@commands.command()
async def randani(self, ctx):
await update_data() # updated the global if its out of date
id_ = random.choice(data)
async with session.get(f'https://api.jikan.moe/v3/anime/{id_}') as y:
if y.status == 200:
.... |
Oh nooo not async. I'm no experience with async. |
Doesnt have to be async, its just an example showing how one would cache the results -- just uses the global
(every 6 hours), and then re-requests the information Wasnt sure what you meant by 'update automatic' |
I'm just confused a bit in this section
I know that concept of your work that json will be updated every 6 hours or if no update at the moment. But somehow i'm still confusing above. Why you using |
|
The You could use |
welp, no |
I start to understand now :). Sorry for make you "confused" . The question "automatically update" i mean, is i want to make my own |
Easiest way to do that would be to either download the file from here periodically, or have a script like #!/usr/bin/env bash
# get the current directory
THIS_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
# change current directory to this one
cd "$THIS_DIR"
# clone the repo if it doesnt exist
if [[ ! -e mal-id-cache ]]; then
git clone 'https://github.com/seanbreckenridge/mal-id-cache'
fi
cd 'mal-id-cache'
# infinite loop to keep this updated
while true; do
git pull
sleep 30m
done
keep a local clone of it updated.
|
Thanks. I will close this report bug. Thanks for your patience |
Hello guys. I have an idea about making some random manga/anime suggest bot. This is my concept. I'm currently improve it, but using random number is kinda risky. Because some time it give me 404 . Can you point me where can i improve , or prevent both 404 siuation?
The text was updated successfully, but these errors were encountered: