noembryo / KoHighlights

KOHighlights is a utility for viewing KOReader's highlights and/or export them to simple text, html, csv or markdown files.
MIT License
128 stars 5 forks source link

Can't export to csv #19

Closed Tokariew closed 1 year ago

Tokariew commented 2 years ago

Python 3.10 on Linux When choosing to export to csv i get following error:

Traceback (most recent call last):
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/secondary.py", line 362, in on_export_btn_clicked
    self.base.on_export()
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/main.py", line 2178, in on_export
    if self.save_sel_highlights():          # combine to one file
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/main.py", line 2433, in save_sel_highlights
    text += get_csv_row(data) + "\n"
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/main.py", line 103, in get_csv_row
    value = data[key].replace('"', '""')
AttributeError: 'int' object has no attribute 'replace'
Traceback (most recent call last):
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/secondary.py", line 362, in on_export_btn_clicked
    self.base.on_export()
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/main.py", line 2178, in on_export
    if self.save_sel_highlights():          # combine to one file
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/main.py", line 2433, in save_sel_highlights
    text += get_csv_row(data) + "\n"
  File "/media/hdds/download/KoHighlights.v1.4.4.0.PySide2/main.py", line 103, in get_csv_row
    value = data[key].replace('"', '""')
AttributeError: 'int' object has no attribute 'replace'

Probably page key is understood as int so as quick fix i used str(data[key]).replace('"', '""') to fix issue for me

noembryo commented 2 years ago

Nope, there must be something else.

I tried to reproduce it but I can't. Used 2.7 and 3.7 on windows, but I don't know about 3.10 changing something about the strings..

All the values that data contains are strings: https://github.com/noembryo/KoHighlights/blob/efeb8235bc1ac1c7b0811268e597aae7c6acdc6e/main.py#L2455-L2472

Strange.. :thinking:

Tokariew commented 2 years ago

There is no problem when exporting from books tab, but from highlights section. analyze_high is not called from HIGHLIGHTS_VIEW path here: https://github.com/noembryo/KoHighlights/blob/efeb8235bc1ac1c7b0811268e597aae7c6acdc6e/main.py#L2171-L2206

save_sel_highlights is not going into export so not going into save_multi_files/save_merged_file which call get_item_data which call analyze_high

noembryo commented 2 years ago

There is no problem when exporting from books tab, but from highlights section.

Now you're saying.. :stuck_out_tongue:

Well, there was a big refactoring in this version and I was curious of what it will pop from it.. :smile: You can change: https://github.com/noembryo/KoHighlights/blob/efeb8235bc1ac1c7b0811268e597aae7c6acdc6e/main.py#L1429 to highlight["page"] = str(page), but I have to check if there is a problem elsewhere.. Thank you for the heads up.. :+1:

noembryo commented 1 year ago

Fixed in 1.5.0.0