Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of stockstert. 

5 

6stockstert is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11stockstert is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with stockstert. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from flask import render_template, Blueprint 

21from flask_login import login_required 

22from flask import request 

23from stockstert.flask import db 

24from stockstert.utils.anilist import load_anilist 

25from stockstert.db.MangaChapterGuess import MangaChapterGuess 

26 

27static_blueprint = Blueprint("static", __name__) 

28 

29 

30@static_blueprint.route("/anilist/manga", methods=["GET"]) 

31def anilist_manga(): 

32 username = request.args["username"] 

33 custom_list = request.args.get("list") 

34 mincount = int(request.args.get("mincount", 0)) 

35 user_list = load_anilist(username, "MANGA", custom_list) 

36 

37 cached_guesses = {x.id: x.guess for x in MangaChapterGuess.query.all()} 

38 

39 for entry in user_list: 

40 anilist_id = entry["media"]["id"] 

41 if anilist_id not in cached_guesses: 

42 new_guess = MangaChapterGuess(id=anilist_id, last_check=0) 

43 db.session.add(new_guess) 

44 cached_guesses[anilist_id] = new_guess 

45 db.session.commit() 

46 

47 display_data = [] 

48 print(len(user_list)) 

49 for entry in user_list: 

50 data = { 

51 "name": entry["media"]["title"]["english"], 

52 "id": entry["media"]["id"], 

53 "progress": entry["progress"], 

54 "latest": entry["media"]["chapters"], 

55 "cover": entry["media"]["coverImage"]["medium"], 

56 "url": "https://anilist.co/manga/{}".format(entry["media"]["id"]) 

57 } 

58 

59 if data["name"] is None: 

60 data["name"] = entry["media"]["title"]["romaji"] 

61 if data["latest"] is None: 

62 data["latest"] = cached_guesses.get(entry["media"]["id"]) 

63 

64 data["diff"] = data["latest"] - data["progress"] 

65 if data["diff"] >= mincount: 

66 display_data.append(data) 

67 

68 display_data.sort(key=lambda x: x["diff"], reverse=True) 

69 

70 return render_template( 

71 "sortable_list.html", 

72 username=username, 

73 display_data=display_data 

74 ) 

75 

76 

77@static_blueprint.route("/update") 

78def update(): 

79 for guess in MangaChapterGuess.query.all(): 

80 try: 

81 print(guess) 

82 guess.update() 

83 db.session.commit() 

84 except IndexError: 

85 pass