total_doc = doccano_client.get_project_statistics(1)[ 'total'] # 1 is for project_id remaining_doc = doccano_client.get_project_statistics(1)[ 'remaining'] # 1 is for project_id documnet_iter_start = doccano_client.get_document_list(1)['results'][0]['id'] try: connection = psycopg2.connect(user="******", password="******", host="127.0.0.1", port="5432", database="sahib") cursor = connection.cursor() postgres_insert_query = """ INSERT INTO output_data (ID, info) VALUES (%s,%s)""" for i in range(documnet_iter_start, documnet_iter_start + total_doc): s = doccano_client.get_document_detail(1, i) doc_id = s['id'] doc_text = s['text'].replace("'", "") doc_ann = s['annotations'] temp = {"text": doc_text, "annotations": doc_ann} cursor.execute( """INSERT INTO output_data (id,info) VALUES ( '{}','{}') """. format(doc_id, json.dumps((temp)))) connection.commit() except (Exception, psycopg2.Error) as error: if (connection): print("Failed to push records into insert table", error) finally:
from doccano_api_client import DoccanoClient doccano_client = DoccanoClient('http://15.207.89.34', 'admin', 'spinnaker') ls = [] for i in range(123719, 124718): # try: # ls.append(doccano_client.get_document_detail(1,i)['id']) id_ = doccano_client.get_document_detail(4, i)['id'] text = doccano_client.get_document_detail(4, i)['text'] if text == 'Like': print(doccano_client.get_document_detail(4, i)) ls.append(id_) doccano_client.delete_document(1, i) except: continue # print(doccano_client.get_document_detail(3,i)['id']) # if text=='Like': # ls.append(id_) # doccano_client.delete_document(3,id_) # else: # continue print(len(ls))