本文整理汇总了Python中models.Tweet.tweet_id方法的典型用法代码示例。如果您正苦于以下问题:Python Tweet.tweet_id方法的具体用法?Python Tweet.tweet_id怎么用?Python Tweet.tweet_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tweet
的用法示例。
在下文中一共展示了Tweet.tweet_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_success
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import tweet_id [as 别名]
def on_success(self, data):
if 'text' in data:
data['fetched_timestamp'] = datetime.datetime.now()
data['fresh_tweet'] = True
tweet = Tweet()
tweet.tweet_id = data['id_str']
tweet.tweets.append(data)
tweet.save()
print("saved", self.i)
self.i += 1
示例2: update_tweets
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import tweet_id [as 别名]
def update_tweets(request):
twitter_auth = request.user.social_auth.filter(provider='twitter')[0]
oauth_token = twitter_auth.tokens['oauth_token']
oauth_secret = twitter_auth.tokens['oauth_token_secret']
twitter = Twython(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET, oauth_token, oauth_secret)
tweets = twitter.get_home_timeline(count=200)
for tweet in tweets:
if len(tweet['entities']['urls']) != 0:
if not (Tweet.objects.filter(tweet_id=tweet['id'], user=request.user)):
tweet_object = Tweet()
tweet_object.tweet_id = tweet['id']
tweet_object.text = tweet['text']
tweet_object.source_url = tweet['entities']['urls'][0]['expanded_url']
tweet_object.display_url = tweet['entities']['urls'][0]['display_url']
tweet_object.host_url = urlparse.urlparse(tweet['entities']['urls'][0]['expanded_url']).hostname
tweet_object.created_at = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(tweet['created_at'],'%a %b %d %H:%M:%S +0000 %Y'))
tweet_object.tweeted_by = tweet['user']['screen_name']
tweet_object.user = request.user
tweet_object.save()
示例3: import_tweets
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import tweet_id [as 别名]
def import_tweets(request):
consumer = oauth.Consumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
token = oauth.Token(settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_TOKEN_SECRET)
client = oauth.Client(consumer, token)
# GET YOUR PROFILE
response, content = client.request('https://api.twitter.com/1/statuses/user_timeline.json', 'GET')
tweets = []
if response.status == 200:
tweets = simplejson.loads(content)
for tweet in tweets:
if Tweet.objects.filter(tweet_id=long(tweet['id'])).count() < 1:
db_tweet = Tweet()
db_tweet.text = tweet['text']
db_tweet.created_at = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(tweet['created_at'],'%a %b %d %H:%M:%S +0000 %Y'))
db_tweet.tweet_id = tweet['id']
db_tweet.save()
# put the logging stuff here
return render_to_response('templates/import_tweets.html', locals())
示例4: storeTimeline
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import tweet_id [as 别名]
def storeTimeline():
while 1:
try:
logger.info("Starting to store timeline data (pid %s)" % os.getpid())
twitter_stream = TwitterStream(domain="userstream.twitter.com")
db.init_db()
for msg in twitter_stream.stream.user(following=True):
if msg.get("text"):
tweet = Tweet()
tweet.text = msg["text"].encode("utf-8")
tweet.created_at = parser.parse(msg["created_at"]).replace(tzinfo=None)
if msg.get("coordinates"):
tweet.lon = msg["coordinates"]["coordinates"][0]
tweet.lat = msg["coordinates"]["coordinates"][1]
tweet.tweet_id = msg["id"]
tweet.retweet_count = msg["retweet_count"]
tweet.user_id = msg["user"]["id"]
db.session.add(tweet)
db.session.commit()
logger.error("Stream timeout or other cause for shutdown")
except Exception, err:
logger.error("%s, %s" % (Exception, err))
raise