本文整理汇总了Python中models.Tweet.text方法的典型用法代码示例。如果您正苦于以下问题:Python Tweet.text方法的具体用法?Python Tweet.text怎么用?Python Tweet.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tweet
的用法示例。
在下文中一共展示了Tweet.text方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tweet
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import text [as 别名]
def tweet(self, include, reply, data):
tweet=data.get("text", "")
log.info("In tweet(), ")
h = data.get('handler', None)
wrap = TW_API.get(h, None)
try:
if include:
inObj = Includable(include)
tweet = tweet+" "+str(inObj)
if reply:
q=reply.get('topic', None)
sr_list=SearchResult.objects.filter(query=q, autoPostStatus=None)[:1]
log.info("length sr_list: "+str(sr_list))
if len(sr_list)<1:
search = Searching()
search.search(data.get('handler'), reply.get('topic'))
log.info("reply input: "+str(reply))
r = Reply(reply)
tweetId = r.getTweetId()
screenName = r.getScreenName()
tweet=wrap.replyTweet(tweet, screenName, tweetId)
reply={"screenName": screenName, "tweetId": tweetId}
else:
log.info("about to post a tweet...")
try:
wrap.postTweet(tweet)
except Exception as e:
log.info("error in posting tweet, "+str(e))
log.info(("came here"))
tw = Tweet()
secret = TwitterSecret.objects.get(handler=h)
tw.handler=secret
tw.state="updated"
tw.uuid= uuid.uuid4()
tw.text=tweet
tw.save()
except Exception as e:
log.info("An err while posting tweet"+str(e))
return Response({'tweet':tweet, "reply":reply})
示例2: get_tweets_data_for_hash_tag_from_twitter
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import text [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
示例3: update_tweets
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import text [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()
示例4: import_tweets
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import text [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())
示例5: storeTimeline
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import text [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
示例6: get_tweets
# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import text [as 别名]
def get_tweets(request):
consumer_key = keys.CONSUMER_KEY
consumer_secret = keys.CONSUMER_SECRET
access_token = keys.ACCESS_TOKEN
access_token_secret = keys.ACCESS_TOKEN_SECRET
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
coxinha_words = ['AvanteTemer', 'ForaDilma', 'petralha', 'ForaLula', 'TchauQuerida', 'Petista', 'Esquerdista']
petralha_words = ['NãoVaiTerGolpe', 'ForaTemer', 'GloboGolpista', 'DilmaFica', 'FicaDilma', 'TemerJamais', 'VoltaDilma', 'VaiTerLuta', 'Golpista']
#potential_words = ['Dilma', 'Lula', 'Temer', 'Cunha', 'Aécio', 'Moro', 'Golpe', 'Oposição', 'Impeachment', 'governo', 'democracia', 'político', 'política', 'operação', 'Corrupção', 'Corrupto', 'Jucá', 'cpiminc', 'Esquerda', 'Sarney']
#potential_words = ['Comunista', 'Comuna', 'esquerdopata', 'Jucá', 'Direita', 'Ministro']
#potential_words = ['Petralhas', 'PassaDilma', 'Protesto', 'Protestos', 'Ministros']
# is_Petralha = False
# for query in coxinha_words:
# for status in tweepy.Cursor(api.search, q=query + '&place:d9d978b087a92583').items():
#
# if status.geo != None:
# print "Tweet:", status.text.encode('utf8')
# print "Geo:", status.geo['coordinates']
# print "//////////////////"
# try:
# tweet = Tweet()
# tweet.is_Petralha = is_Petralha
# tweet.text = status.text.encode('utf-8')
# tweet.lat = status.geo['coordinates'][0]
# tweet.lng = status.geo['coordinates'][1]
# tweet.save()
# print "ADDED"
# except IntegrityError as e:
# print e.message
#
is_Petralha = True
for query in petralha_words:
for status in tweepy.Cursor(api.search, q=query + '&place:d9d978b087a92583').items():
if status.geo != None:
print "Tweet:", status.text.encode('utf8')
print "Geo:", status.geo['coordinates']
print "//////////////////"
try:
tweet = Tweet()
tweet.is_Petralha = is_Petralha
tweet.text = status.text.encode('utf-8')
tweet.lat = status.geo['coordinates'][0]
tweet.lng = status.geo['coordinates'][1]
tweet.save()
print "ADDED"
except IntegrityError as e:
print e.message
#
# for query in potential_words:
# for status in tweepy.Cursor(api.search, q=query + '&place:d9d978b087a92583').items():
#
# if status.geo != None:
# print "Tweet:", status.text.encode('utf8')
# print "Geo:", status.geo['coordinates']
# print "//////////////////"
# try:
# tweet = Tweets();
# tweet.text = status.text.encode('utf-8')
# tweet.lat = status.geo['coordinates'][0]
# tweet.lng = status.geo['coordinates'][1]
# tweet.save()
# print "ADDED POTENTIAL"
# except IntegrityError as e:
# print e.message
print "That's end"
return render(request, 'coxinhaoupetralha/index.html', {})