def getAnimeByGenres(genres, year=""): if year != "" and len(year) != 4: return Response(response=json([]), status=200, mimetype="application/json") genres_list = [] if "," in genres: genres_list = genres.split(",") else: genres_list.append(genres) query = collection.find({ "$and": [{ "genres": { "$all": genres_list } }, { "premiere": { "$regex": year } }] }) query = sorted(query, key=lambda x: x["series_pretty"]) data = json(query) return Response(response=data, status=200, mimetype="application/json")
def getAnimeByYear(year=""): if len(year) != 4: return Response(response=json([]), status=200, mimetype="application/json") query = collection.find({"premiere": {"$regex": year}}) query = sorted(query, key=lambda x: x["series_pretty"]) data = json(query) return Response(response=data, status=200, mimetype="application/json")
def getUpcomingAnimes(): query = collection.find({"upcoming": {"$eq": True}}) query = sorted(query, key=lambda x: x["series_pretty"]) data = json(query) return Response(response=data, status=200, mimetype="application/json")
def getTopAnimes(): query = collection.find({"score": {"$gte": "7.5"}}) query = sorted(query, key=lambda x: float(x["score"] or 0.00)) query = list(reversed(query)) data = json(query[:50]) return Response(response=data, status=200, mimetype="application/json")
def getLatestAnimes(): query = collection.find( {"updated": { "$gte": datetime.now() - timedelta(weeks=9) }}) query = sorted(query, key=lambda x: compareJSONdate(x["updated"]), reverse=True) data = json(query[:12]) return Response(response=data, status=200, mimetype="application/json")
def getAnime(id): query = collection.find( {"$or": [ { "series_pretty": id }, { "series": id }, { "title": id }, ]}) data = json(query) return Response(response=data, status=200, mimetype="application/json")
def getRandomAnimes(): size = request.args.get('size') query = collection.aggregate([{ "$match": { "series": { "$exists": True } } }, { "$sample": { "size": int(size) if size else 6 }, }]) data = json(query) return Response(response=data, status=200, mimetype="application/json")
def searchAnime(id=""): if id == "": return Response(response=dumps([]), status=200, mimetype="application/json") query = collection.find({ "$or": [ { "series_pretty": { "$regex": id, "$options": "i" } }, { "title": { "$regex": id, "$options": "i" } }, { "title_romaji": { "$regex": id, "$options": "i" } }, ], }) query = sorted(query, key=lambda x: x["series_pretty"]) # add count and sanitize for anime in query: anime['count'] = len(dict(anime['eps']).keys()) anime.pop('__v', None) anime.pop('eps', None) anime.pop('desc', None) anime.pop('genres', None) anime.pop('trailer', None) anime.pop('duration', None) anime.pop('broadcast', None) return Response(response=json(query), status=200, mimetype="application/json")
def getLastAiredAnimes(): return Response(response=json("This route has been deprecated"), status=200, mimetype="application/json")