本文整理汇总了Python中models.Tweet.created_at方法的典型用法代码示例。如果您正苦于以下问题:Python Tweet.created_at方法的具体用法?Python Tweet.created_at怎么用?Python Tweet.created_at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tweet
的用法示例。
在下文中一共展示了Tweet.created_at方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tweets_data_for_hash_tag_from_twitter
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import created_at [as 别名]
def get_tweets_data_for_hash_tag_from_twitter(hash_tag):
"""
Get tweets by hash tag data from twitter
:param hash_tag:
:return:
"""
hash_tag = HashTag.objects.get(hash_tag=hash_tag)
tweets = []
new_tweets = 0
tweet_objs = []
base_url = 'https://api.twitter.com/1.1/search/tweets.json'
next_url = '?q=%23'+ hash_tag.hash_tag + '&lang=en'
logger.info("Getting Tweet data for hashtag: %s" % hash_tag.hash_tag)
while next_url:
url = base_url + next_url
page_data = client.request(url)
tweets += page_data.get('statuses')
next_url = page_data.get('search_metadata').get('next_results')
for tweet in tweets:
try:
tweet_obj = Tweet.objects.get(id_str=tweet.get('id_str'))
except ObjectDoesNotExist:
tweet_obj = Tweet()
tweet_obj.id_str = tweet.get('id_str')
tweet_obj.created_at = dateutil.parser.parse((tweet.get('created_at')))
tweet_obj.text = tweet.get('text')
tweet_obj.hash_tag = hash_tag
# get the tweet typos
get_tweet_typos(tweet_obj)
tweet_obj.save()
new_tweets += 1
tweet_objs.append(tweet_obj)
logger.info("Found %s tweets for hashtag: %s" % (len(tweet_objs), hash_tag.hash_tag))
logger.info("Found %s new tweets for hashtag: %s" % (str(new_tweets), hash_tag.hash_tag))
return tweet_objs
示例2: update_tweets
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import created_at [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 created_at [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 created_at [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