本文整理汇总了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):