В Heroku развернуто базовое приложение на python / flask (код ниже).Насколько я знаю, procfile является правильным и требования актуальны.Приложение в основном получает два аргумента через браузер и возвращает JSON.Я относительно новичок в heroku и procfiles, поэтому я боюсь, что это что-то простое.
Но я получаю эту ошибку в своих журналах, как только я пытаюсь открыть ссылку в браузере:
OSError: [Errno 98] Адрес уже используется
Правильный ли мой procfile?
Пожалуйста, найдите код для справки:
Procfile:
web: gunicorn SA2:SAapp
Код Python:
from textblob import TextBlob
import tweepy
import matplotlib.pyplot as plt
from flask import Flask
import json
SAapp = Flask("Sentwinel")
#Function that collects the percentages
def percentage(part, whole):
return 100 * float(part)/float(whole)
#Setting variables for the auth information that allows us to access twitters API
consumerKey = "3DOvT3TjEgd16Yk7xvNxNjUMQ"
consumerSecret = "DeMxglGqNdO9A1xwE8PfI4IMTPFnL6jAihxunsA45zlxfwW9bk"
accessToken = "381544613-Zda1F8KbIZ0q1Eyz1azIpllKu9eimHaUkJNZpioa"
accessTokenSecret = "GwtenTAoU3Bki2F1MvnbNRxm3XahX0O8vRx8eFqC8SVoR"
#Connects to the twitter API
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth)
#The function that gets the search terms and returns the SA
@SAapp.route("/<searchTerm>/<noOfSearchTerms>")
def GetPlot (searchTerm, noOfSearchTerms):
noOfSearchTerms = int(noOfSearchTerms)
tweets = tweepy.Cursor(api.search, q=searchTerm).items(noOfSearchTerms)
positive = 0
negative = 0
neutral = 0
polarity = 0
for tweet in tweets:
print(tweet.text)
analysis = TextBlob(tweet.text)
polarity += analysis.sentiment.polarity
if (analysis.sentiment.polarity == 0):
neutral += 1
elif (analysis.sentiment.polarity < 0.00):
negative += 1
elif (analysis.sentiment.polarity > 0.00):
positive += 1
#Shows the percentages of how many tweets per emotion per how many search terms.
positive = percentage(positive, noOfSearchTerms)
negative = percentage(negative, noOfSearchTerms)
neutral = percentage(neutral, noOfSearchTerms)
polarity = percentage(polarity, noOfSearchTerms)
#Formats the polarity to show to 2 decimal places
#positive = format(positive, '.2f')
#negative = format(negative, '.2f')
#neutral = format(neutral, '.2f')
print("How people are reacting on " + searchTerm + "by analyzing" + str(noOfSearchTerms) + " Tweets.")
if (polarity == 0 ):
print("Neutral")
elif (polarity < 0.00 ):
print("Negative")
elif (polarity > 0.00 ):
print("Postitive")
#Returns the polarity scores as JSON integers, for Android Studio
return json.dumps({"positive":positive,"negative":negative,"neutral":neutral})
SAapp.run()