Beispiel #1
0
 def __init__(self, config_type, config_filename):
     if not Helper.is_string(config_filename):
         raise AvivoreConfigException('Invalid config file specified!')
     self.config_type = config_type
     self.config_filename = config_filename
     self.config = ConfigParser()
     self.twitter_search_types = []
     self.twitter_search_terms = []
     self.twitter_track_keywords = None
     self.twitter_consumer_key = None
     self.twitter_consumer_secret = None
     self.twitter_search_interval = 30
     self.credentials_file = None
     self.database_path = None
     self.mandatory_options = [
         # Be sure to keep order of database table layout for options from 'config' database
         # append type definitions for twitter_search_objects!
         ('database', 'dbpath'),
         ('twitter_auth', 'consumer_key'),
         ('twitter_auth', 'consumer_secret'),
         ('twitter_auth', 'credentials_file'),
         ('twitter_search', 'stream_tracking_keyword'),
         ('twitter_search', 'csv_search_term'),
         ('twitter_search_objects', '0'),
     ]
Beispiel #2
0
    def init_database(self):
        """
        Prepares a sqlite3 database for data set storage. If the file specified in AvivoreConfig.database_path
        doesn't exist a new sqlite3 database with table 'Data' is created. Otherwise the existing database is used to
        store additional data sets.

        :return:    None
        """
        if not Helper.is_string(self.database_path):
            raise AvivoreConfigException('Invalid database path specified!')

        table_data_exists = False

        if os.path.isfile(self.database_path):
            Helper.output('Using existing database to store results.')
            try:
                dbcon = lite.connect(self.database_path)
                dbcur = dbcon.cursor()
                dbcur.execute('SELECT Count(*) FROM Data')
                Helper.output(str(dbcur.fetchone()[0]) + ' entries in this database so far.')
                table_data_exists = True
            except lite.OperationalError:
                Helper.output('[W] Table \'Data\' not found in database!')

        if not table_data_exists:  # If the database doesn't exist, we'll create it.
            Helper.output('Creating new table \'Data\' in database \'%s\' to store data!' % self.database_path)
            dbcon = lite.connect(self.database_path)
            dbcur = dbcon.cursor()
            dbcur.execute(
                'CREATE TABLE Data (TimeRecv int, Type int, User text, UserId text, Value text, TID int, Message text)')
 def __init__(self, config_type, config_filename):
     if not Helper.is_string(config_filename):
         raise AvivoreConfigException('Invalid config file specified!')
     self.config_type = config_type
     self.config_filename = config_filename
     self.config = ConfigParser()
     self.twitter_search_types = []
     self.twitter_search_terms = []
     self.twitter_track_keywords = None
     self.twitter_consumer_key = None
     self.twitter_consumer_secret = None
     self.twitter_search_interval = 30
     self.credentials_file = None
     self.database_path = None
     self.mandatory_options = [
         # Be sure to keep order of database table layout for options from 'config' database
         # append type definitions for twitter_search_objects!
         ('database', 'dbpath'),
         ('twitter_auth', 'consumer_key'),
         ('twitter_auth', 'consumer_secret'),
         ('twitter_auth', 'credentials_file'),
         ('twitter_search', 'stream_tracking_keyword'),
         ('twitter_search', 'csv_search_term'),
         ('twitter_search_objects', '0'),
     ]
    def init_database(self):
        """
        Prepares a sqlite3 database for data set storage. If the file specified in AvivoreConfig.database_path
        doesn't exist a new sqlite3 database with table 'Data' is created. Otherwise the existing database is used to
        store additional data sets.

        :return:    None
        """
        if not Helper.is_string(self.database_path):
            raise AvivoreConfigException('Invalid database path specified!')

        table_data_exists = False

        if os.path.isfile(self.database_path):
            Helper.output('Using existing database to store results.')
            try:
                dbcon = lite.connect(self.database_path)
                dbcur = dbcon.cursor()
                dbcur.execute('SELECT Count(*) FROM Data')
                Helper.output(
                    str(dbcur.fetchone()[0]) +
                    ' entries in this database so far.')
                table_data_exists = True
            except lite.OperationalError:
                Helper.output('[W] Table \'Data\' not found in database!')

        if not table_data_exists:  # If the database doesn't exist, we'll create it.
            Helper.output(
                'Creating new table \'Data\' in database \'%s\' to store data!'
                % self.database_path)
            dbcon = lite.connect(self.database_path)
            dbcur = dbcon.cursor()
            dbcur.execute(
                'CREATE TABLE Data (TimeRecv int, Type int, User text, UserId text, Value text, TID int, Message text)'
            )
Beispiel #5
0
    def test_is_string(self):
        # testing non-string types
        self.assertFalse(Helper.is_string(['value1', 'value2', 'value3']))
        self.assertFalse(Helper.is_string(('item1', 'item2')))
        self.assertFalse(Helper.is_string(array('l', [1, 2, 3, 4, 5])))
        self.assertFalse(Helper.is_string(array('d', [1.0, 2.0, 3.0, 4.0, 5.0])))
        self.assertFalse(Helper.is_string(bytearray.fromhex("deadbeef")))
        self.assertFalse(Helper.is_string(dict(one=1, two=2, three=3)))
        self.assertFalse(Helper.is_string(3))
        self.assertFalse(Helper.is_string(3.14))
        self.assertFalse(Helper.is_string(self))
        self.assertFalse(Helper.is_string(None))
        self.assertFalse(Helper.is_string(True))
        self.assertFalse(Helper.is_string(Helper.is_string))

        # testing string types
        self.assertTrue(Helper.is_string("Hello World"))
        self.assertTrue(Helper.is_string("Hello World\u203c"))
Beispiel #6
0
    def test_is_string(self):
        # testing non-string types
        self.assertFalse(Helper.is_string(['value1', 'value2', 'value3']))
        self.assertFalse(Helper.is_string(('item1', 'item2')))
        self.assertFalse(Helper.is_string(array('l', [1, 2, 3, 4, 5])))
        self.assertFalse(
            Helper.is_string(array('d', [1.0, 2.0, 3.0, 4.0, 5.0])))
        self.assertFalse(Helper.is_string(bytearray.fromhex("deadbeef")))
        self.assertFalse(Helper.is_string(dict(one=1, two=2, three=3)))
        self.assertFalse(Helper.is_string(3))
        self.assertFalse(Helper.is_string(3.14))
        self.assertFalse(Helper.is_string(self))
        self.assertFalse(Helper.is_string(None))
        self.assertFalse(Helper.is_string(True))
        self.assertFalse(Helper.is_string(Helper.is_string))

        # testing string types
        self.assertTrue(Helper.is_string("Hello World"))
        self.assertTrue(Helper.is_string("Hello World\u203c"))