-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
24839 - script to add corrections and related changes (#3168)
* 24839 - script to add corrections and related changes * 24839 - remove unused file * 24839 - remove unused data * 24839 - updated queries * 24839 - remove commented out code * 24629 - fix linting issue * 24629 - remove uneeded code * 24629 - add correction check * 24629 - fix correction format share class logic
- Loading branch information
1 parent
9f33aad
commit 9ca5ad0
Showing
12 changed files
with
276 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Add Correction filing for All active existing companies" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<b> Purpose: Add Corrections filing for all active existing BENs.</b>\n", | ||
"\n", | ||
"This is a one time (python) script to be run at a given date/time.<br>\n", | ||
"Set the configuration (client_id, client_secret, url(s)) for a scpecific environment.<br>\n", | ||
"Get access token for authorization.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Access token returned successfully\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import requests\n", | ||
"import os\n", | ||
"from datetime import datetime\n", | ||
"\n", | ||
"# token_url, client_id, client_secret, base_url - update based on environment\n", | ||
"token_url = os.getenv('ACCOUNT_SVC_AUTH_URL')\n", | ||
"client_id = os.getenv('ACCOUNT_SVC_CLIENT_ID')\n", | ||
"client_secret = os.getenv('ACCOUNT_SVC_CLIENT_SECRET')\n", | ||
"base_url = os.getenv('LEGAL_API_BASE_URL')\n", | ||
"\n", | ||
"header = {\n", | ||
" \"Content-Type\": \"application/x-www-form-urlencoded\"\n", | ||
"}\n", | ||
"\n", | ||
"data = 'grant_type=client_credentials'\n", | ||
"\n", | ||
"res = requests.post(token_url, data, auth=(client_id, client_secret), headers=header)\n", | ||
"\n", | ||
"# Check the status code of the response\n", | ||
"if res.status_code == 200:\n", | ||
" print(\"Access token returned successfully\")\n", | ||
" token = res.json()[\"access_token\"]\n", | ||
"else:\n", | ||
" print(f\"Failed to make POST request. Status code: {res.status_code}\")\n", | ||
" print(res.text) # Print the error message if the request fails\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Call API (POST) endpoint to createCorrection filing with details as Ben correction statement for businesses." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Correction created successfully for BC0871147\n", | ||
"Correction created successfully for BC0871183\n", | ||
"Correction created successfully for BC0871186\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from urllib.parse import urljoin\n", | ||
"from corrections_output import correction_businesses\n", | ||
"\n", | ||
"current_date = datetime.now().date().isoformat()\n", | ||
"headers = {\n", | ||
" 'Content-Type': 'application/json',\n", | ||
" 'Authorization': 'Bearer ' + token\n", | ||
"}\n", | ||
"\n", | ||
"# loop through list of businesses to create filing\n", | ||
"for correction_businesse in correction_businesses:\n", | ||
" identifier = correction_businesse[0]\n", | ||
" filind_id = correction_businesse[1]\n", | ||
" correction_filing_data = {\n", | ||
" \"filing\": {\n", | ||
" \"header\": {\n", | ||
" \"name\": \"correction\",\n", | ||
" \"date\": current_date,\n", | ||
" \"certifiedBy\": \"system\"\n", | ||
" },\n", | ||
" \"business\": {\n", | ||
" \"identifier\": identifier,\n", | ||
" \"legalType\": \"BC\"\n", | ||
" },\n", | ||
" \"correction\": {\n", | ||
" \"details\": \"First correction\",\n", | ||
" \"correctedFilingId\": filind_id,\n", | ||
" \"correctedFilingType\": \"incorporationApplication\",\n", | ||
" \"comment\": f\"\"\"Correction for Incorporation Application filed on {current_date} \\n\n", | ||
" BC benefit company statement contained in notice of articles as required under section \n", | ||
" 51.992 of the Business Corporations Act corrected from “This company is a benefit company \n", | ||
" and, as such, has purposes that include conducting its business in a responsible and \n", | ||
" sustainable manner and promoting one or more public benefits” to \n", | ||
" “This company is a benefit company and, as such, is committed to conducting its business in \n", | ||
" a responsible and sustainable manner and promoting one or more public benefits”.\"\"\"\n", | ||
" }\n", | ||
" }\n", | ||
" }\n", | ||
"\n", | ||
" filing_url = urljoin(base_url, f\"/api/v2/businesses/{identifier}/filings\")\n", | ||
" rv = requests.post(filing_url, headers=headers, json=correction_filing_data)\n", | ||
"\n", | ||
" # Check the status code of the response\n", | ||
" if rv.status_code == 201:\n", | ||
" print(f\"Correction created successfully for {identifier}\")\n", | ||
" else:\n", | ||
" print(f\"Failed to make POST request. Status code: {rv.status_code}\")\n", | ||
" print(rv.text) # Print the error message if the request fails\n", | ||
" \n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pandas as pd | ||
|
||
# Function to convert CSV to array of arrays using pandas | ||
def convert_csv_to_array_of_arrays(csv_filename): | ||
# Read the CSV file into a pandas DataFrame | ||
df = pd.read_csv(csv_filename) | ||
|
||
# Convert the DataFrame to a list of lists (array of arrays) | ||
rows_array = df.values.tolist() | ||
|
||
return rows_array | ||
|
||
# Write the array of arrays to a Python file | ||
def write_array_to_python_file(array, output_filename): | ||
with open(output_filename, 'w') as f: | ||
f.write('correction_businesses = [\n') # Start the Python array | ||
for row in rows_array: | ||
f.write(f' {row},\n') # Write each row as a list | ||
f.write(']\n') # End the Python array | ||
|
||
# Specify your input and output filenames | ||
csv_filename = 'corrections_results.csv' | ||
output_filename = 'corrections_output.py' | ||
|
||
# Convert CSV to array of arrays | ||
rows_array = convert_csv_to_array_of_arrays(csv_filename) | ||
|
||
# Write the result to a Python file | ||
write_array_to_python_file(rows_array, output_filename) | ||
|
||
print(f"Data has been written to {output_filename}") |
32 changes: 32 additions & 0 deletions
32
jobs/correction-ben-statement/convert_registrar_notation_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import csv | ||
|
||
# Function to read CSV and convert to a Python array | ||
def csv_to_python_array(file_path): | ||
array = [] | ||
|
||
# Open the CSV file and read its contents | ||
with open(file_path, mode='r', newline='') as file: | ||
reader = csv.reader(file) | ||
for row in reader: | ||
array.extend(row) # Add each element from the row to the array | ||
|
||
return array | ||
|
||
# Function to write the Python array to a file, with each element on a new row | ||
def write_to_python_file(array, output_file): | ||
with open(output_file, 'w') as file: | ||
file.write('rn_businesses = [\n') # Start the array in Python format | ||
for element in array: | ||
file.write(f" '{element}',\n") # Write each element in the array | ||
file.write(']\n') # End the array in Python format | ||
|
||
input_csv = 'registrar_notation_result.csv' | ||
output_python_file = 'rn_output.py' | ||
|
||
# Convert CSV to Python array | ||
python_array = csv_to_python_array(input_csv) | ||
|
||
# Write the array to a Python file | ||
write_to_python_file(python_array, output_python_file) | ||
|
||
print(f"Python array has been written to {output_python_file}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
correction_businesses = [ | ||
['BC0871147', 131528], | ||
['BC0871183', 133390], | ||
['BC0871186', 139687], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"identifier","id" | ||
"BC1218818",110441 | ||
"BC1218819",110445 | ||
"BC1218820",110446 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- query to get all businesses (BENs) for Registrar's Notation | ||
select b.identifier | ||
from businesses b | ||
where b.legal_type = 'BEN' | ||
order by b.identifier asc; | ||
|
||
-- query to get all ACTIVE businesses (BENs) for Corrections | ||
select b.identifier, f.id | ||
from businesses b join filings f on b.id = f.business_id | ||
where b.legal_type = 'BEN' and f.filing_type = 'incorporationApplication' and b.state = 'ACTIVE' | ||
order by b.identifier asc; | ||
|
||
-- query to get all ACTIVE businesses (BENs) which have "in progress" drafts | ||
select b.identifier, f.id, f.filing_type | ||
from businesses b join filings f on b.id = f.business_id | ||
where b.legal_type = 'BEN' and b.state = 'ACTIVE' and f.status = 'DRAFT' | ||
order by b.identifier asc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"BC1230101" | ||
"BC1230102" | ||
"BC1230104" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rn_businesses = [ | ||
'BC1230101', | ||
'BC1230102', | ||
'BC1230104', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters