Beispiel #1
0
def login():
    if request.method == 'GET':
        try:
            return Login.show_login_page(request.args['err'])
        except:
            return Login.show_login_page(False)
    elif request.method == 'POST':
        return Login.verify_login()
Beispiel #2
0
def scrapy_product():
    try:
        Login().login()
        Purchase().index().export().send_message()

    except Exception:
        msg = traceback.format_exception(*sys.exc_info())
        logging.error(''.join(msg))
        raise Exception(''.join(msg))
    finally:
        Browser().quit()
        print('do again!!!!')
Beispiel #3
0
    def twitter_request(self, uri, verb='GET'):
        authorized_token = oauth2.Token(self.oauth_token,
                                        self.oauth_token_secret)
        authorized_client = oauth2.Client(Login.get_consumer(),
                                          authorized_token)

        # Make Twitter API calls!
        response, content = authorized_client.request(uri, verb)
        if response.status != 200:
            print("An error occurred when searching!")

        return json.loads(content.decode('utf-8'))
Beispiel #4
0
def scrapy_product():
        try:
            Login().login()
            Product.correct_sku_timer()
            Product().operate()
        except Exception:
            msg = traceback.format_exception(*sys.exc_info())
            logging.error(
                ''.join(msg)
            )
            raise Exception(''.join(msg))
        finally:
            Browser().quit()
            print('do again!!!!')
Beispiel #5
0
def initiate_flask_operator():

    login = Login()
    app = Flask(__name__)
    app.secret_key = "1234"

    @app.before_request
    def load_user():
        # Check if there is key called 'screen_name'
        if 'screen_name' in session:
            g.user = User.load_from_db_by_screen_name(session['screen_name'])

    @app.route("/")
    def homage():
        return render_template("home.html")

    @app.route("/login/twitter")
    def twitter_login():

        # If user logged in, redirect to profile.
        if 'screen_name' in session:
            return redirect(url_for("profile"))

        request_token = login.get_request_token()
        session['request_token'] = request_token

        return redirect(login.get_auth_verifier_url(request_token))

    @app.route("/auth/twitter")
    def twitter_auth():
        authentication_verifier = request.args.get("oauth_verifier")

        # Retrieve the value of request token from the session.
        access_token = login.get_access_token(session["request_token"],
                                              authentication_verifier)

        user = User.load_from_db_by_screen_name(access_token['screen_name'])
        if not user:
            user = User(None, access_token['screen_name'],
                        access_token['oauth_token'],
                        access_token['oauth_token_secret'])

        session['screen_name'] = user.get_screen_name()

        return redirect(url_for("profile"))

    @app.route("/profile")
    def profile():
        return render_template("profile.html", user=g.user)

    @app.route("/logout")
    def logout():
        session.clear()
        return redirect(url_for("homepage"))

    @app.route("/search")
    def search():
        query = request.args.get('q')
        tweets = g.user.twitter_request(
            f"https://api.twitter.com/1.1/search/tweets.json?q={query}")

        tweet_texts = [{
            "tweet": tweet['text'],
            "label": "neutral"
        } for tweet in tweets['statuses']]

        for tweet in tweet_texts:
            r = requests.post("http://text-processing.com/api/sentiment/",
                              data={"text": tweet["tweet"]})
            json_response = r.json()
            tweet["label"] = json_response["label"]

        return render_template("search.html", content=tweet_texts)

    # Callback URL in application settings would then be: http://127.0.0.1:4995/auth/twitter
    app.run(port=4995)
Beispiel #6
0
def logout():
    return Login.logout()
Beispiel #7
0
from utils.login_required import LoginValidator
from db_connection import DBGateway
from controller.login import Login
from controller.register import Register
from controller.process_item import ProcessItem
from controller.catalog import Catalog
from controller.loan import Loan
from controller.search import SearchItem

app = Flask(__name__)
app.secret_key = b'\xfb\xcf\x9e\x10\xd2\xdc2\x86\xe3\xf8\xf6\xf1\x89\xe1\xf8R'
db_gateway = DBGateway(app)
app.template_folder = 'view/templates'
app.static_folder = 'view/static'
app.active_users = 0
Login = Login(db_gateway)
Register = Register(db_gateway)
ProcessItem = ProcessItem(db_gateway)
Catalog = Catalog(db_gateway)
Loan = Loan(db_gateway)
SearchItem = SearchItem(db_gateway)


@app.errorhandler(500)
def page_not_found(e):
    return render_template('error.html'), 500


@app.route('/', defaults={'path': ''})
@app.route("/<path:path>")
@LoginValidator.login_required