我试图建立一个基本的twitter新闻机器人,我想知道为什么这段代码不会运行:
import tweepy
import feedparser
# Set up Twitter API keys and access tokens
consumer_key = "YOUR_CONSUMER_KEY"
consumer_secret = "YOUR_CONSUMER_SECRET"
access_token = "YOUR_ACCESS_TOKEN"
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"
# Authenticate with Twitter API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Define function to post tweets
def post_tweet(title, url):
tweet = f"{title}\n{url}"
api.update_status(tweet)
# Get Bitcoin-related news from Coindesk RSS feed
rss_url = "https://www.coindesk.com/feed"
feed = feedparser.parse(rss_url)
# Filter news articles related to Bitcoin
bitcoin_articles = [entry for entry in feed.entries if "bitcoin" in entry.title.lower()]
# Post the selected articles to Twitter
for article in bitcoin_articles:
post_tweet(article.title, article.link)
我已经添加了正确的密钥和令牌。终端没有错误,什么都没有发生。
我尝试重新安装依赖项并重新确认密钥和令牌是正确的,但仍然一无所获。
1条答案
按热度按时间6kkfgxo01#
您正在使用重定向到其他URL的URL(解析器无法处理重定向)。以下代码打印:
输出(只有2个条目,因为太多):