From fb6323e5ff6f71c221c29a513801c544fb9dec2b Mon Sep 17 00:00:00 2001 From: elliott Date: Wed, 30 Dec 2020 19:06:50 +0000 Subject: [PATCH] Ran black --- bin/bop_custom | 4 +++- bin/bop_download_data | 4 +++- lib/bankofparliament/convert.py | 14 ++++++++------ lib/bankofparliament/download.py | 11 +++++++++-- lib/bankofparliament/extraction.py | 17 +++++++++++++---- lib/bankofparliament/graphdb.py | 4 +++- lib/bankofparliament/relationships/base.py | 1 - .../relationships/relationships.py | 4 +++- 8 files changed, 42 insertions(+), 17 deletions(-) diff --git a/bin/bop_custom b/bin/bop_custom index 8b26989..dfa6d0c 100755 --- a/bin/bop_custom +++ b/bin/bop_custom @@ -22,7 +22,9 @@ if __name__ == "__main__": default=False, ) - parser.add_argument("-o", "--output", help="Output file", action="store", default=None) + parser.add_argument( + "-o", "--output", help="Output file", action="store", default=None + ) args = parser.parse_args() diff --git a/bin/bop_download_data b/bin/bop_download_data index bbffaae..b8e70c2 100755 --- a/bin/bop_download_data +++ b/bin/bop_download_data @@ -28,7 +28,9 @@ if __name__ == "__main__": action="store_true", default=False, ) - parser.add_argument("-o", "--output", help="Ouptut Path", action="store", default=None) + parser.add_argument( + "-o", "--output", help="Ouptut Path", action="store", default=None + ) args = parser.parse_args() timestamp = datetime.datetime.now().strftime("%Y%m%d") diff --git a/lib/bankofparliament/convert.py b/lib/bankofparliament/convert.py index 17a57d9..3d95d62 100755 --- a/lib/bankofparliament/convert.py +++ b/lib/bankofparliament/convert.py @@ -157,7 +157,7 @@ def convert_commons_members_interests(self): target="House of Commons", text=["Member of the House of Commons"], link=DATA_PARLIAMENT_LINK_URL.format(member["@Member_Id"], "contact"), - amount=self.get_house_of_commons_salary() + amount=self.get_house_of_commons_salary(), ) # government relationship @@ -245,7 +245,7 @@ def convert_lords_members_interests(self): target="House of Lords", text=["Member of the House of Lords"], link=DATA_PARLIAMENT_LINK_URL.format(member["@Member_Id"], "contact"), - amount=self.get_house_of_lords_salary(member) + amount=self.get_house_of_lords_salary(member), ) # government relationship @@ -321,9 +321,7 @@ def convert_spads(self): relationship_type="advisor_to", source=name, target=resolved_employer, - text=[ - "An advisor to {}".format(resolved_employer) - ], + text=["An advisor to {}".format(resolved_employer)], link=SPADS_URL, ) self.add_relationship( @@ -422,7 +420,11 @@ def add_government_relationship(self, member): source=member["DisplayAs"], relationship_type="member_of", target="Her Majesty's Government", - text=["Employed as {} for Her Majesty's Government".format(post["Name"])], + text=[ + "Employed as {} for Her Majesty's Government".format( + post["Name"] + ) + ], amount=self.get_government_salary(post), link=DATA_PARLIAMENT_LINK_URL.format( member["@Member_Id"], "contact" diff --git a/lib/bankofparliament/download.py b/lib/bankofparliament/download.py index e2721b1..94de1d5 100755 --- a/lib/bankofparliament/download.py +++ b/lib/bankofparliament/download.py @@ -11,7 +11,12 @@ # local libs from .utils import get_request -from .constants import DATA_PARLIAMENT_QUERY_URL, THEYWORKFORYOU_QUERY_URL, HEADERS, SPADS_URL +from .constants import ( + DATA_PARLIAMENT_QUERY_URL, + THEYWORKFORYOU_QUERY_URL, + HEADERS, + SPADS_URL, +) # third party libs import scraperwiki @@ -82,7 +87,9 @@ def get_spads_pdf(self): else: self.logger.warning("Failed to download special advisors pdf") else: - self.logger.debug("Special advisors pdf already downloaded: {}".format(self.spads_path)) + self.logger.debug( + "Special advisors pdf already downloaded: {}".format(self.spads_path) + ) def get_theyworkforyou_quota(self): """Log the current theyworkforyou api quota""" diff --git a/lib/bankofparliament/extraction.py b/lib/bankofparliament/extraction.py index de68642..3c1424e 100755 --- a/lib/bankofparliament/extraction.py +++ b/lib/bankofparliament/extraction.py @@ -87,7 +87,7 @@ def merge_entities(self, entities, new): new_name = new_entity["name"] new_aliases = new_entity["aliases"].lower().split(";") - filt = (entities["name"] == new_name) + filt = entities["name"] == new_name existing_entities = entities.loc[filt] if len(existing_entities): @@ -98,7 +98,9 @@ def merge_entities(self, entities, new): new_entities.append(new_entity.to_dict()) if len(new_entities): - entities = pandas.concat([entities, pandas.DataFrame(new_entities)], ignore_index=True) + entities = pandas.concat( + [entities, pandas.DataFrame(new_entities)], ignore_index=True + ) return entities @@ -127,12 +129,19 @@ def extract_entities_from_relationships(self): ) continue - if relationship["source"] == "UNKNOWN" and relationship["target"] == "UNKNOWN": + if ( + relationship["source"] == "UNKNOWN" + and relationship["target"] == "UNKNOWN" + ): # family lobbyist resolved_source = self.get_target_from_previous_relationship(index) if resolved_source: relationship["source"] = resolved_source - relationship["text"] = relationship["text"].lower().replace(resolved_source.lower(), "") + relationship["text"] = ( + relationship["text"] + .lower() + .replace(resolved_source.lower(), "") + ) elif relationship["source"] == "UNKNOWN": resolved_source = self.get_missing_source_entity(relationship) diff --git a/lib/bankofparliament/graphdb.py b/lib/bankofparliament/graphdb.py index b023a31..ef1cce6 100644 --- a/lib/bankofparliament/graphdb.py +++ b/lib/bankofparliament/graphdb.py @@ -18,7 +18,9 @@ class GraphDB: """Generates neo4j database""" - def __init__(self, host, port, user, password, entities, relationships, limit, logger): + def __init__( + self, host, port, user, password, entities, relationships, limit, logger + ): """Initialise the neo4j graphdb class""" self.logger = logger self.host = host diff --git a/lib/bankofparliament/relationships/base.py b/lib/bankofparliament/relationships/base.py index df28fa9..01bf9f2 100644 --- a/lib/bankofparliament/relationships/base.py +++ b/lib/bankofparliament/relationships/base.py @@ -546,7 +546,6 @@ def find_alias_from_text( ) return entity - alias_entity_types = ( alias_entity_types if alias_entity_types else self.ALIAS_ENTITY_TYPES ) diff --git a/lib/bankofparliament/relationships/relationships.py b/lib/bankofparliament/relationships/relationships.py index bcdfa4f..5c5e3bb 100644 --- a/lib/bankofparliament/relationships/relationships.py +++ b/lib/bankofparliament/relationships/relationships.py @@ -213,7 +213,9 @@ def solve(self): elif self.entity_type == "union": entity = self.find_alias_from_text( - text=entry, alias_entity_types=["union", "person"], prefered_entity_types=["union"] # accounting for bug + text=entry, + alias_entity_types=["union", "person"], + prefered_entity_types=["union"], # accounting for bug ) if entity: self.extracted_entities.append(entity)