def refresh_chapters(): comics = data.get_comics() result = {} for comic in comics: comic_id, saved_chapter_num = refresh_chapter(comic.id) result[comic_id] = saved_chapter_num return result
def refresh_chapters(listener=None): comics = data.get_comics() results = [] total = len(comics) current = 0 for comic in comics: comic_id, saved_chapter_num = refresh_chapter(comic.id) current += 1 result = {'comic_id': comic_id, 'count': saved_chapter_num} results.append(result) if listener is not None: listener(current, total, result) return results
def refresh_comic_images(): comics = data.get_comics() result = dict() for comic in comics: front_cover = comic.front_cover if 'ishuhui' not in front_cover: current_app.logger.info('comic {} already refreshed'.format(comic.id)) continue image = requests.get(front_cover).content files = {'smfile': image} response = json.loads( requests.post('https://sm.ms/api/upload', files=files).text) if response.get('code') == 'success': url = response.get('data')['url'] comic.front_cover = url db.session.commit() result[comic.id] = url current_app.logger.info('refresh comic {} cover succeed, url :{}'.format( comic.id, url)) else: current_app.logger.info('failed comic {}'.format(comic.id)) return result
def comics(): comics = data.get_comics() return render_template('comics.html', comics=comics)
def comics(): classify_id = request.args.get('classify_id') comics = data.get_comics(classify_id) return render_template('comics.html', comics=comics)