Skip to content

Commit

Permalink
24378 - script to add Registrar's Notation to all existing companies (b…
Browse files Browse the repository at this point in the history
…cgov#3088)

* 24378 - jupyter notebook to add registrars notation filing for existing BENs

* 24378 - update notebook

* 24378 - update date

* 24378 - move files

* 24378 - update data

* 24378 - updat order details text
  • Loading branch information
ketaki-deodhar authored Dec 4, 2024
1 parent 969d921 commit 50e41da
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
135 changes: 135 additions & 0 deletions jobs/correction-ben-statement/add_registrars_notation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Add Registrar's Notation to all existing companies"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<b> Purpose: Add Registrar's Notation filing to all 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": null,
"metadata": {},
"outputs": [],
"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 create Registrar's Notation filing for businesses."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from urllib.parse import urljoin\n",
"from data import ben_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 ben in ben_businesses:\n",
" filing_data = {\n",
" \"filing\": {\n",
" \"header\": {\n",
" \"name\": \"registrarsNotation\",\n",
" \"date\": current_date,\n",
" \"certifiedBy\": \"system\"\n",
" },\n",
" \"business\": {\n",
" \"identifier\": ben,\n",
" \"legalType\": \"BEN\"\n",
" },\n",
" \"registrarsNotation\": {\n",
" \"orderDetails\": \"BC benefit company statement contained in notice of articles as required under \" + \n",
" \"section 51.992 of the Business Corporations Act corrected from \" +\n",
" \"\\\"This company is a benefit company and, as such, has purposes that include conducting its business \" +\n",
" \" in a responsible and 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 a \" + \n",
" \"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/{ben}/filings\")\n",
" response = requests.post(filing_url, headers=headers, json=filing_data)\n",
"\n",
" # Check the status code of the response\n",
" if response.status_code == 201:\n",
" print(f\"Registrars Notation cretaed successfully for {ben}\")\n",
" else:\n",
" print(f\"Failed to make POST request. Status code: {response.status_code}\")\n",
" print(response.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
}
7 changes: 7 additions & 0 deletions jobs/correction-ben-statement/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Populate this list with the existing BEN business identifiers from specified environment
# This works as a data file for Jupyter notebook used to add Registrar's Notation
ben_businesses = [
"BC0871277",
"BC0871062"
]

0 comments on commit 50e41da

Please sign in to comment.