From fb81854aa4b4007eb4db59fd41edabe0d67e7cf0 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Mon, 19 Dec 2022 15:27:21 -0500 Subject: [PATCH 1/9] collapse pco sub-orgs' briefingt/qpnotes records under pco --- bin/migrate/migrate_briefingt_2022_12.py | 36 ++++++++++++++++++++++++ bin/migrate/migrate_qpnotes_2022_12.py | 36 ++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 bin/migrate/migrate_briefingt_2022_12.py create mode 100644 bin/migrate/migrate_qpnotes_2022_12.py diff --git a/bin/migrate/migrate_briefingt_2022_12.py b/bin/migrate/migrate_briefingt_2022_12.py new file mode 100644 index 000000000..9729f81d6 --- /dev/null +++ b/bin/migrate/migrate_briefingt_2022_12.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all briefingt records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vmp', + 'pqcc-pcprc', + 'ql-lq', + 'srp-rsp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line['owner_org'] = PCO['owner_org'] + line['owner_org_title'] = PCO['owner_org_title'] + out_csv.writerow(line) diff --git a/bin/migrate/migrate_qpnotes_2022_12.py b/bin/migrate/migrate_qpnotes_2022_12.py new file mode 100644 index 000000000..39f1a0587 --- /dev/null +++ b/bin/migrate/migrate_qpnotes_2022_12.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all qpnotes records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vmp', + 'pqcc-pcprc', + 'ql-lq', + 'srp-rsp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line['owner_org'] = PCO['owner_org'] + line['owner_org_title'] = PCO['owner_org_title'] + out_csv.writerow(line) From 26db8dabb7eff2181ec5e551e78631414fb6e2f2 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Tue, 20 Dec 2022 10:12:11 -0500 Subject: [PATCH 2/9] update pco-sub org name change to pkcc-pcprc --- bin/migrate/migrate_briefingt_2022_12.py | 2 +- bin/migrate/migrate_qpnotes_2022_12.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/migrate/migrate_briefingt_2022_12.py b/bin/migrate/migrate_briefingt_2022_12.py index 9729f81d6..299b5d6b4 100644 --- a/bin/migrate/migrate_briefingt_2022_12.py +++ b/bin/migrate/migrate_briefingt_2022_12.py @@ -16,7 +16,7 @@ 'mdi-mid', 'miga-maig', 'dpm-vmp', - 'pqcc-pcprc', + 'pkcc-pcprc', 'ql-lq', 'srp-rsp', ] diff --git a/bin/migrate/migrate_qpnotes_2022_12.py b/bin/migrate/migrate_qpnotes_2022_12.py index 39f1a0587..aa40cc96c 100644 --- a/bin/migrate/migrate_qpnotes_2022_12.py +++ b/bin/migrate/migrate_qpnotes_2022_12.py @@ -16,7 +16,7 @@ 'mdi-mid', 'miga-maig', 'dpm-vmp', - 'pqcc-pcprc', + 'pkcc-pcprc', 'ql-lq', 'srp-rsp', ] From 3601faef39f4e9a25256262f9d42fc985aeb6e28 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Tue, 20 Dec 2022 10:49:14 -0500 Subject: [PATCH 3/9] minor improvement to pco sub-orgs migration script --- bin/migrate/migrate_briefingt_2022_12.py | 5 ++--- bin/migrate/migrate_qpnotes_2022_12.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/bin/migrate/migrate_briefingt_2022_12.py b/bin/migrate/migrate_briefingt_2022_12.py index 299b5d6b4..8962abb77 100644 --- a/bin/migrate/migrate_briefingt_2022_12.py +++ b/bin/migrate/migrate_briefingt_2022_12.py @@ -15,7 +15,7 @@ 'iga-aig', 'mdi-mid', 'miga-maig', - 'dpm-vmp', + 'dpm-vpm', 'pkcc-pcprc', 'ql-lq', 'srp-rsp', @@ -31,6 +31,5 @@ for line in in_csv: if line['owner_org'] in sub_orgs: - line['owner_org'] = PCO['owner_org'] - line['owner_org_title'] = PCO['owner_org_title'] + line.update(PCO) out_csv.writerow(line) diff --git a/bin/migrate/migrate_qpnotes_2022_12.py b/bin/migrate/migrate_qpnotes_2022_12.py index aa40cc96c..78efa27a8 100644 --- a/bin/migrate/migrate_qpnotes_2022_12.py +++ b/bin/migrate/migrate_qpnotes_2022_12.py @@ -15,7 +15,7 @@ 'iga-aig', 'mdi-mid', 'miga-maig', - 'dpm-vmp', + 'dpm-vpm', 'pkcc-pcprc', 'ql-lq', 'srp-rsp', @@ -31,6 +31,5 @@ for line in in_csv: if line['owner_org'] in sub_orgs: - line['owner_org'] = PCO['owner_org'] - line['owner_org_title'] = PCO['owner_org_title'] + line.update(PCO) out_csv.writerow(line) From e2f571988ff7d966a26aa78270aa87b4f4ee5a51 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Tue, 20 Dec 2022 10:50:36 -0500 Subject: [PATCH 4/9] add pco sub-orgs migration scripts for travelq and hospitalityq --- bin/migrate/migrate_hospitalityq_2022_12.py | 35 +++++++++++++++++++++ bin/migrate/migrate_travelq_2022_12.py | 35 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 bin/migrate/migrate_hospitalityq_2022_12.py create mode 100644 bin/migrate/migrate_travelq_2022_12.py diff --git a/bin/migrate/migrate_hospitalityq_2022_12.py b/bin/migrate/migrate_hospitalityq_2022_12.py new file mode 100644 index 000000000..56de00cdd --- /dev/null +++ b/bin/migrate/migrate_hospitalityq_2022_12.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all hospitalityq records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_travelq_2022_12.py b/bin/migrate/migrate_travelq_2022_12.py new file mode 100644 index 000000000..7cf013fe5 --- /dev/null +++ b/bin/migrate/migrate_travelq_2022_12.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all travelq records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) From 8205820e8bca16afc8898559a07055c25dfafaef Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Fri, 23 Dec 2022 10:17:25 -0500 Subject: [PATCH 5/9] migration script to collapse pco sub-orgs for travelq-nil --- bin/migrate/migrate_travelq_nil_2022_12.py | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bin/migrate/migrate_travelq_nil_2022_12.py diff --git a/bin/migrate/migrate_travelq_nil_2022_12.py b/bin/migrate/migrate_travelq_nil_2022_12.py new file mode 100644 index 000000000..d1bd17e77 --- /dev/null +++ b/bin/migrate/migrate_travelq_nil_2022_12.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all travelq-nil records +for PCO sub-organizations into PCO organization. +Duplicate records from sub-orgnizations for (year,month) +will be ignored +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +data = [] + +def report_exists(year, month, owner_org): + for row in data: + if row['year'] == year and \ + row['month'] == month and \ + row['owner_org'] == owner_org: + return True + return False + +for line in in_csv: + if line['owner_org'] in sub_orgs: + if not report_exists(line['year'], line['month'], PCO['owner_org']): + line.update(PCO) + data.append(line) + else: + data.append(line) + +for line in data: + out_csv.writerow(line) From da9f9801df11ce118b26908019d42b1af01f4258 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Fri, 23 Dec 2022 11:58:11 -0500 Subject: [PATCH 6/9] migration script to collapse pco sub-orgs for hospitalityq-nil --- .../migrate_hospitalityq_nil_2022_12.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bin/migrate/migrate_hospitalityq_nil_2022_12.py diff --git a/bin/migrate/migrate_hospitalityq_nil_2022_12.py b/bin/migrate/migrate_hospitalityq_nil_2022_12.py new file mode 100644 index 000000000..108c9470e --- /dev/null +++ b/bin/migrate/migrate_hospitalityq_nil_2022_12.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all hospitalityq-nil records +for PCO sub-organizations into PCO organization. +Duplicate records from sub-orgnizations for (year,month) +will be ignored +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +data = [] + +def report_exists(year, month, owner_org): + for row in data: + if row['year'] == year and \ + row['month'] == month and \ + row['owner_org'] == owner_org: + return True + return False + +for line in in_csv: + if line['owner_org'] in sub_orgs: + if not report_exists(line['year'], line['month'], PCO['owner_org']): + line.update(PCO) + data.append(line) + else: + data.append(line) + +for line in data: + out_csv.writerow(line) From eebf379cf29f348f8aa7ef68d44ef8b9ee74e837 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Wed, 1 Mar 2023 13:15:06 -0500 Subject: [PATCH 7/9] add more organizations to migration scripts for pco --- bin/migrate/migrate_briefingt_2022_12.py | 5 +++++ bin/migrate/migrate_hospitalityq_2022_12.py | 5 +++++ bin/migrate/migrate_hospitalityq_nil_2022_12.py | 5 +++++ bin/migrate/migrate_qpnotes_2022_12.py | 5 +++++ bin/migrate/migrate_travelq_2022_12.py | 5 +++++ bin/migrate/migrate_travelq_nil_2022_12.py | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/bin/migrate/migrate_briefingt_2022_12.py b/bin/migrate/migrate_briefingt_2022_12.py index 8962abb77..d0bfcad19 100644 --- a/bin/migrate/migrate_briefingt_2022_12.py +++ b/bin/migrate/migrate_briefingt_2022_12.py @@ -19,6 +19,11 @@ 'pkcc-pcprc', 'ql-lq', 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', ] PCO = { 'owner_org': 'pco-bcp', 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } diff --git a/bin/migrate/migrate_hospitalityq_2022_12.py b/bin/migrate/migrate_hospitalityq_2022_12.py index 56de00cdd..54889985e 100644 --- a/bin/migrate/migrate_hospitalityq_2022_12.py +++ b/bin/migrate/migrate_hospitalityq_2022_12.py @@ -19,6 +19,11 @@ 'pkcc-pcprc', 'ql-lq', 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', ] PCO = { 'owner_org': 'pco-bcp', 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } diff --git a/bin/migrate/migrate_hospitalityq_nil_2022_12.py b/bin/migrate/migrate_hospitalityq_nil_2022_12.py index 108c9470e..00bc20d5e 100644 --- a/bin/migrate/migrate_hospitalityq_nil_2022_12.py +++ b/bin/migrate/migrate_hospitalityq_nil_2022_12.py @@ -21,6 +21,11 @@ 'pkcc-pcprc', 'ql-lq', 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', ] PCO = { 'owner_org': 'pco-bcp', 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } diff --git a/bin/migrate/migrate_qpnotes_2022_12.py b/bin/migrate/migrate_qpnotes_2022_12.py index 78efa27a8..0a19a00f0 100644 --- a/bin/migrate/migrate_qpnotes_2022_12.py +++ b/bin/migrate/migrate_qpnotes_2022_12.py @@ -19,6 +19,11 @@ 'pkcc-pcprc', 'ql-lq', 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', ] PCO = { 'owner_org': 'pco-bcp', 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } diff --git a/bin/migrate/migrate_travelq_2022_12.py b/bin/migrate/migrate_travelq_2022_12.py index 7cf013fe5..f9ae73ad1 100644 --- a/bin/migrate/migrate_travelq_2022_12.py +++ b/bin/migrate/migrate_travelq_2022_12.py @@ -19,6 +19,11 @@ 'pkcc-pcprc', 'ql-lq', 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', ] PCO = { 'owner_org': 'pco-bcp', 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } diff --git a/bin/migrate/migrate_travelq_nil_2022_12.py b/bin/migrate/migrate_travelq_nil_2022_12.py index d1bd17e77..fadc91f58 100644 --- a/bin/migrate/migrate_travelq_nil_2022_12.py +++ b/bin/migrate/migrate_travelq_nil_2022_12.py @@ -21,6 +21,11 @@ 'pkcc-pcprc', 'ql-lq', 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', ] PCO = { 'owner_org': 'pco-bcp', 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } From a7cb68ac3caa832b766c3905ba24f299d53fa149 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Wed, 1 Mar 2023 13:57:26 -0500 Subject: [PATCH 8/9] add migration scripts for contracts, travela for pco merge --- bin/migrate/migrate_contracts_2022_12.py | 40 ++++++++++++++++++++++++ bin/migrate/migrate_travela_2022_12.py | 40 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 bin/migrate/migrate_contracts_2022_12.py create mode 100644 bin/migrate/migrate_travela_2022_12.py diff --git a/bin/migrate/migrate_contracts_2022_12.py b/bin/migrate/migrate_contracts_2022_12.py new file mode 100644 index 000000000..bbe736b3b --- /dev/null +++ b/bin/migrate/migrate_contracts_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all contracts records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_travela_2022_12.py b/bin/migrate/migrate_travela_2022_12.py new file mode 100644 index 000000000..d5636d5e4 --- /dev/null +++ b/bin/migrate/migrate_travela_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all travela records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) From ead9e2121ade8d6d5e4b70086e70ef27d7c7bcc8 Mon Sep 17 00:00:00 2001 From: Rabia Sajjad Date: Wed, 1 Mar 2023 15:57:46 -0500 Subject: [PATCH 9/9] add migration script for contracts-nil for pco-merge --- bin/migrate/migrate_contracts_nil_2022_12.py | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 bin/migrate/migrate_contracts_nil_2022_12.py diff --git a/bin/migrate/migrate_contracts_nil_2022_12.py b/bin/migrate/migrate_contracts_nil_2022_12.py new file mode 100644 index 000000000..9900170ac --- /dev/null +++ b/bin/migrate/migrate_contracts_nil_2022_12.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all contracts-nil records +for PCO sub-organizations into PCO organization. +Duplicate records from sub-orgnizations for +reporting_period will be ignored +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +data = [] + +def report_exists(reporting_period, owner_org): + for row in data: + if row['reporting_period'] == reporting_period and \ + row['owner_org'] == owner_org: + return True + return False + +for line in in_csv: + if line['owner_org'] in sub_orgs: + if not report_exists(line['reporting_period'], PCO['owner_org']): + line.update(PCO) + data.append(line) + else: + data.append(line) + +for line in data: + out_csv.writerow(line)