def test_distinct_insert2(self): conn = Couch("test") test_doc = {"adsf": {"bbb": "fdsa", "aand": "ssss"}} for i in range(3): conn.distinct_insert(test_doc) query_result = conn.query(test_doc) conn.close() self.assertEqual(1, len(query_result))
def test_database_insert_and_query(self): conn = Couch("test") test_doc = {"abc": "def"} conn.insert(test_doc) selector = {"abc": "def"} res = conn.query(selector) conn.close() for item in res: self.assertEqual(item['abc'], 'def')
def test_database_insert_and_partial_query(self): conn = Couch("test") test_doc = {"adsf": {"bbb": "fdsa", "aand": "ssss"}} conn.insert(test_doc) selector = {"asdf": {"bbb": "fdsa"}} res = conn.query(selector) conn.close() for item in res: self.assertEqual(item, test_doc)
def import_directory_to_db(path, db_name): db = Couch(db_name) files = os.listdir(path) cnt = 0 for filename in files: if cnt % 100 == 0: print('Processing {} of {} records.'.format(cnt, len(files))) cnt += 1 import_file_to_db(path + "/" + filename, db) logger.info('{} records inserted.'.format(len(files))) db.close()
def test_retrieve_flickr_realtime_in_db(self): account = {'platform': 'Flickr', 'account': 'sakuranyochan'} retrieve(account, REALTIME_MODE) db = Couch('flickr') query_result = db.query({'profile': {'username': '******'}}) db.close() self.assertTrue(len(query_result) > 0) query_result = retrieve(account, REALTIME_MODE) for item in query_result: self.assertTrue('profile' in item.keys() and item['profile']['username'] == 'sakuranyochan')
def store_result(info1, info2, vector, database): database = Couch(database) doc = { 'platform1': info1['platform'], 'platform2': info2['platform'], 'username1': info1['profile']['username'], 'username2': info2['profile']['username'], 'vector': vector } logger.info('Storing result: {}'.format(doc)) doc_id = database.distinct_insert(_convert_float(doc)) database.close() return doc_id
def login_account(): data = json.loads(request.get_data().decode('utf-8')) platform = data['platform'] username = data['username'] password = decrypt(data['password']) res = False instance = None if len(username) == 0 and len(password) == 0: return make_response({'result': res}) if platform == 'Instagram': instance = InsUtilsWithLogin(displayed=False) elif platform == 'Twitter': instance = TwiUtilsWithLogin(displayed=False) if instance is None: return make_response({'result': False}) instance.set_account((username, password)) res = instance.login() if res: database = Couch(DATABASE_CREDENTIAL) database.insert(data) database.close() return make_response({'result': res})
def test_query_latest(self): conn = Couch("test") selector = {"abc": "def"} res = conn.query_latest_change(selector) conn.close() self.assertEqual(1, len(res))