本文整理汇总了Python中models.Tweet.get方法的典型用法代码示例。如果您正苦于以下问题:Python Tweet.get方法的具体用法?Python Tweet.get怎么用?Python Tweet.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tweet
的用法示例。
在下文中一共展示了Tweet.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import get [as 别名]
def put(self, tweet_id):
tweet_id = int(tweet_id)
tweet = Tweet.get(id=tweet_id)
if not tweet:
raise tornado.web.HTTPError(404)
action = self.get_argument('action', None)
user = self.current_user
if not action:
result = {'status': 'error', 'message':
'缺少参数'}
return self.send_result(result)
if action == 'up':
if tweet.user_id != user.id:
result = user.up(tweet_id=tweet.id)
else:
result = {'status': 'info', 'message':
'不能为自己的推文投票'}
if action == 'down':
if tweet.user_id != user.id:
result = user.down(tweet_id=tweet.id)
else:
result = {'status': 'info', 'message':
'不能为自己的推文投票'}
if action == 'collect':
result = user.collect(tweet_id=tweet.id)
if action == 'thank':
result = user.thank(tweet_id=tweet.id)
if action == 'report':
result = user.report(tweet_id=tweet.id)
return self.send_result(result)
示例2: put
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import get [as 别名]
def put(self, tweet_id):
tweet_id = int(tweet_id)
tweet = Tweet.get(id=tweet_id)
if not tweet:
raise tornado.web.HTTPError(404)
action = self.get_argument('action', None)
user = self.current_user
if action and user:
if action == 'up':
if tweet.user_id != user.id:
result = user.up(tweet_id=tweet.id)
else:
result = {'status': 'info', 'message':
'不能为自己的推文投票'}
if action == 'down':
if tweet.user_id != user.id:
result = user.down(tweet_id=tweet.id)
else:
result = {'status': 'info', 'message':
'不能为自己的推文投票'}
if action == 'collect':
result = user.collect(tweet_id=tweet.id)
if action == 'thank':
result = user.thank(tweet_id=tweet.id)
if action == 'report':
result = user.report(tweet_id=tweet.id)
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect_next_url()
示例3: delete
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import get [as 别名]
def delete(self, tweet_id):
if not self.current_user.is_admin:
return self.redirect_next_url()
tweet = Tweet.get(id=tweet_id)
if not tweet:
return self.redirect_next_url()
tweet.remove()
result = {'status': 'success', 'message': '已成功删除'}
return self.send_result(result)
示例4: get
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import get [as 别名]
def get(self, tweet_id):
tweet_id = int(tweet_id)
tweet = Tweet.get(id=tweet_id)
if not tweet:
raise tornado.web.HTTPError(404)
return self.render("tweet/index.html", tweet=tweet)
示例5: run
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import get [as 别名]
def run(self, bot):
self.logger.debug("Fetching tweets...")
tweet_rows = []
# fetch the tw users' tweets
tw_users = list((TwitterUser.select()
.join(Subscription)
.group_by(TwitterUser)
.order_by(TwitterUser.last_fetched)))
updated_tw_users = []
users_to_cleanup = []
for tw_user in tw_users:
try:
if tw_user.last_tweet_id == 0:
# get just the latest tweet
self.logger.debug(
"Fetching latest tweet by {}".format(tw_user.screen_name))
tweets = bot.tw.user_timeline(
screen_name=tw_user.screen_name,
count=1)
else:
# get the fresh tweets
self.logger.debug(
"Fetching new tweets from {}".format(tw_user.screen_name))
tweets = bot.tw.user_timeline(
screen_name=tw_user.screen_name,
since_id=tw_user.last_tweet_id)
updated_tw_users.append(tw_user)
except tweepy.error.TweepError as e:
sc = e.response.status_code
if sc == 429:
self.logger.debug("- Hit ratelimit, breaking.")
break
if sc == 401:
users_to_cleanup.append((tw_user, 'PROTECTED'))
self.logger.debug("- Protected tweets here. Cleaning up this user")
continue
if sc == 404:
users_to_cleanup.append((tw_user, 'NOTFOUND'))
self.logger.debug("- 404? Maybe screen name changed? Cleaning up this user")
continue
self.logger.debug(
"- Unknown exception, Status code {}".format(sc))
continue
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 = []
TwitterUser.update(last_fetched=datetime.now()) \
.where(TwitterUser.id << [tw.id for tw in updated_tw_users]).execute()
if not updated_tw_users:
return
if tweet_rows:
Tweet.insert_many(tweet_rows).execute()
#.........这里部分代码省略.........