def move_data():
    for i, cur_record in enumerate(get_all(limit=None)):
        print i
        tmp_result = cPickle.loads(cur_record.get('content')) 
        test_data = {'url': tmp_result.get('url')}
        src = tmp_result.pop('zipped_page')

        insert_data({'content': cPickle.dumps(tmp_result), 'src': cPickle.dumps(src)}, test_data, table_name='buzz_data')
def main():
    possible_choice = ['create data table', 'drop data table', 'insert data',
                       'get data', 'update data', 'delete data']
    choice = raw_input('Please input your choice: ')
    if choice in possible_choice:
        cur = get_cur()
        if choice == 'create data table':
            num_of_cols = int(raw_input('Please insert a number of columns: '))
            cols = {}
            for item in range(num_of_cols):
                col_name = raw_input('Please insert a column name: ')
                col_type = raw_input('Please insert a column type: ')
                cols[col_name] = col_type
            return create_table(cur, **cols)
        elif choice == 'drop data table':
            return del_table(cur)
        elif choice == 'insert data':
            file_name = raw_input('Please input name of the log file: ')
            key1 = raw_input('Please input the first key: ')
            key2 = raw_input('Please input the second key: ')
            cols = []
            num_of_cols = int(raw_input('Please insert a number of columns: '))
            for item in range(num_of_cols):
                col_name = raw_input('Please insert a {} column '
                                     'name: '.format(item + 1))
                cols.append(col_name)
            uniq = raw_input('Please chose \'data\' or \'calc\': ')
            archive = {'yes': True, 'no': False}
            arch = raw_input('Read from an archive? Please input \'yes\' or '
                             '\'no\' (default \'no\'): ')
            return insert_data(cur, file_name, key1, key2, cols, uniq,
                               archive.get(arch, False))
        elif choice == 'get data':
            id_val = int(raw_input('Please insert the \'id\' value: '))
            return get_data(cur, id_val)
        elif choice == 'update data':
            id_val = int(raw_input('Please insert the \'id\' value: '))
            cols_to_update = raw_input('Please input a column or columns to '
                                       'update: ')
            cols_vals = {}
            for item in cols_to_update.split(', '):
                cols_vals[item] = raw_input('Please input a new value for the '
                                            '\'{}\' column: '.format(item))
            return update_data(cur, id_val, **cols_vals)
        elif choice == 'delete data':
            cols = raw_input('Please input a column or columns to '
                             'delete: ')
            cols_vals = {}
            for item in cols.split(', '):
                cols_vals[item] = raw_input('Please input a value of the '
                                            '\'{}\' column: '.format(item))
            return delete_data(cur, **cols_vals)
Exemple #3
0
 def test_add_data(self):
     """
     test when we add data to redis
     """
     res = insert_data(self.fake_redis_db, "huxy", "2.1")
     self.assertIsNotNone(res)