本文整理汇总了Python中models.Tweet类的典型用法代码示例。如果您正苦于以下问题:Python Tweet类的具体用法?Python Tweet怎么用?Python Tweet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tweet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: search_tweets
def search_tweets(search_query):
result = {}
json_data = raw_to_json(Tweet.search(search_query.replace("&", " ").split())[0])
result[search_query] = json_data
json_data = raw_to_json(Tweet.search(search_query.replace("&", " ").split())[1])
result[search_query+"_or"] = json_data
return jsonify(result)
开发者ID:tweetcity,项目名称:cs373-idb,代码行数:7,代码来源:__init__.py
示例2: get_context_data
def get_context_data(self, *args, **kwargs):
context = super(TestTweetsView, self).get_context_data(*args, **kwargs)
# retrieve tweets from db whose actual classifications have been set (already verified from previous tests)
tweets_train_tourism = Tweet.objects.filter(classified=True, actual_classification='tourism')
tweets_train_nontourism = Tweet.objects.filter(classified=True, actual_classification='nontourism')
# train classifier using tourism and nontourism files and tweets from db
train_result = train_db(tweets_train_tourism, tweets_train_nontourism)
classifier = train_result['classifier']
# retrieve random tweets from a file
tweets = self.randomize_tweets('classifier/data/2015-03-06.happydata.txt', 10)
tweets_test = []
for tweet in tweets:
if not Tweet.objects.filter(tweet_id=tweet['id']) and tweet['coordinates']:
tweet_id = tweet['id']
user = tweet['user']['name'].encode('utf-8')
lat = tweet['coordinates']['coordinates'][1]
lng = tweet['coordinates']['coordinates'][0]
text = tweet['text'].encode('utf-8')
if tweet_id and user and lat and lng and text:
# classify tweet
classification = classifier.classify(feature_extractor_lda_tripadvisor_top_words_weights(text))
# save tweet with classification (to be verified later)
tweet_obj = Tweet(tweet_id=tweet_id, user=user,
lat=lat, lng=lng, text=text,
classification=classification)
tweet_obj.save()
tweets_test.append(tweet_obj)
context['tweets'] = tweets_test
return context
开发者ID:jedijulia,项目名称:nlp-tourism,代码行数:33,代码来源:views.py
示例3: schedule
def schedule(request):
if request.POST.get('auth') != settings.TWITGHOST_AUTH_KEY:
logging.error("Unauthorized access")
return HttpResponse('forbidden', status=403)
new_tweet = Tweet(tweet=request.POST['tweet'])
new_tweet.save()
return HttpResponse('ok', mimetype="text/xml")
开发者ID:cgst,项目名称:twitghost,代码行数:7,代码来源:views.py
示例4: tweet
def tweet(request):
if request.method == 'POST':
form = TweetForm(request.POST)
if form.is_valid():
twit = Tweet()
status = twit.tweet = form.cleaned_data['tweet']
twit.name = request.user.username
twit.save()
variables = RequestContext(request,{
'status':status
})
return render_to_response('tweet.html',RequestContext(request),variables)
else:
return render_to_response('tweet.html',{'request':RequestContext(request)})
else:
tweets = []
queryset=Tweet.objects.all()
for query in queryset:
if request.user.username == query.name:
tweets.append(query)
status = ''
for tweet in tweets:
status = tweet.tweet
form = TweetForm()
form.name = request.user
variables = RequestContext(request, {
'form': form,'status': status
})
return render_to_response('tweet.html',RequestContext(request),variables)
开发者ID:Kanchu,项目名称:twitter,代码行数:33,代码来源:views.py
示例5: feed
def feed(request, username):
url = "https://twitrss.me/twitter_user_to_rss/?user=" + username
dicc = feedparser.parse(url)
out = ""
for number in range(5):
out += dicc.entries[number].title + "<br>"
#Obtener las urls del tweet si hay
urls = dicc.entries[number].title.split()
for i in urls:
if i.startswith("http://") or i.startswith("https://"):
i = i.split('&')[0]
out += "<li><a href=" + i + ">" + i + "</a></li>"
#Obtener primer elemento <p>
soup = BeautifulSoup(urllib.urlopen(i).read())
out += str(soup.p).decode('utf8')
#Obtener primer elemento <img>
out += str(soup.img).decode('utf8') + "<br><br>"
#Comprobar y guardar autor del tweet
user = dicc.entries[number].title.split(':')[0]
try:
p = User.objects.get(name=user)
except ObjectDoesNotExist:
p = User(name=user)
p.save()
#Comprobar y guardar tweet
try:
t = Tweet.objects.get(content=dicc.entries[number].title)
except ObjectDoesNotExist:
t = Tweet(content=dicc.entries[number].title, url= dicc.entries[number].link, name=p)
t.save()
return HttpResponse(out)
开发者ID:RebeccaSaez,项目名称:X-Serv-15.12-Django-feedexpander,代码行数:35,代码来源:views.py
示例6: do
def do(self):
logger.info("Initiating cronjob: {}".format(self.code))
try:
auth = tweepy.OAuthHandler(self._tak, self._tas)
auth.set_access_token(self._tat, self._tats)
api = tweepy.API(auth)
screen_name = api.me().screen_name
timeline = api.home_timeline()
except Exception:
e = traceback.format_exc()
logger.error("Could not get home timeline. Error: {}".format(self.screen_name, e))
return False
for t in timeline:
if t.user.screen_name == screen_name:
msg = t.text
if msg.startswith('RT @everycolorbot'):
chex = msg.split()[2].strip("\"")
evcinst = EveryColorBotTweet.objects.get_or_none(color__hex = chex)
if evcinst is not None:
evcinst.tweeted = True
evcinst.save()
inst = Tweet.objects.get_or_none(message = msg)
if inst is None:
logger.info('Cronjob encountered unsaved tweet: "{}" Saving it to database.'.format(msg))
inst = Tweet(color_code = chex, message = msg)
inst.save()
开发者ID:assamite,项目名称:TwatBot,代码行数:27,代码来源:cron.py
示例7: post
def post(self):
data = request.json
validation_error = validate_user(data)
if validation_error is not None:
return validation_error
user = get_user(data['user']['username'])
if user is None:
return jsonify(status=400, message="user does not exist")
if user.password != data['user']['password']:
return jsonify(status=403, message="incorrect password")
text = data['text']
if(len(text) > 140):
return jsonify(status=400, message="tweet too long"), 400
if(len(text) == 0):
return jsonify(status=400, message="empty tweet"), 400
for word in [u"#arsenal", u"#denfølelsen"]:
if word in text.lower():
abort(418) # I am a teapot
tweet = Tweet(user, text)
db['tweets'].append(tweet)
return jsonify(tweet.serialize()), 200
开发者ID:NinaMargrethe,项目名称:AngularJS-kurs,代码行数:27,代码来源:api.py
示例8: fromUser
def fromUser(self, screen_name, tweets_number=10, is_bot=False):
user = self.createUser(screen_name, is_bot)
tweets = self.twitter_client.user_timeline(screen_name=screen_name, count=tweets_number)
for i, status in enumerate(tweets):
tweet = status._json
text = tweet['text']
date = tweet['created_at']
entities = tweet['entities']
user_mentions = entities['user_mentions']
mentions_list = []
if len(user_mentions) > 0:
for mention in user_mentions:
mentions_list.append(mention['screen_name'])
text_string = unicodedata.normalize('NFKD', text).encode('ascii','ignore')
date_string = unicodedata.normalize('NFKD', date).encode('ascii','ignore')
name_mentions_string = ",".join(mentions_list)
Tweet.create(
user = user,
text = text_string,
date = date_string,
source = status.source,
mentions = name_mentions_string
)
开发者ID:AlexSoudant,项目名称:twitter-bot-detection,代码行数:27,代码来源:tweetimporter.py
示例9: get
def get(self):
self.response.write(self.request.get("keyword"))
# Prompt for login credentials and setup stream object
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
keyword = self.request.get("keyword")
count =0
search_results = api.search(q=keyword, result_type = "recent", count=100)
for tweet in search_results:
if tweet.place != None:
count+=1
tweet.text.replace("\n", " ");
text = tweet.text.encode('utf8')
print text
#logging.info(tweet.text)
latitude = tweet.place.bounding_box.coordinates[0][0][0]
longtitude = tweet.place.bounding_box.coordinates[0][0][1]
e = Tweet(search_key=keyword, text=tweet.text, latitude= latitude, longtitude= longtitude)
e.put()
开发者ID:ycc111,项目名称:TwittMap,代码行数:27,代码来源:twitter_api.py
示例10: search
def search(search_query):
search_query_strings = search_query.replace("&", " ").split()
json_data = {
"tweets" : raw_to_json(Tweet.search(search_query_strings)[0]),
"tweets_or": raw_to_json(Tweet.search(search_query_strings)[1]),
"hashtags" : raw_to_json(Hashtag.search(search_query_strings)[0]),
"hashtags_or": raw_to_json(Hashtag.search(search_query_strings)[1])
}
return jsonify(json_data)
开发者ID:tweetcity,项目名称:cs373-idb,代码行数:9,代码来源:__init__.py
示例11: buscar_en_todos_los_tweets
def buscar_en_todos_los_tweets(busqueda, cantidad_de_tweets=50, partir_del_tweet=None):
## App keys
APP_KEY = 'IR5sQyceHa34Cxxm2hAw'
APP_SECRET = 'y5Nti0zdCFfzY1ifokC6iHIZFZ14Z2GAjTI6VFx2mg'
## User keys
OAUTH_TOKEN = '202826188-6OCQEmzi7JCu8S6UERP5nhjUo4NHirk0Kd4VRRvl'
OAUTH_TOKEN_SECRET = '1wmkXUkqkDhBnbugzaNIzf07VKeCddjEPynVG2gayU'
# requires authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
search_results = twitter.search(q=busqueda, count=cantidad_de_tweets)
print '===============', busqueda, '==============='
except TwythonError as e:
print e
# Initialize array of tweet objects
tweets = []
for tweet in search_results['statuses']:
# Parameters of a tweet
tweet_id = tweet['id_str']
tweet_user = tweet['user']['screen_name'].encode('utf-8')
tweet_created_at = tweet['created_at']
tweet_text = tweet['text'].encode('utf-8')
tweet_reply_to_status_id = tweet['in_reply_to_user_id_str']
tweet_retweet_count = tweet['retweet_count']
try:
Tweet.objects.get(pk=tweet_id)
print "Tweet %s already in the db." % tweet_id
except:
# Print in console
print 'Added %s.- Tweet from @%s Date: %s' % (tweet_id, tweet_user, tweet_created_at)
print tweet_text, '\n', 'reply to %s' % tweet_reply_to_status_id
## Change twitter api time to python datetime
## ej. Wed Jan 16 22:08:18 +0000 2013
tweet_created_at = datetime.strptime(tweet_created_at, "%a %b %d %H:%M:%S +0000 %Y").replace(tzinfo=utc)
tmp_tweet = Tweet(id=tweet_id, user=tweet_user, text=tweet_text, created_at=tweet_created_at, retweet_count=tweet_retweet_count)
add_tweet_search = TwitterSearch(search=busqueda, tweet=tmp_tweet)
# extract, save and link hastags with tweet
extract_hash_tags(tmp_tweet)
# save newly created objects
tmp_tweet.save()
add_tweet_search.save()
## Tests are to be performed here
# buscar_en_todos_los_tweets('#uabc')
开发者ID:jimenezjrs,项目名称:hermes,代码行数:57,代码来源:recolector.py
示例12: on_success
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
开发者ID:kaflesudip,项目名称:TweetStats,代码行数:10,代码来源:get_tweets.py
示例13: save_raw
def save_raw(results: Generator) -> Generator:
"""Save the results and yields the id values
"""
for result in results:
id_str = result.__dict__.get('id_str')
data = result.__dict__.get('_json')
tweet = Tweet(id_str)
tweet.save(data)
yield id_str
开发者ID:markdessain,项目名称:tweet-analyser,代码行数:11,代码来源:twitter.py
示例14: tweets
def tweets(handle):
statuses = api.GetUserTimeline(screen_name=handle)
tweet_list = []
for s in statuses:
tweet = Tweet(id = s.id, text=s.text, retweet_count = s.retweet_count,
created_at = convert_datetime(s.created_at), influence_score=influence_score_calc(s.text),
picture = (None if s.media==[] else s.media[0].get("media_url", None)))
tweet_list.append(tweet)
return jsonify(tweets=[tweet.serialize() for tweet in tweet_list])
开发者ID:ydawant,项目名称:twitter_flask,代码行数:11,代码来源:api.py
示例15: tweet_add
def tweet_add():
user = current_user()
if user is None:
return redirect(url_for('login_view'))
else:
t = Tweet(request.form)
# 设置是谁发的
t.user = user
# 保存到数据库
t.save()
return redirect(url_for('timeline_view', username=user.username))
开发者ID:James-Lee-s,项目名称:lisen,代码行数:11,代码来源:app.py
示例16: post
def post(self, request, username):
form = TweetForm(self.request.POST)
if form.is_valid():
user = User.objects.get(username=username)
tweet = Tweet(text=form.cleaned_data['text'], user=user, country=form.cleaned_data['country'])
tweet.save()
words = form.cleaned_data['text'].split(" ")
for word in words:
if word[0] == "#": #Separamos todas las letras del tweet y si empieza con #, se va a crear un hashtag de esa palabra
hashtag, created = HashTag.objects.get_or_create(name=word[1:])
hashtag.tweet.add(tweet)
return HttpResponseRedirect('/user/' +username)
开发者ID:quinto7,项目名称:django_mytweets,代码行数:12,代码来源:views.py
示例17: post
def post(self):
if not self.has_permission:
return
user = self.current_user
content = self.get_argument('content', None)
image_ids = self.get_argument('image_ids', None)
images = []
if content and len(strip_tags(content)) >= 3:
tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
tweet.put_notifier()
if image_ids:
image_ids = image_ids.split(',')
for image_id in image_ids:
image_id = int(image_id)
image = Image.get(id=image_id)
if image:
image.tweet_id = tweet.id
images.append({
'id': image.id,
'path': image.path,
'width': image.width,
'height': image.height,
})
if images != []:
tweet.has_img = 'true'
result = {
'status' : 'success',
'message' : '推文创建成功',
'content' : tweet.content,
'name' : tweet.author.name,
'nickname' : tweet.author.nickname,
'author_avatar' : tweet.author.get_avatar(size=48),
'author_url' : tweet.author.url,
'author_name' : tweet.author.name,
'author_nickname' : tweet.author.nickname,
'tweet_url' : tweet.url,
'created' : tweet.created,
'id' : tweet.id,
'images' : images,
}
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect('/timeline')
result = {
'status': 'error',
'message': '推文内容至少 3 字符'
}
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect('/timeline')
开发者ID:Quasimo,项目名称:collipa,代码行数:52,代码来源:tweet.py
示例18: post
def post(self, request, username):
form = TweetForm(self.request.POST)
if form.is_valid():
user = User.objects.get(username = username)
tweet = Tweet(text = form.cleaned_data['text'], user = user,
country = "Vietname" )#form.cleaned_data['country'])
tweet.save()
words = form.cleaned_data['text'].split(" ")
for word in words:
hashtag, created = HashTag.objects.get_or_create(name = word[1:])
hashtag.tweet.add(tweet)
return HttpResponseRedirect('/tweets/user/%s' % username)
return redirect(Profile.as_view())
开发者ID:enixdark,项目名称:django-rest-pratices,代码行数:13,代码来源:views.py
示例19: GetPastTweets
def GetPastTweets(app, searchStrings):
with app.app_context():
auth = OAuthHandler( current_app.config['TWITTER_CONSUMER_KEY'], current_app.config['TWITTER_CONSUMER_SECRET'])
auth.set_access_token(current_app.config['TWITTER_ACCESS_TOKEN'], current_app.config['TWITTER_ACCESS_TOKEN_SECRET'])
api = API(auth)
deleteEntries = connect(current_app.config['MONGODB_SETTINGS']['DB'])
deleteEntries.drop_database(current_app.config['MONGODB_SETTINGS']['DB'])
listTweetIDs = []
user_query = session['userSentence']
session['completeTweetFetch'] = False
session['completedMetaModel'] = False
for searchString in searchStrings:
# Sleep for 28 secs to avoid Twitter download rate restrictions
searchTweets = [status for status in Cursor(api.search, q=searchString).items(current_app.config['MAX_FETCH_TWEETS'])]
for tweet in searchTweets:
tweet_id = tweet.id
if listTweetIDs.__contains__(tweet_id):
continue
if len(Tweet.objects(tweet_id=tweet_id)) > 1:
continue
tweet_message = tweet.text.encode("utf-8")
tweet_userhandle = tweet.user.screen_name
tweet_retweet_count = tweet.retweet_count
tweet_createtime = tweet.created_at
tweet_location = None
tweet_geo = None
tweet_favoritecount = tweet.favorite_count
tweet_username = tweet.user.name
tweet_user_no_of_following = tweet.user.friends_count
tweet_user_no_of_followers = tweet.user.followers_count
tweet_positiveOrnegative = 0
tweet_polarOrneutral = 0
tweet_isRetweet = 0
oneTweet = Tweet(tweet_id=tweet_id, tweet_msg=tweet_message, tweet_likes=tweet_favoritecount, tweet_retweets=tweet_retweet_count, tweet_search_category=searchString, tweet_user_search_query=user_query, tweet_positiveOrnegative=tweet_positiveOrnegative, tweet_polarOrneutral=tweet_polarOrneutral, tweet_user_handle=tweet_userhandle, tweet_user_name=tweet_username, tweet_user_followers=tweet_user_no_of_followers, tweet_user_following=tweet_user_no_of_following, tweet_isretweet=tweet_isRetweet, tweet_time=tweet_createtime, tweet_location=tweet_location, tweet_geo=tweet_geo)
oneTweet.save()
listTweetIDs.append(tweet_id)
if session['metamodelThread'] is None:
session['metamodelThread'] = thread.start_new_thread(twittermetamodelBuilding, ())
print 'completed tweet fetch'
session['completeTweetFetch'] = True
pass
开发者ID:harsha-kadekar,项目名称:Chitralochana,代码行数:51,代码来源:DataDownloader.py
示例20: search_anime_tweet
def search_anime_tweet(search_query):
import requests
anime_json = requests.get("http://animedb.me/search/"+search_query).json()["searchResults"]
result = []
for anime in anime_json:
anime_result = {"title" : anime["title"], "id" : anime["id"]}
if all([x in anime["title"].lower() for x in search_query.replace("&", " ").split()]):
json_data = raw_to_json(Tweet.search(search_query.replace("&", " ").split())[0])
anime_result['tweets'] = json_data
json_data = raw_to_json(Tweet.search(search_query.replace("&", " ").split())[1])
anime_result['tweets_or'] = json_data
if "tweets" in anime_result or "tweets_or" in anime_result:
result.append(anime_result);
return json.dumps(result, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ': '))
开发者ID:tweetcity,项目名称:cs373-idb,代码行数:14,代码来源:__init__.py
注:本文中的models.Tweet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论