hadynz / obsidian-kindle-plugin

Sync your Kindle notes and highlights directly into your Obsidian vault
MIT License
922 stars 52 forks source link

[BUG] "lastAnnotatedDate" marked as "Invalid date" #186

Closed jmMeessen closed 2 years ago

jmMeessen commented 2 years ago

Bug descriptions

When using the French (FR) Amazon, the lastAnnotatedDate in the header is only filled with "Invalid date", hinting that there was a date parsing error (probably due to the exotic date format.

The error is with all the books.

Method of syncing

To Reproduce

Steps to reproduce the behaviour:

  1. Run sync with Amazon FR configured
  2. Open a book and examine header
  3. lastAnnotatedDate: Invalid date
  4. No error spotted in Developer Tools console

Expected behaviour

Would have expected to have `lastAnnotatedDate: 2022-08-31

Screenshots

Metadata

jmMeessen commented 2 years ago

If I look at the interactive annotation page, the date is looking like this: Consulté pour la dernière fois le mardi août 30, 2022. I am too unfamiliar with node to effectively help on my own. Please guide me.

hadynz commented 2 years ago

Thanks for raising this issue @jmMeessen

The parsing of annotation date current does not work for all locales. I've only made it work with locales that I have access to. This is a good opportunity to fix this for French.

Can you send me a screenshot of the last annotated date in your online Amazon Kindle reader, and maybe a couple of other examples of how the last annotated dates look like - if you can also tell me what they be converted to in DD/MM/YYYY then you would've made my life much easier.

Otherwise - je parle francais en peu, and I have Google translate to figure it all out!

jmMeessen commented 2 years ago

😄 @hadynz

Screenshot 2022-09-02 at 08 28 36

The above renders as

---
kindle-sync:
  bookId: '62657'
  title: >-
    The Culture Map (INTL ED): Decoding How People Think, Lead, and Get Things
    Done Across Cultures (English Edition)
  author: "Par\_: Erin Meyer"
  asin: B06XCJ125R
  lastAnnotatedDate: Invalid date
  bookImageUrl: 'https://m.media-amazon.com/images/I/81Xhfeh2StL._SY160.jpg'
  highlightsCount: 76
---
# The Culture Map
## Metadata
* Author: [[Par : Erin Meyer]]
* ASIN: B06XCJ125R
* Reference: https://www.amazon.com/dp/B06XCJ125R
* [Kindle link](kindle://book?action=open&asin=B06XCJ125R)

## Highlights
“Speaking of cultural differences leads us to stereotype and therefore put individuals in boxes with ‘general traits.’ — location: [271](kindle://book?action=open&asin=B06XCJ125R&location=271) ^ref-59296

---
If you go into every interaction assuming that culture doesn’t matter, your default mechanism 

FYI: "Consulté pour la dernière fois le mardi août 30, 2022" means "Last viewed on Tuesday August 30, 2022". Note that the way Amazon displays the french date is not correct. One would expect "mardi 30 août 2022". This can mislead "localed" date parsers.

Changing the URL to "...&language-en-US" does not change the way the date is rendered.

Also note the glitch with author's parsing. "Par" means "By". I planned to open a separate ticket for it (unless you want to piggyback it on this ticket).

I understand the difficulty for you to deal with these localization issues. So don't hesitate to ask me so that you can move forward. Didn't see any tracing option. But I am just Java and Golang literate so I might have overlooked it.

hadynz commented 2 years ago

Any chance you can also inspect and share with me the DOM for the section that contains the last annotated date?

Two examples should do.

jmMeessen commented 2 years ago

Hello,

(not sure that I correctly understood your wish)

This is the DOM part for the date shown:

<span id="kp-notebook-annotated-date">mardi août 30, 2022</span>

<span id="kp-notebook-annotated-date">vendredi juillet 8, 2022</span>

I think that I looked at the correct field as in the source of the plugin I found: const lastAnnotatedDate = $('[id^="kp-notebook-annotated-date"]', bookEl).val();

The format used is <dayOdWeek> <month> <day>, <year>, which as said is not a standard french date string.

jmMeessen commented 2 years ago

For the author parsing glitch, I believe I found the location of the culprit (scrapeBooks.ts, line 43)

The .replace does not work in French as "Par: " is used instead of "By:"

Do you want an other ticket for that one ?

hadynz commented 2 years ago

This has been fixed and released in version 1.6.7.

Give it and try and let me know if it works for you as expected.

jmMeessen commented 2 years ago

Hello @hadynz ,

It works (at least on my configuration 😄 ):

Thanks a lot for the quick response and guidance. It was fun and instructive to help you fix this issue.

/- Jmm

---
kindle-sync:
  bookId: '62657'
  title: >-
    The Culture Map (INTL ED): Decoding How People Think, Lead, and Get Things
    Done Across Cultures (English Edition)
  author: Erin Meyer
  asin: B06XCJ125R
  lastAnnotatedDate: '2022-09-03'
  bookImageUrl: 'https://m.media-amazon.com/images/I/81Xhfeh2StL._SY160.jpg'
  highlightsCount: 76
---
# The Culture Map
## Metadata
* Author: [Erin Meyer](https://www.amazon.com/Erin-Meyer/e/B00HOFLR1K/ref=dp_byline_cont_ebooks_1)
* ASIN: B06XCJ125R
* Reference: https://www.amazon.com/dp/B06XCJ125R
* [Kindle link](kindle://book?action=open&asin=B06XCJ125R)