本文整理匯總了Python中DBManager.DBManager.get_new_model_instance方法的典型用法代碼示例。如果您正苦於以下問題:Python DBManager.get_new_model_instance方法的具體用法?Python DBManager.get_new_model_instance怎麽用?Python DBManager.get_new_model_instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DBManager.DBManager
的用法示例。
在下文中一共展示了DBManager.get_new_model_instance方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from DBManager import DBManager [as 別名]
# 或者: from DBManager.DBManager import get_new_model_instance [as 別名]
#.........這裏部分代碼省略.........
"""
tweets_results = []
twitter_manager = TwitterManager()
chunks_of_tweets_ids = self.__helper.get_chunks_of_list(tweet_ids, self.__max_num_of_tweets_at_once)
for chunk in chunks_of_tweets_ids:
print("Searching for "+str(len(chunk))+" tweets.")
result = twitter_manager.lookup(chunk)
print("Found "+str(len(result))+" tweets.")
tweets_results+=result
return tweets_results
def _get_tweets_ids(self, tweets_with_classes):
"""
Extracts tweet ids from tweets with classes
:param tweets_with_classes: List, tweet_with classes
:return: extracted ids
"""
ids = [x[0] for x in tweets_with_classes]
return ids
def _create_tweet_objects(self, all_tweets):
"""
Creates a list which holds db model objects.
:param tweet_info: List, tweets
:return: List, tweet objects
"""
all_tweet_objects = []
for tweet in all_tweets:
tweet_object = self.__db_manager.get_new_model_instance()
tweet_object.id = tweet.id_str
tweet_object.created_at = tweet.created_at
tweet_object.lang = tweet.lang
tweet_object.source = tweet.source
tweet_object.user_id = tweet.user.id_str
tweet_object.text = self.__preprocess_manager.clean_emojis_and_smileys(tweet.text).encode('utf-8')
tweet_object.tweet_class = self._get_sentiment_class_of_tweet(tweet.id_str)
all_tweet_objects.append(tweet_object)
return all_tweet_objects
def _get_sentiment_class_of_tweet(self, tweet_id):
"""
Returns a sentiment class for given tweet id
:param tweet_id: string
:return: tweet class
"""
return self.__tweets_classes_dictionary[tweet_id]
def _find_not_found_tweets_on_twitter(self, twitter_response):
"""
Finds not found tweets on Twitter API
:param twitter_response: list, Twitter response
:return: list, not found tweets
"""
tweets_ids = self._get_tweets_ids(self.__tweets_with_classes)
response_ids = [a_tweet_response.id_str for a_tweet_response in twitter_response]
return list(set(tweets_ids) - set(response_ids))
def import_new_tweets_from_csv(self, root_path):