Example #1
0
def generate_message(body, methods=["POST"]):
  question = body["message"]
  twitter_handle = body["username"]

  # Call get_user_tweets() from twitter_scraper_fetcher.py to scrape some tweets
  tweets = get_user_tweets(twitter_handle)
  try:
    cleaned_tweets = clean_tweets_data(tweets)
    # Get a random tweet from the list of tweets
    bot_answer = generate_bot_answer(twitter_handle, question)

    # Send the answer to the app, to display to the user
    answer = {"username": twitter_handle, "message": moderate(bot_answer)}
    socketio.emit("bot answer", answer)
  except:
    bot_answer = "Sorry, I couldn't process that. Try again please."
    socketio.emit("error", {"username": twitter_handle, "message": moderate(bot_answer)})
Example #2
0
def generate_message(body, methods=["POST"]):
  question = body["message"]
  twitter_handle = body["username"]

  try:
    # Get a random tweet from the list of tweets
    bot_answer = generate_bot_answer(twitter_handle, question)

    # Send the answer to the app, to display to the user
    answer = {"username": twitter_handle, "message": bot_answer}
    socketio.emit("bot answer", answer)
    
  except:
    bot_answer = "Sorry, I couldn't process that. Try again please."
    socketio.emit("error", {"username": twitter_handle, "message": moderate(bot_answer)})
def generate_message(body, methods=["POST"]):
    question = body["message"]
    twitter_handle = body["username"]

    try:
        bot_answer = generate_bot_answer(twitter_handle, question)
        moderated_bot_answer = moderate(bot_answer)

        answer = {"username": twitter_handle, "message": moderated_bot_answer}
        socketio.emit("bot answer", answer)
    except:
        bot_answer = "Sorry, I couldn't process that. Try again please."
        socketio.emit("error", {
            "username": twitter_handle,
            "message": bot_answer
        })
Example #4
0
def generate_message(body, methods=["POST"]):
  question = body["message"]
  twitter_handle = body["username"]

  # Call get_user_tweets() from twitter_scraper_fetcher.py to scrape some tweets
  tweets = get_user_tweets(twitter_handle)

  try:
    # obtiene una lista random de twees
    cleaned_tweets = clean_tweets_data(tweets)
    single_tweet = random.choice(tweets)
    bot_answer = moderate(single_tweet)

    # Send the answer to the app, to display to the user
    answer = {"username": twitter_handle, "message": bot_answer}
    socketio.emit("bot answer", answer)
  except:
    bot_answer = "Lo siento, No pude procesar eso. Intente de nuevo."
    socketio.emit("error", {"username": twitter_handle, "message": bot_answer})
Example #5
0
def content():
    if not request.json or not "content" in request.json:
        abort(400)

    return jsonify({"data": moderate(request.json.get("content", ""))})