Почему я получаю эту ошибку при попытке запустить погодный бот в Твиттере?Python

Программы на Python
Ответить
Anonymous
 Почему я получаю эту ошибку при попытке запустить погодный бот в Твиттере?

Сообщение Anonymous »

Код: Выделить всё

def reply_to_tweet():
print("retrieving and replying to tweets...")
last_seen_tweet = read_last_seen(FILE_NAME)
# mentions_timeline() returns a list of 20 most recent mentions
mentions = api.mentions_timeline(last_seen_tweet, tweet_mode="extended")

# reversing to read old tweets first
for mention in reversed(mentions):
print(str(mention.id) + " - " + mention.full_text)
last_seen_tweet = mention.id
store_last_seen(FILE_NAME, last_seen_tweet)
if "#" in mention.full_text.lower():
print("found #")

location = get_location(mention.full_text)
weather = get_weather(location)

# responding to tweet mention
api.update_status("@" + mention.user.screen_name + weather, mention.id)

def get_location(tweet):
# takes tweet and returns only the substring attached to hashtag
tweet_location = [i.strip("#") for i in tweet.split() if i.startswith("#")[0]]
tweet_location += " today weather.com"
return tweet_location

def get_weather(query):
for url in search(query, stop=1):
print("Results is " + url)

#this code sends a request and reads the webpage enclsed to the request
request = Request(url, headers={"User-Agent": "Mozilla/5.0"})

webpage = urlopen(request).read()
soup = BeautifulSoup(webpage, "html.parser")

try:
title = soup.findAll("span", "today-daypart-title")[0].string
phrase = soup.findAll("span", "today-daypart-wxphrase")[0].string
except IndexError as e:
forecast = (" could not find the weather, check back later")
print(e)
else:
forecast = (" forecast for " + title + " is " + phrase)
print(forecast)

return forecast

while True:
reply_to_tweet()
time.sleep(15)
Затем я вызываю ответ_to_tweet(), он ищет и отображает твит, но когда он пытается найти местоположение, я получаю:
TypeError: объект 'bool' не подлежит подписке
Я новичок в ботах и ​​API, я использую BeautifulSoup, googlesearch и tweepy

Подробнее здесь: https://stackoverflow.com/questions/672 ... eather-bot
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»