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 2019 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of _stockstert. 

5 

6_stockstert 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 

11_stockstert 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 

20import time 

21from stockstert.flask import db 

22from stockstert.utils.anilist import guess_latest_manga_chapter 

23 

24 

25class MangaChapterGuess(db.Model): 

26 

27 __tablename__ = "manga_chapter_guesses" 

28 """ 

29 The name of the database table 

30 """ 

31 

32 id = db.Column( 

33 db.Integer, primary_key=True, nullable=False, autoincrement=True 

34 ) 

35 """ 

36 The ID is the primary key of the table and increments automatically 

37 """ 

38 

39 last_check = db.Column(db.Integer, default=0, nullable=False) 

40 """ 

41 Indicates when the last check was 

42 """ 

43 

44 guess = db.Column(db.Integer, default=0, nullable=False) 

45 """ 

46 The current guess value 

47 """ 

48 

49 def update(self) -> bool: 

50 """ 

51 Updates the current value if more than an hour has elapsed since the 

52 last update 

53 :return: Whether or not the value was updated 

54 """ 

55 if time.time() - self.last_check > 3600: 

56 guess = guess_latest_manga_chapter(self.id) 

57 if guess is None: 

58 return False 

59 else: 

60 self.guess = guess 

61 self.last_check = time.time() 

62 return True 

63 else: 

64 return False