예제 #1
0
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))
예제 #2
0
def db_create():
    "Will create the database from conf parameters."
    with application.app_context():
        try:
            db.create_all()
        except Exception as e:
            print(e)
예제 #3
0
파일: manager.py 프로젝트: moser/newspipe
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)
예제 #4
0
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():
        db.create_all()
        UserController(ignore_context=True).create(**admin)
예제 #5
0
from newspipe.bootstrap import application

babel = Babel(application)


# Jinja filters
def month_name(month_number):
    return calendar.month_name[month_number]


application.jinja_env.filters["month_name"] = month_name
application.jinja_env.filters["datetime"] = format_datetime
# inject application in Jinja env
application.jinja_env.globals["application"] = application

with application.app_context():
    g.api = Api(application, prefix="/api/v2.0")
    g.babel = babel

    from newspipe.web import views

    application.register_blueprint(views.articles_bp)
    application.register_blueprint(views.article_bp)
    application.register_blueprint(views.feeds_bp)
    application.register_blueprint(views.feed_bp)
    application.register_blueprint(views.categories_bp)
    application.register_blueprint(views.category_bp)
    application.register_blueprint(views.icon_bp)
    application.register_blueprint(views.admin_bp)
    application.register_blueprint(views.users_bp)
    application.register_blueprint(views.user_bp)
예제 #6
0
def db_empty():
    "Will drop every datas stocked in db."
    with application.app_context():
        newspipe.models.db_empty(db)