Commit 5baa725a authored by Dorian's avatar Dorian
Browse files

writing actors directly in other tables for the moment

parent 31578fc4
......@@ -19,8 +19,8 @@ mobilierurbain_catid = 1007
potelet_catid = 2030
# ratio for the number of items got by request
itemsbypages = 24
poteletbycategory = 48
itemsbypages = 2
poteletbycategory = 2
#---- DB WRITING ----
......@@ -80,8 +80,8 @@ def init_poteletsDB(conn):
updatedDate text,
duplicates text,
severalOccurrence text,
responsibleOrganisation_id integer,
responsibleDepartment_id integer
responsibleOrganisation text,
responsibleDepartment text
); """
attachments_table = """ CREATE TABLE IF NOT EXISTS attachments (
......@@ -90,7 +90,9 @@ def init_poteletsDB(conn):
date text,
type text,
content text,
actor_id integer
actor_type text,
organisation text,
department text
); """
history_table = """ CREATE TABLE IF NOT EXISTS history (
......@@ -98,8 +100,9 @@ def init_poteletsDB(conn):
potelet_id integer,
date text,
type text,
organisation_id integer,
department_id integer
actor_type text,
organisation text,
department text
); """
actors_table = """ CREATE TABLE IF NOT EXISTS actors (
......@@ -113,7 +116,7 @@ def init_poteletsDB(conn):
create_table(conn, potelets_table);
create_table(conn, attachments_table);
create_table(conn, history_table);
create_table(conn, actors_table);
# create_table(conn, actors_table);
def addPotelet(conn, potelet):
# basic data
......@@ -142,20 +145,24 @@ def addPotelet(conn, potelet):
# ext_id = potelet['externalId']
# priv_location = potelet['privateLocation']
# ADD ACTORS RESP ORG / DEP
# ADD ACTORS
# orga_short, depa_short = addActorFromIncident(conn, potelet)
# responsibleOrganisation_id = potelet['responsibleOrganisation']['id']
# responsibleDepartment_id = potelet['responsibleDepartment']['id']
# print('responsibleOrga.: ' + orga_short)
# print('responsibleDepa.: ' + depa_short)
# HARDCODE ACTORS
organisation = potelet['responsibleOrganisation']['nameEn']
department = potelet['responsibleDepartment']['nameEn']
# add it to potelets table
# value_list = [id, status, subcat, adress, coordinates, creationDate, updatedDate, responsibleOrganisation_id, responsibleDepartment_id]
# sql = ''' INSERT INTO potelets(id,status,subcat,adress,coordinates,creationDate,updatedDate,responsibleOrganisation_id,responsibleDepartment_id)
# VALUES(?,?,?,?,?,?,?,?,?) '''
value_list = [id, status, subcat, adress, coordinates, creationDate, updatedDate, duplicates, severalOccurrence]
sql = ''' INSERT INTO potelets(id,status,subcat,adress,coordinates,creationDate,updatedDate, duplicates, severalOccurrence)
VALUES(?,?,?,?,?,?,?,?,?) '''
value_list = [id, status, subcat, adress, coordinates, creationDate, updatedDate, duplicates, severalOccurrence, organisation, department]
sql = ''' INSERT INTO potelets(id,status,subcat,adress,coordinates,creationDate,updatedDate, duplicates, severalOccurrence, responsibleOrganisation, responsibleDepartment)
VALUES(?,?,?,?,?,?,?,?,?,?,?) '''
cur = conn.cursor()
cur.execute(sql, value_list)
......@@ -172,17 +179,44 @@ def addAttachment(conn, attachment):
else:
print("Error: attachment of unkown type " + type)
# ADD ACTORS
# actor_id, actor_short = addActorFromAttachment(conn, attachment)
# print('• ' + date + ' | ' + actor_short + ': ' + content)
print('• ' + date + ' | ' + content)
#HARDCODE ACTORS
actor_short = ''
orga_name = None
depa_name = None
actor_type = attachment['reporter']['type']
if actor_type == 'CITIZEN': # it is CITIZEN, no actor id
# CHECK: do we have others infos ??? -> no
actor_short = actor_type
else:
#-- organisation
if 'corporation' in attachment['reporter']:
orga = attachment['reporter']['corporation']
orga_name = orga['nameEn']
actor_short += orga_name
#-- departement
if 'team' in attachment['reporter']:
depa = attachment['reporter']['team']
depa_name = depa['nameEn']
actor_short += ' → ' + depa_name
actor_short += ' (' + actor_type + ')'
# CHECK: other keys than 'corporation' ??? -> no
print('• ' + date + ' | ' + actor_short + ': ' + content)
# add it to attachments table
# value_list = [id, potelet_id, date, type, content, actor_id]
# sql = ''' INSERT INTO attachments(id,potelet_id,date,type,content,actor_id)
# VALUES(?,?,?,?,?,?) '''
value_list = [id, potelet_id, date, type, content]
sql = ''' INSERT INTO attachments(id,potelet_id,date,type,content)
VALUES(?,?,?,?,?) '''
value_list = [id, potelet_id, date, type, content, actor_type, orga_name, depa_name]
sql = ''' INSERT INTO attachments(id,potelet_id,date,type,content,actor_type,organisation,department)
VALUES(?,?,?,?,?,?,?,?) '''
cur = conn.cursor()
cur.execute(sql, value_list)
......@@ -192,17 +226,42 @@ def addStory(conn, story):
date = story['historyDate']
type = story['historyType']
# ADD ACTORS
# orga_id, depa_id = addActorFromHistory(conn, story)
# print('• ' + date + ' | add actor: ' + ': ' + type)
print('• ' + date + ' | ' + type)
# HARDCODE ACTORS
actor_short = ''
orga_name = None
depa_name = None
actor_type = story['information']['actorType']
if actor_type == 'CITIZEN':
actor_short = actor_type
else:
#-- organisation
if 'corporation' in story['information']:
orga = story['information']['corporation']
orga_name = orga['nameEn']
actor_short += orga_name
#-- departement
if 'team' in story['information']:
depa = story['information']['team']
depa_name = depa['nameEn']
actor_short += ' → ' + depa_name
actor_short += ' (' + actor_type + ')'
# CHECK: other keys than 'corporation' ??? -> no
print('• ' + date + ' | ' + actor_short + ': ' + type)
# add it to story table
# value_list = [id, potelet_id, date, type, orga_id, depa_id]
# sql = ''' INSERT INTO history(id,potelet_id,date,type,organisation_id,department_id)
# VALUES(?,?,?,?,?,?) '''
value_list = [id, potelet_id, date, type]
sql = ''' INSERT INTO history(id,potelet_id,date,type)
VALUES(?,?,?,?) '''
value_list = [id, potelet_id, date, type, actor_type, orga_name, depa_name]
sql = ''' INSERT INTO history(id,potelet_id,date,type, actor_type, organisation, department)
VALUES(?,?,?,?,?,?,?) '''
cur = conn.cursor()
cur.execute(sql, value_list)
......
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment