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>
4This file is part of otaku-info-bot.
6otaku-info-bot 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.
11otaku-info-bot 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.
16You should have received a copy of the GNU General Public License
17along with otaku-info-bot. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import time
21from kudubot.db import Base
22from sqlalchemy import Column, Integer
23from otaku_info_bot.fetching.anilist import guess_latest_manga_chapter
26class MangaChapterGuess(Base):
27 """
28 Models a manga chapter guess
29 """
31 __tablename__ = "manga_chapter_guesses"
32 """
33 The name of the database table
34 """
36 id = Column(Integer, primary_key=True, autoincrement=True)
37 """
38 The anilist ID of the guess
39 """
41 last_check = Column(Integer, default=0, nullable=False)
42 """
43 Indicates when the last check was
44 """
46 guess = Column(Integer, default=0, nullable=False)
47 """
48 The current guess value
49 """
51 def update(self) -> bool:
52 """
53 Updates the current value if more than an hour has elapsed since the
54 last update
55 :return: Whether or not the value was updated
56 """
57 if time.time() - self.last_check > 3600:
58 guess = guess_latest_manga_chapter(self.id)
59 if guess is None:
60 return False
61 else:
62 self.guess = guess
63 self.last_check = time.time()
64 return True
65 else:
66 return False