Skip to content

Commit

Permalink
Correções de formatação de código.
Browse files Browse the repository at this point in the history
Aplicando as correções de código feitas pelo commando black.
  • Loading branch information
jvanz committed Jan 30, 2023
1 parent 62e310a commit aa199f9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 56 deletions.
22 changes: 7 additions & 15 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 = (
Expand Down
11 changes: 2 additions & 9 deletions cities/city_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
)


Expand Down Expand Up @@ -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")

Expand Down
4 changes: 1 addition & 3 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""
)
Expand Down
18 changes: 10 additions & 8 deletions gazettes/gazette_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
],
)

Expand All @@ -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)

Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions index/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions main/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 14 additions & 12 deletions themed_excerpts/themed_excerpt_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
],
)

Expand Down Expand Up @@ -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
Expand All @@ -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
]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit aa199f9

Please sign in to comment.