diff --git a/api/api.py b/api/api.py index d410037..0449ed0 100644 --- a/api/api.py +++ b/api/api.py @@ -129,12 +129,10 @@ class CreateSuggestionBody(BaseModel): title="Email address", description="Email address who is sending email" ) name: str = Field( - title="Name", - description="Name who is sending email", + title="Name", description="Name who is sending email", ) content: str = Field( - title="Email content", - description="Email content with suggestion", + title="Email content", description="Email content with suggestion", ) @@ -271,8 +269,7 @@ async def get_gazettes( description="Number of search results to be skipped in the response.", ), sort_by: SortBy = Query( - SortBy.RELEVANCE, - description="How to sort the search results.", + SortBy.RELEVANCE, description="How to sort the search results.", ), ): gazette_request = GazetteRequest( @@ -362,8 +359,7 @@ async def get_themed_excerpts( description="Number of search results to be skipped in the response.", ), sort_by: SortBy = Query( - SortBy.RELEVANCE, - description="How to sort the search results.", + SortBy.RELEVANCE, description="How to sort the search results.", ), ): themed_excerpt_request = ThemedExcerptRequest( @@ -421,8 +417,7 @@ async def get_available_themes(): ) async def get_available_subthemes( theme: str = Path( - ..., - description="Theme that can be used to search in gazettes by theme.", + ..., description="Theme that can be used to search in gazettes by theme.", ), ): subthemes = app.themed_excerpts.get_available_subthemes(theme) @@ -444,8 +439,7 @@ async def get_available_subthemes( ) async def get_available_entities( theme: str = Path( - ..., - description="Theme that can be used to search in gazettes by theme.", + ..., description="Theme that can be used to search in gazettes by theme.", ), ): entities = app.themed_excerpts.get_available_entities(theme) @@ -504,9 +498,7 @@ async def get_city( ) async def add_suggestion(response: Response, body: CreateSuggestionBody): suggestion = Suggestion( - email_address=body.email_address, - name=body.name, - content=body.content, + email_address=body.email_address, name=body.name, content=body.content, ) suggestion_sent = app.suggestion_service.add_suggestion(suggestion) response.status_code = ( diff --git a/cities/city_access.py b/cities/city_access.py index 1aa3e11..681f61a 100644 --- a/cities/city_access.py +++ b/cities/city_access.py @@ -42,12 +42,7 @@ def __repr__(self): def __hash__(self): return hash( - ( - self.territory_id, - self.territory_name, - self.state_code, - self.level, - ) + (self.territory_id, self.territory_name, self.state_code, self.level,) ) @@ -155,9 +150,7 @@ def create_cities_data_gateway(city_database_file: str) -> CityDataGateway: return CitiesCSVDatabaseGateway(city_database_file) -def create_cities_interface( - data_gateway: CityDataGateway, -) -> CityAccessInterface: +def create_cities_interface(data_gateway: CityDataGateway,) -> CityAccessInterface: if not isinstance(data_gateway, CityDataGateway): raise Exception("Data gateway should implement the CityDataGateway interface") diff --git a/config/config.py b/config/config.py index 0c2bed3..9edc17d 100644 --- a/config/config.py +++ b/config/config.py @@ -53,9 +53,7 @@ def __init__(self): self.gazette_publication_date_field = os.environ.get( "GAZETTE_PUBLICATION_DATE_FIELD", "" ) - self.gazette_scraped_at_field = os.environ.get( - "GAZETTE_SCRAPED_AT_FIELD", "" - ) + self.gazette_scraped_at_field = os.environ.get("GAZETTE_SCRAPED_AT_FIELD", "") self.gazette_territory_id_field = os.environ.get( "GAZETTE_TERRITORY_ID_FIELD", "" ) diff --git a/gazettes/gazette_access.py b/gazettes/gazette_access.py index a22f19d..80f5689 100644 --- a/gazettes/gazette_access.py +++ b/gazettes/gazette_access.py @@ -224,10 +224,7 @@ def build_query( self.add_sorts( query=query, sorts=[ - self.build_sort( - field=self.publication_date_field, - order=order, - ) + self.build_sort(field=self.publication_date_field, order=order,) ], ) @@ -244,12 +241,18 @@ def build_query( field=self.territory_id_field, terms=territory_ids ) published_date_query = self.build_date_range_query( - field=self.publication_date_field, since=published_since, until=published_until + field=self.publication_date_field, + since=published_since, + until=published_until, ) scraped_at_query = self.build_date_range_query( field=self.scraped_at_field, since=scraped_since, until=scraped_until ) - filter_query = [q for q in [territory_query, published_date_query, scraped_at_query] if q is not None] + filter_query = [ + q + for q in [territory_query, published_date_query, scraped_at_query] + if q is not None + ] query["query"] = self.build_bool_query(must=must_query, filter=filter_query) @@ -268,8 +271,7 @@ def build_query( matched_fields=matched_fields, ) self.add_highlight( - query=query, - fields_highlights=[text_highlight], + query=query, fields_highlights=[text_highlight], ) return query diff --git a/index/elasticsearch.py b/index/elasticsearch.py index 49a6d3d..362504e 100644 --- a/index/elasticsearch.py +++ b/index/elasticsearch.py @@ -98,7 +98,7 @@ def build_date_range_query( ) -> Union[Dict, None]: if since is None and until is None: return - + date_range_query = {field: {}} if since is not None: date_range_query[field]["gte"] = since.isoformat() @@ -174,11 +174,7 @@ def add_pagination_fields( class HighlightMixin: - def add_highlight( - self, - query: Dict, - fields_highlights: List[Dict] = [], - ) -> None: + def add_highlight(self, query: Dict, fields_highlights: List[Dict] = [],) -> None: if fields_highlights == []: return diff --git a/main/__main__.py b/main/__main__.py index ca684ef..7865f92 100644 --- a/main/__main__.py +++ b/main/__main__.py @@ -4,9 +4,7 @@ from cities import create_cities_data_gateway, create_cities_interface from config import load_configuration from companies import create_companies_interface -from database import ( - create_companies_database_interface, -) +from database import create_companies_database_interface from gazettes import ( create_gazettes_interface, create_gazettes_data_gateway, diff --git a/themed_excerpts/themed_excerpt_access.py b/themed_excerpts/themed_excerpt_access.py index 13718eb..1383727 100644 --- a/themed_excerpts/themed_excerpt_access.py +++ b/themed_excerpts/themed_excerpt_access.py @@ -293,10 +293,7 @@ def build_query( self.add_sorts( query=query, sorts=[ - self.build_sort( - field=self.publication_date_field, - order=order, - ) + self.build_sort(field=self.publication_date_field, order=order,) ], ) @@ -326,7 +323,9 @@ def build_query( field=self.territory_id_field, terms=territory_ids ) published_date_query = self.build_date_range_query( - field=self.publication_date_field, since=published_since, until=published_until + field=self.publication_date_field, + since=published_since, + until=published_until, ) scraped_at_query = self.build_date_range_query( field=self.scraped_at_field, since=scraped_since, until=scraped_until @@ -339,7 +338,13 @@ def build_query( ) filter_query = [ q - for q in [territory_query, published_date_query, scraped_at_query, entities_query, subthemes_query] + for q in [ + territory_query, + published_date_query, + scraped_at_query, + entities_query, + subthemes_query, + ] if q is not None ] @@ -368,8 +373,7 @@ def build_query( matched_fields=matched_fields, ) self.add_highlight( - query=query, - fields_highlights=[text_highlight], + query=query, fields_highlights=[text_highlight], ) return query @@ -546,8 +550,7 @@ def get_themed_excerpts(self, filters: ThemedExcerptRequest): raise Exception(f"Theme not found.") total_number_excerpts, excerpts = self._data_gateway.get_themed_excerpts( - theme_index=theme_index, - **vars(filters), + theme_index=theme_index, **vars(filters), ) return (total_number_excerpts, [vars(excerpt) for excerpt in excerpts]) @@ -593,8 +596,7 @@ def create_themed_excerpts_query_builder( def create_themed_excerpts_data_gateway( - search_engine: SearchEngineInterface, - query_builder: QueryBuilderInterface, + search_engine: SearchEngineInterface, query_builder: QueryBuilderInterface, ) -> ThemedExcerptDataGateway: if not isinstance(search_engine, SearchEngineInterface): raise Exception(