Exemplo n.º 1
0
from datetime import datetime
from logger_config import *
import logger_config

## Twitter credentials
CONSUMER_KEY = "bezNRWxWzcloXMNaedkZYzMij"
CONSUMER_SECRET = "2WSPYdZvsp3XJ1UIgELQN7Qppuhxts6GJBjfJc9wD14Dh5lktV"
ACCESS_TOKEN = "1062335738723745792-30gESiVR2MgJF6KumGYwAYAfVXZ9Lj"
ACCESS_TOKEN_SECRET = "ctCX8HMNTfYKrMTPFzIDw3CMhgshGHyha7PUjpBTafdDk"

#---Query---
QUERY = 'cyclone gaja'

#---Configuring log filename---
log_file = os.path.splitext(os.path.basename(__file__))[0] + ".log"
log = logger_config.configure_logger(
    'default', "" + DIR + "" + LOG_DIR + "/" + log_file + "")


#---Class for listening live streams---
class StdOutListener(StreamListener):
    def on_status(self, status):
        # Prints the text of the tweet
        tweet_str = str(status.text)
        tweet_location = str(status.user.location)
        log.info(tweet_str)
        time_str = str(datetime.now().strftime('%d/%m/%Y  %H:%M:%S'))
        with open(QUERY + '_tweets_.csv', 'a') as writeFile:
            writer = csv.writer(writeFile)
            writer.writerow([tweet_str, time_str, tweet_location])

    def on_error(self, status_code):
Exemplo n.º 2
0
import os
import logger_config
from flask import (
    Flask,
    request,
    jsonify,
)
from decorator.token_web_authorize_jwt import required_web_token_authorize
from controllers import (ApiAuthController, ApiCardController)
from controllers.ApiUserController import ApiUserController

app = Flask(__name__)
logger_config.configure_logger(app, __name__)
logger = logger_config.get_logger()


@app.route("/")
def hello():
    return jsonify({"message": "Bem vindo Desafio Hypercriativa"})


@app.route('/card', methods=['POST'])
@required_web_token_authorize
def card():
    http_code, json_payload = ApiCardController.post_card(request)
    logger.debug(f'AUTH - HTTP_CODE: {http_code}')
    response = app.response_class(response=json_payload,
                                  status=http_code,
                                  mimetype='application/json')
    return response