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 otaku-info-web. 

5 

6otaku-info-web 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 

11otaku-info-web 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 otaku-info-web. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20import time 

21from puffotter.flask.base import db, app 

22from otaku_info_web.db.MediaUserState import MediaUserState 

23from otaku_info_web.db.MangaChapterGuess import MangaChapterGuess 

24from otaku_info_web.utils.enums import MediaType, ListService 

25 

26 

27def update_manga_chapter_guesses(): 

28 """ 

29 Updates the manga chapter guesses 

30 :return: None 

31 """ 

32 app.logger.debug("Starting update of manga chapter guesses") 

33 anilist_ids = { 

34 x.media_id.service_id: x.media_id 

35 for x in MediaUserState.query.all() 

36 if x.media_id.media_item.media_type == MediaType.MANGA 

37 and x.media_id.service == ListService.ANILIST 

38 } 

39 guesses = { 

40 x.media_id.service_id: x 

41 for x in MangaChapterGuess.query.all() 

42 } 

43 

44 for anilist_id in anilist_ids: 

45 if anilist_id not in guesses: 

46 new_guess = MangaChapterGuess(media_id=anilist_ids[anilist_id]) 

47 db.session.add(new_guess) 

48 guesses[anilist_id] = new_guess 

49 

50 db.session.commit() 

51 

52 for anilist_id, guess in guesses.items(): 

53 

54 if anilist_id not in anilist_ids: 

55 db.session.delete(guess) 

56 app.logger.debug(f"Deleting stale chapter guess for {anilist_id}") 

57 else: 

58 app.logger.debug(f"Updating chapter guess for {anilist_id}") 

59 guess.update() 

60 time.sleep(1) 

61 

62 db.session.commit() 

63 

64 app.logger.debug("Finished updating manga chapter guesses")