diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-04-06 23:05:31 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-04-06 23:05:31 +0200 |
commit | 49b199c610bb32d0581d771d856b3e3332707f17 (patch) | |
tree | 9e9c633d5d77bf3ae56395d8cd732ce20dba6b43 /manager.py | |
parent | Added a link to the documentation in the about page. (diff) | |
download | newspipe-49b199c610bb32d0581d771d856b3e3332707f17.tar.gz newspipe-49b199c610bb32d0581d771d856b3e3332707f17.tar.bz2 newspipe-49b199c610bb32d0581d771d856b3e3332707f17.zip |
Migrate form Flask-Script to the built-in integration of the click command line interface of Flask.
Diffstat (limited to 'manager.py')
-rwxr-xr-x | manager.py | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/manager.py b/manager.py deleted file mode 100755 index fcb5d0c5..00000000 --- a/manager.py +++ /dev/null @@ -1,98 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -import logging -import os -from datetime import datetime - -from flask_migrate import Migrate, MigrateCommand -from flask_script import Manager -from werkzeug.security import generate_password_hash - -import newspipe.models -from newspipe.bootstrap import application, db -from newspipe.controllers import UserController - -logger = logging.getLogger("manager") - -Migrate(application, db) - -manager = Manager(application) -manager.add_command("db", MigrateCommand) - - -@manager.command -def db_empty(): - "Will drop every datas stocked in db." - with application.app_context(): - newspipe.models.db_empty(db) - - -@manager.command -def db_create(): - "Will create the database from conf parameters." - admin = { - "is_admin": True, - "is_api": True, - "is_active": True, - "nickname": "admin", - "pwdhash": generate_password_hash(os.environ.get("ADMIN_PASSWORD", "password")), - } - with application.app_context(): - try: - db.create_all() - UserController(ignore_context=True).create(**admin) - except Exception as e: - print(e) - - -@manager.command -def create_admin(nickname, password): - "Will create an admin user." - admin = { - "is_admin": True, - "is_api": True, - "is_active": True, - "nickname": nickname, - "pwdhash": generate_password_hash(password), - } - with application.app_context(): - UserController(ignore_context=True).create(**admin) - - -@manager.command -def fetch_asyncio(user_id=None, feed_id=None): - "Crawl the feeds with asyncio." - import asyncio - - with application.app_context(): - from newspipe.crawler import default_crawler - - filters = {} - filters["is_active"] = True - filters["automatic_crawling"] = True - if None is not user_id: - filters["id"] = user_id - users = UserController().read(**filters).all() - - try: - feed_id = int(feed_id) - except: - feed_id = None - - loop = asyncio.get_event_loop() - queue = asyncio.Queue(maxsize=3, loop=loop) - - producer_coro = default_crawler.retrieve_feed(queue, users, feed_id) - consumer_coro = default_crawler.insert_articles(queue, 1) - - logger.info("Starting crawler.") - start = datetime.now() - loop.run_until_complete(asyncio.gather(producer_coro, consumer_coro)) - end = datetime.now() - loop.close() - logger.info("Crawler finished in {} seconds.".format((end - start).seconds)) - - -if __name__ == "__main__": - manager.run() |