Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initial = tweet[RT][u'user'][u'screen_name']
fmt_text = fmt % (initial, user)
fmt_html = fmt % (user_url(initial), user_url(user))
text = tweet[RT]['text']
elif REPLY_NAME in tweet and tweet[REPLY_NAME] is not None and tweet[REPLY_TWEET] is not None:
fmt = u'Tweet de %s en réponse à %s : '
url_text = '%s/%s/status/%s' % (URL, tweet[REPLY_NAME], tweet[REPLY_TWEET])
url_html = '<a href="%s">%s</a>' % (url_text, tweet[REPLY_NAME])
fmt_text = fmt % (user, url_text)
fmt_html = fmt % (user_url(user), url_html)
else:
fmt = u'Tweet de %s : '
fmt_text = fmt % user
fmt_html = fmt % user_url(user)
self.bot.say({'text': fmt_text + unescape(text),
'xhtml': fmt_html + Twython.html_for_tweet(tweet)})
tweets.add(tweet['id'])
if timeline:
last_tweet.last = timeline[0]['id']
for tweet in tweets:
self.bot.session.merge(Tweets(id=tweet))
self.bot.session.commit()
print deleted_status['id_str'] + ' not found in db'
else:
tweet = json.loads(row[0])
if 'retweeted_status' not in tweet:
elapsed = (int(data['delete']['timestamp_ms']) - int(tweet['timestamp_ms'])) / 1000
status = 'deleted after ' + nice_interval(elapsed)
if len(tweet['entities']['urls']) > 0:
status += "\nlinks in original tweet:"
for url in tweet['entities']['urls']:
status += ' ' + url['expanded_url']
image_path = tweetcap(\
template_path,\
tweet['user']['name'],\
tweet['user']['screen_name'],\
tweet['user']['profile_image_url'],\
Twython.html_for_tweet(tweet),\
datetime.fromtimestamp(int(tweet['timestamp_ms']) / 1000).replace(tzinfo=dateutil.tz.tzutc()))
image = open(image_path, 'rb')
media_id = rest.upload_media(media=image)['media_id']
rest.update_status(status=status, media_ids=[media_id])
image.close()
os.remove(image_path)
* Replaces t.co URLs with clickable, full links.
"""
# Temporary, until Twython.html_for_tweet() can handle tweets with
# 'full_text' attributes.
if 'full_text' in json_data:
json_data['text'] = json_data['full_text']
# Some Tweets (eg from a downloaded archive) don't have entities['symbols']
# which Twython.html_for_tweet() currently expects.
if 'entities' in json_data and 'symbols' not in json_data['entities']:
json_data['entities']['symbols'] = []
# This does most of the work for us:
# https://twython.readthedocs.org/en/latest/usage/special_functions.html#html-for-tweet
html = Twython.html_for_tweet(
json_data, use_display_url=True, use_expanded_url=False)
# Need to do some tidying up:
try:
ents = json_data['entities']
except KeyError:
ents = {}
urls_count = len(ents['urls']) if 'urls' in ents else 0
media_count = len(ents['media']) if 'media' in ents else 0
hashtags_count = len(ents['hashtags']) if 'hashtags' in ents else 0
symbols_count = len(ents['symbols']) if 'symbols' in ents else 0
user_mentions_count = len(ents['user_mentions']) if 'user_mentions' in ents else 0
# Replace the classes Twython adds with rel="external".