ephes / kptncook

Fetch receipts from kptncook API and export them to mealie or paprika
MIT License
42 stars 4 forks source link

Error while backup favorites #39

Closed BigDi closed 2 months ago

BigDi commented 5 months ago

Get a traceback while backuping my 1086 favorites.

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ C:\Python311\Lib\site-packages\kptncook__init__.py:167 in backup_kptncook_favorites │ │ │ │ 164 │ │ sys.exit(1) │ │ 165 │ │ │ 166 │ fs_repo = RecipeRepository(settings.root) │ │ ❱ 167 │ fs_repo.add_list(recipes) │ │ 168 │ rprint(f"Added {len(recipes)} recipes to local repository") │ │ 169 │ │ 170 │ │
UnicodeEncodeError: 'charmap' codec can't encode character '\u202f' in position 829203: character maps to

Kadz93 commented 3 months ago

super quick fix, i hope somebody sees it lol @ephes @alexdetsch @luebbert42

in repository.py add utf8 encodings in the functions:

you can do it in your local code @BigDi

ephes commented 2 months ago

Well, pydantic deliberately returns a unicode string when models.model_dump_json() is called. And calling write on a file opened in text mode should do the right thing on your operating system. Maybe your default encoding is something like cp1252?

Hmm, maybe it's enough just to overwrite the operating system default by calling:

        with self.path.open("w", encoding="utf-8") as f:
            f.write(models.model_dump_json())

This is still normal text mode, but would overwrite the default encoding and use utf-8. Can you try this and tell me if it works on windows?

Kadz93 commented 2 months ago

I can confirm that the additional encoding solves the problem on windows.

ephes commented 2 months ago

Cool! I'll released 0.0.21 containing the fix.