def toogle_subscription(user_id): user = s.query(User).filter_by(user_id=user_id).first() if not user.active: user.active = True else: user.active = False s.commit()
def erase_new_chapters(context): manga_list = s.query(Tracking).all() for manga in manga_list: manga.new_chapters = None s.commit() s.close() print("new chapters erased")
def delete_manga(manga_site, manga_id): """ deletes manga from readmanga or mintmanga tables """ if manga_site == 'readmanga': manga = s.query(Readmanga).filter_by(id=manga_id).first() if manga_site == 'mintmanga': manga = s.query(Mintmanga).filter_by(id=manga_id).first() s.delete(manga) s.commit()
def get_or_create_subscriber(effective_user, message): subscriber = s.query(User).filter_by(user_id=effective_user.id).first() if not subscriber: subscriber = User( username=effective_user.username, user_id=effective_user.id, chat_id=message.chat.id, active=False ) s.add(subscriber) s.commit() return subscriber
def unsubscribe_from_manga(manga_site, user_id, manga_id): """ manga_site - 'readmanga' or 'mintmanga' user_id - telegram user_id from effective_user returns list with readmanga/mintmanga ids """ user = get_user(user_id) if manga_site == 'readmanga': manga = s.query(Readmanga).filter_by(id=manga_id).first() user.readmanga.remove(manga) elif manga_site == 'mintmanga': manga = s.query(Mintmanga).filter_by(id=manga_id).first() user.mintmanga.remove(manga) s.commit()
def import_manga(filename, table): with open(filename, 'r') as f: data = json.load(f) for manga in data: manga_exists = s.query(table).filter_by( title=manga['title']).count() if manga_exists == 0: new_manga = table(title=manga['title'], url=manga['url'], img_url=manga['img_url']) s.add(new_manga) s.commit() else: continue
def subscribe_to_manga(manga_site, user_id, manga_id): """ manga_site - 'readmanga' or 'mintmanga' user_id - telegram user_id from effective_user manga_id - integer adding readmanga/mintmanga to user supscriptions """ user = get_user(user_id) if manga_site == 'readmanga': manga = s.query(Readmanga).filter_by(id=manga_id).first() user.readmanga.append(manga) elif manga_site == 'mintmanga': manga = s.query(Mintmanga).filter_by(id=manga_id).first() user.mintmanga.append(manga) s.commit()
def update_manga(manga_site, manga_id): """ manga_site - 'readmanga' or 'mintmanga' returns False if manga has no chapters or returns True """ time.sleep(get_random_sleep_time()) if manga_site == 'readmanga': manga = s.query(Readmanga).filter_by(id=manga_id).first() elif manga_site == 'mintmanga': manga = s.query(Mintmanga).filter_by(id=manga_id).first() if manga.update_date != date.today() or manga.update_date is None: html = get_html(manga.url) chapters = get_chapters_value(html) if chapters == "no chapters": return False manga.chapters = chapters manga.update_date = date.today() manga.number_of_chapters = len(chapters) s.commit() return True