class TestConfig(TestCase): def __init__(self, *args, **kwargs): super(TestConfig, self).__init__(*args, **kwargs) self.conf = AppConf() def test_test_mode(self): self.assertTrue(os.environ.get("TEST_MODE")) db_path = self.conf.get("SQL", "dbPath") self.assertTrue(db_path.endswith("test_db.sqlite")) def test_check_paths(self): self.conf.check_paths() def test_staging_dir(self): self.conf.stagingCSVs() def test_read_values(self): """ Do no validation, just check the section and field can be read. """ self.conf.get("TwitterAuth", "consumerKey") self.conf.get("TwitterAuth", "consumerSecret") self.conf.get("TwitterAuth", "accessKey") self.conf.get("TwitterAuth", "accessSecret")
# Allow imports to be done when executing this file directly. sys.path.insert( 0, os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir) ), ) from lib import database as db from lib.config import AppConf from lib.tweets import insertOrUpdateTweetBatch from lib.db_query.tweets.categories import printAvailableCategories conf = AppConf() UTILITY_CAMPAIGN = conf.get("Labels", "fetchTweets") def main(): """ Command-line interface to fetch Tweet data for Profile Categories. """ parser = argparse.ArgumentParser( description="""Fetch Tweets for Profiles utility. Filter Profiles in the DB using a Category input, update them with new data and insert or update the most recent Tweets for each. Tweets are assigned to the '{0}' Campaign.""".format( UTILITY_CAMPAIGN ) )
) import lib import lib.text_handling import lib.twitter_api.authentication import lib.twitter_api.search import lib.tweets from lib import database as db from lib.config import AppConf from lib.db_query.tweets.campaigns import ( printAvailableCampaigns, printCampaignsAndTweets, ) from models import Campaign conf = AppConf() UTILITY_CATEGORY = UTILITY_CAMPAIGN = conf.get("Labels", "search") # Create initial global API connection object, which needs to be set. API_CONN = None def search(query, pageCount=1, extended=True): """ Do a Search API query for one or more pages of tweets matching the query. After every 100 or slightly fewer tweets, a new request will be done to get the next page. :param query: Query text to search on the Twitter API. :param pageCount: Count pages of tweets to fetch. Each page contains 100 tweets, which is the Search API's limit.
import sys # Allow imports to be done when executing this file directly. sys.path.insert( 0, os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)), ) from lib import database as db from lib.config import AppConf from lib.tweets import insertOrUpdateProfileBatch, assignProfileCategory from lib.db_query.tweets.categories import printAvailableCategories conf = AppConf() UTILITY_CATEGORY = conf.get("Labels", "fetchProfiles") INFLUENCER_CATEGORY = conf.get("Labels", "influencers") def main(): """ Command-line tool to add or update Profile records from list of Twitter screen names. Expects a list screen names, either from arguments list or to be read from a specified text file. If custom Category is provided, then assign to the Profiles. :return: None """ parser = argparse.ArgumentParser(description="""Fetch Profiles Utility.
import csv import sys import os sys.path.insert( 0, os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)), ) from lib import database as db from lib.config import AppConf conf = AppConf() REPORT_DIR = conf.get("Reporting", "reportingDir") # TODO: Refactor to be in lib dir. def write_csv(path, rows, append=False): """ Write a CSV file to a path with given rows and header from first row. Default behavior is to overwrite an existing file. Append to existing file if append is flag True. Either way, the header will only be added on a new file. Appending is useful when adding sections to a report, but overwriting is better when rerunning an entire report. """ if not rows: print("No rows to write") print()