def setUp(self): self.db_clients = [] configs = load_settings() for db_name in configs['dbs'].keys(): db_configs = configs['dbs'][db_name] test_db_name = 'test_%s' % db_configs['db'] self.db_clients.append(connect_db(db_configs['host'], db_configs['port'], test_db_name))
def test_load_settings(self): """Reads settings from a file.""" settings_yaml = settings.load_settings( filename=os.path.join(TEST_FILES, 'test_settings1.yaml')) expected_result = {'Setting': {'File': 'Test'}} self.assertEqual(settings_yaml, expected_result)
def __init__(self): super(TwitterFetcher, self).__init__() self.settings = load_settings() self.tw_client = twitter.Api( consumer_key=self.settings['twitter']['credentials'] ['consumer_key'], consumer_secret=self.settings['twitter']['credentials'] ['consumer_secret'], access_token_key=self.settings['twitter']['credentials'] ['access_token'], access_token_secret=self.settings['twitter']['credentials'] ['access_token_secret']) self.current_twitter_page = None
def _get_topics(self): settings = load_settings() return settings['topics']
def _get_sources(self): return ', '.join(load_settings()['news_api']['sources'])
def _get_api_token(self): return load_settings()['news_api']['api_token']
import csv from core.connect_db import connect_db from models.tweet import Tweet from models.twitter_user import TwitterUser from settings.settings import load_settings if __name__ == '__main__': settings = load_settings() mongo_config = settings['dbs']['mongo'] con = connect_db(**mongo_config) formed_tweets = [] twitter_users_mapping = { user.twitter_id: user.screen_name for user in TwitterUser.objects } for tweet in Tweet.objects: if tweet.twitter_user_id in twitter_users_mapping: tweet_author_name = twitter_users_mapping[tweet.twitter_user_id] else: tweet_author_name = 'UNKNOWN' formed_tweet_text = tweet.text for char in ['\n', '\r', '…']: formed_tweet_text.replace(char, '') formed_tweets.append( [formed_tweet_text, str(tweet.created_at), tweet_author_name])
def _connect_to_db(self): settings = load_settings() mongo_config = settings['dbs']['mongo'] con = connect_db(**mongo_config)