我想要Telegram的Twitter转发器。
我找到了这个:https://github.com/franciscod/telegram-twitter-forwarder-bot
现在的问题是,如果推文在链接之前包含主题标签,Telegram会向我显示指向主题标签的链接。
我尝试了不同的东西并搜索了一下,但我不知道如何只接收来自twitter的纯文本。
如果推文很长,我也不会得到短链接。这只是一个很长的链接。
for tweet in tweets:
self.logger.debug("- Got tweet: {}".format(tweet.text))
# Check if tweet contains media, else check if it contains a link to an image
extensions = ('.jpg', '.jpeg', '.png', '.gif')
pattern = '[(%s)]$' % ')('.join(extensions)
photo_url = ''
tweet_text = html.unescape(tweet.text)
if 'media' in tweet.entities:
photo_url = tweet.entities['media'][0]['media_url_https']
else:
for url_entity in tweet.entities['urls']:
expanded_url = url_entity['expanded_url']
if re.search(pattern, expanded_url):
photo_url = expanded_url
break
if photo_url:
self.logger.debug("- - Found media URL in tweet: " + photo_url)
for url_entity in tweet.entities['urls']:
expanded_url = url_entity['expanded_url']
indices = url_entity['indices']
display_url = tweet.text[indices[0]:indices[1]]
tweet_text = tweet_text.replace(display_url, expanded_url)
tw_data = {
'tw_id': tweet.id,
'text': tweet_text,
'created_at': tweet.created_at,
'twitter_user': tw_user,
'photo_url': photo_url,
}
try:
t = Tweet.get(Tweet.tw_id == tweet.id)
self.logger.warning("Got duplicated tw_id on this tweet:")
self.logger.warning(str(tw_data))
except Tweet.DoesNotExist:
tweet_rows.append(tw_data)
if len(tweet_rows) >= self.TWEET_BATCH_INSERT_COUNT:
Tweet.insert_many(tweet_rows).execute()
tweet_rows = []
答案 0 :(得分:0)
只需停用markdown_twitter_hashtags()功能,让它返回from selenium.webdriver.support import expected_conditions as EC
#code block
self.chrome_session.find_element_by_xpath("//input[@value='Accept']").click()
WebDriverWait(self.chrome_session, 10).until(EC.alert_is_present)
self.chrome_session.switch_to().alert().accept()
print("Accepted work order {0} at {1}.".format(link_text, datetime.datetime.now()))
而不替换它。