Skip to content

Commit

Permalink
A couple of fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
murchik committed Jun 10, 2022
1 parent 3296c96 commit 19fc0f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
9 changes: 6 additions & 3 deletions adapters/spreadsheet_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ def convert_lng(self, longitude: str) -> str:
return self._convert_number(longitude)

def convert_organizations(self, organizations: str) -> List[str]:
return [organizations]
return organizations.split(', ')

def convert_categories(self, organizations: str) -> List[str]:
return [organizations]
def convert_categories(self, categories: str) -> List[str]:
return categories.split(', ')

def convert_tags(self, tags: str) -> List[str]:
return tags.split(', ')

@staticmethod
def _convert_number(number: str) -> str:
Expand Down
13 changes: 12 additions & 1 deletion repositories/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def close_file(file: TextIO):
file.close()


def convert_list(data: list) -> str:
return ','.join(data)


@dataclass
class CSVRepository:

Expand All @@ -28,13 +32,20 @@ class CSVRepository:
close_file: Callable = close_file

def write(self, entries: List[PointOfInterest]) -> List[PointOfInterest]:
converters = {
list: convert_list,
}
fieldnames = list(PointOfInterest.schema()["properties"].keys())
file = self.open_file(self.settings.output_file)

writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
for entry in entries:
writer.writerow(entry.dict())
row = {
k: converters.get(type(v), lambda x: x)(v)
for k, v in entry.dict().items()
}
writer.writerow(row)

self.close_file(file)

Expand Down
1 change: 0 additions & 1 deletion scraping/spiders/moldova_dopomoga.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def parse_details(details: str, city: str = None) -> Tuple[str, str]:
address = strip_punctuation(parts[0])
return name, address or name


parts = details.split(",", 1)
if len(parts) == 1:
value = clean(parts[0])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_convert_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def test_spreadsheet_data_conversion():
result = usecase.convert_spreadsheet("some-id")
csv = FILE_VALUES[0]
expected_row = 'The Ukrainian House,Poland,Warsaw,' \
'"ul. Zamenhofa 1, 00-153",[\'Accommodation\'],' \
'[\'Fundacja “Nasz Wybór”\'],Crisis support center,' \
'"ul. Zamenhofa 1, 00-153",Accommodation,' \
'Fundacja “Nasz Wybór”,Crisis support center,' \
'52.24734033,20.9964833,(+48) 727 805 764 ,' \
'[email protected],,,,' \
'"Monday: 09:00–19:00\nTuesday: 09:00–19:00\n' \
'Wednesday: 09:00–19:00\nThursday: 09:00–19:00\n' \
'Friday: 09:00–19:00\nSaturday: 09:00–17:00\n' \
'Sunday: Closed\n",[],,True,True'
'Sunday: Closed\n",,,True,True'

# TODO: verify city translation

Expand Down

0 comments on commit 19fc0f0

Please sign in to comment.