Skip to content

Commit

Permalink
Merge pull request #94 from akretion/feat/geodis_no_accents
Browse files Browse the repository at this point in the history
Geodis Don't send utf8 in EDI anymore
  • Loading branch information
hparfr authored Mar 7, 2018
2 parents 331ca1f + a758d0a commit b840d2f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Roadmap / TODO:
- Support additionnal methods of api
- Write tests

# 0.3.3 2018-02-19
- Geodis force ASCII conversion for EDI.

# 0.3.2 2018-02-06
- Geodis fix missing CTA segment
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.3.3
32 changes: 30 additions & 2 deletions roulier/carriers/geodis/geodis_transport_edi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def parse_lines(lines):
return "\n".join([parse_segment(segment) for segment in lines])

def sanitize(token):
# replace escapable chars by space
# remove accents and replace escapable chars by space
# because, replacing "'" by "?'"
# increase length of the token
# which is limited by 35
Expand All @@ -63,7 +63,35 @@ def sanitize(token):
.replace("'", " ")
.replace("+", " ")
.replace(":", " ")
)
# quick and dirty replacement
# of common accentued chars in french
# because geodis don't handle well utf8
# TODO: put it in api coerce
.replace(u"é", "e")
.replace(u"è", "e")
.replace(u"ë", "e")
.replace(u"ê", "e")
.replace(u"ô", "o")
.replace(u"ï", "i")
.replace(u"ö", "o")
.replace(u"à", "a")
.replace(u"â", "a")
.replace(u"ç", "c")
.replace(u"û", "u")
.replace(u"ù", "u")
.replace(u"É", "E")
.replace(u"È", "E")
.replace(u"Ë", "E")
.replace(u"Ê", "E")
.replace(u"Ô", "O")
.replace(u"Ï", "I")
.replace(u"Ö", "O")
.replace(u"À", "A")
.replace(u"Â", "A")
.replace(u"Ç", "C")
.replace(u"Û", "U")
.replace(u"Ù", "U")
).encode('ascii', 'ignore') # cut remaining chars
return sanitized

return parse_lines(arr)

0 comments on commit b840d2f

Please sign in to comment.