Пример #1
0
oauth = flask_oauth.OAuth()

twitter = oauth.remote_app(
    'twitter',
    base_url='https://api.twitter.com/1.1/',
    request_token_url='https://api.twitter.com/oauth/request_token',
    access_token_url='https://api.twitter.com/oauth/access_token',
    authorize_url='https://api.twitter.com/oauth/authorize',
    consumer_key=app.config['CONSUMER_KEY'],
    consumer_secret=app.config['CONSUMER_SECRET'])

twitter_connection = Twitter(
    auth=OAuth(app.config["OAUTH_TOKEN"], app.config["OAUTH_SECRET"],
               app.config["CONSUMER_KEY"], app.config["CONSUMER_SECRET"]))

celery = create_celery_app(app, db)

from others import *
from route import *
from route.admin import *
from route.user import *


def configure_blueprints(blueprints):
    for blueprint in blueprints:
        app.register_blueprint(blueprint)


def init_app():
    """Create a Flask app."""
Пример #2
0
# -*- coding: utf-8 -*-
from requests import post
from factory import create_celery_app
import urllib
celery = create_celery_app()

# TODO Possibly remove this on release
# @celery.task
# def CR_installer(crs_csrs_payload, sink_url, source_url):
#     # Get these as parameter or inside crs_csrs_payload
#     endpoint = "/api/1.3/cr/add_cr"
#     print(crs_csrs_payload)
#     source = post(source_url+endpoint, json=crs_csrs_payload["source"])
#     print(source.url, source.reason, source.status_code, source.text)
#
#     sink = post(sink_url+endpoint, json=crs_csrs_payload["sink"])
#     print(sink.url, sink.reason, sink.status_code, sink.text)

import db_handler
from json import dumps, loads
from requests import get
from helpers_srv import Helpers, CR_tool


@celery.task
def get_AuthToken(cr_id, operator_url, app_config):
    print(operator_url, cr_id)
    helpers = Helpers(app_config)
    print(cr_id)
    token = get("{}/api/1.3/cr/auth_token/{}".format(
        operator_url, cr_id))  # TODO Get api path from some config?
Пример #3
0
# -*- coding: utf-8 -*-
import time
import traceback
from factory import create_celery_app
from .models import *
from .utils import translate_document
from datetime import timedelta, datetime
from StringIO import StringIO

celery = create_celery_app().celery

logger = celery.logger

@celery.task()
def process_request(tid):
    logger.warning("TR id: {}".format(tid))
    tr = TranslationRequest.objects.get(id=tid)
    try:
        tr.start()
        if tr.infile:
            infile = tr.infile
        else:
            infile = StringIO(tr.input)
        template = tr.template.text
        out = translate_document(infile=infile.get(),
                                template=template,
                                template_data=tr.to_mongo())
        tr.outfile.delete()
        tr.outfile.new_file(encoding="utf-8")
        for chunk in out:
            tr.outfile.write(chunk)