From c2b301f48e3c5704f75324719ea37f492d996dd4 Mon Sep 17 00:00:00 2001 From: Wil T Date: Thu, 14 Mar 2024 10:57:54 -0400 Subject: [PATCH] black and flake8 linter fixes --- parsons/action_builder/action_builder.py | 2 +- .../test_action_builder.py | 38 ++++++++++--------- .../sample_code/ngpvan_sample_printedlist.py | 21 ++++++---- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/parsons/action_builder/action_builder.py b/parsons/action_builder/action_builder.py index 17aea11fa2..2af620d77f 100644 --- a/parsons/action_builder/action_builder.py +++ b/parsons/action_builder/action_builder.py @@ -279,7 +279,7 @@ def add_section_field_values_to_record( { "action_builder:name": tag, "action_builder:field": field, - "action_builder:section": section + "action_builder:section": section, } for field, tag in field_values.items() ] diff --git a/test/test_action_builder/test_action_builder.py b/test/test_action_builder/test_action_builder.py index 4e8e00676e..79b1ae89bf 100644 --- a/test/test_action_builder/test_action_builder.py +++ b/test/test_action_builder/test_action_builder.py @@ -127,7 +127,7 @@ def setUp(self, m): self.fake_field_values = { "Fake Field 2": "Fake Tag 5", - self.fake_field_1: self.fake_tag_4 + self.fake_field_1: self.fake_tag_4, } self.fake_tagging = [ @@ -140,7 +140,7 @@ def setUp(self, m): "action_builder:name": "Fake Tag 5", "action_builder:field": "Fake Field 2", "action_builder:section": self.fake_section, - } + }, ] self.fake_entity_id = "fake-entity-id-1" @@ -162,7 +162,7 @@ def setUp(self, m): "status": "unsubscribed", "source": "api", } - ] + ], } self.fake_upsert_person = { @@ -179,9 +179,9 @@ def setUp(self, m): "action_builder:identifier": "action_builder:fake-email-id-1", "address": "fakey@mcfakerson.com", "address_type": "Work", - "status": "unsubscribed" + "status": "unsubscribed", } - ] + ], } } @@ -197,7 +197,7 @@ def setUp(self, m): "created_date": self.fake_datetime, "modified_date": self.fake_datetime, } - } + }, } self.fake_update_person = { @@ -234,7 +234,8 @@ def test_get_all_records(self, m): text=json.dumps({"_embedded": {"osdi:tags": []}}), ) assert_matching_tables( - self.bldr._get_all_records(self.campaign, "tags"), Table(self.fake_tags_list) + self.bldr._get_all_records(self.campaign, "tags"), + Table(self.fake_tags_list), ) @requests_mock.Mocker() @@ -274,14 +275,15 @@ def prepare_dict_key_intersection(self, dict1, dict2): # Internal method to compare a reference dict to a new incoming one, keeping only common # keys whose values are not lists (i.e. nested). - common_keys = {key for key, value in dict1.items() if key in dict2 - and not isinstance(value, list)} + common_keys = { + key + for key, value in dict1.items() + if key in dict2 and not isinstance(value, list) + } - dict1_comp = {key: value for key, value in dict1.items() - if key in common_keys} + dict1_comp = {key: value for key, value in dict1.items() if key in common_keys} - dict2_comp = {key: value for key, value in dict2.items() - if key in common_keys} + dict2_comp = {key: value for key, value in dict2.items() if key in common_keys} return dict1_comp, dict2_comp @@ -291,7 +293,9 @@ def test_upsert_entity(self, m): # Flatten and remove items added for spreadable arguments upsert_person = self.fake_upsert_person["person"] - upsert_response = self.bldr._upsert_entity(self.fake_upsert_person, self.campaign) + upsert_response = self.bldr._upsert_entity( + self.fake_upsert_person, self.campaign + ) person_comp, upsert_response_comp = self.prepare_dict_key_intersection( upsert_person, upsert_response @@ -348,15 +352,13 @@ def tagging_callback(self, request, context): tagging_data = post_data["add_tags"] # Force the sort to allow for predictable comparison - return sorted(tagging_data, key=lambda k: k['action_builder:name']) + return sorted(tagging_data, key=lambda k: k["action_builder:name"]) @requests_mock.Mocker() def test_add_section_field_values_to_record(self, m): m.post(f"{self.api_url}/people", json=self.tagging_callback) add_tags_response = self.bldr.add_section_field_values_to_record( - self.fake_entity_id, - self.fake_section, - self.fake_field_values + self.fake_entity_id, self.fake_section, self.fake_field_values ) self.assertEqual(add_tags_response, self.fake_tagging) diff --git a/useful_resources/sample_code/ngpvan_sample_printedlist.py b/useful_resources/sample_code/ngpvan_sample_printedlist.py index 2d884b07ae..498737d08b 100644 --- a/useful_resources/sample_code/ngpvan_sample_printedlist.py +++ b/useful_resources/sample_code/ngpvan_sample_printedlist.py @@ -3,20 +3,27 @@ This script pulls turf information (i.e. precinct name, list number, people count, door count, etc.) from a specificed NGP VAN folder and creates a master check list and pdf printouts to circumvent the sometimes lengthy process in VAN. -To use the script, be sure to set your environmental variables for VAN_API_KEY and GOOGLE_DRIVE_CREDENTIALS. -The blog post explaining contextual information for this script can be found here: . -Please also note that due to the inability to test the script, I decided to pare it down. It does not -include turf prioritization, apartment demarcation, and walkability scores as shown in the blog post. + +To use the script, be sure to set your environmental variables for VAN_API_KEY and +GOOGLE_DRIVE_CREDENTIALS. + +The blog post explaining contextual information for this script can be found here: . + +Please also note that due to the inability to test the script, +I decided to pare it down. It does not include turf prioritization, apartment demarcation, +and walkability scores as shown in the blog post. + To execute the script, run: - python3 ngpvan_sample_printedlist.py --van_folder_name="{Name of NGP VAN folder where printed lists are stored}" --gsheet_uri={URI for gsheet where NGP VAN data will be stored}"" + python3 ngpvan_sample_printedlist.py \ + --van_folder_name="{Name of NGP VAN folder where printed lists are stored}" \ + --gsheet_uri="{URI for gsheet where NGP VAN data will be stored}" """ -import pandas as pd from fpdf import FPDF from parsons import VAN, GoogleSheets, Table -import json import click + # ~~~~~~~~~~~~~~ Get Printed and Saved List Info From VAN ~~~~~~~~~~~~~~~~#