[Feature]: setup plugin with working metadataTab - #6
Conversation
|
Hello, No luck with either. |
|
Hmm it seems the Replaced the implementation using the standard python library would like to know if it fixes the issue |
| retranslate_placeholder(self, _translate) | ||
|
|
||
| self.pushButton_update_metadataTab.setText( | ||
| _translate("Dialog", "Update Book Metadata") |
| book_name = self.mi.title | ||
| if not book_name: | ||
| QMessageBox.warning( | ||
| self, "Input Error", "The book should have a valid Name" |
There was a problem hiding this comment.
"name" here shouldn't be capitalized}
Same for "error"
| if not bbid: | ||
| continue | ||
| bookTitle = item.get("defaultAlias", {}).get("name", "Unknown") | ||
| bookLang = item.get("defaultAlias", {}).get("language", "eng") |
There was a problem hiding this comment.
This represents the language of the title rather than the language of the edition.
It's a bit confusing, I know, but the book language should be queried from item.get("languages", []) whichj is an array of language codes (there can be more than one, although that is rare)
"languages": [
"eng",
"fra"
],should display "eng, fra" as a composited string
Is there a built-in way to translate those codes to a language name such as "English, French" or something like that?
| self.pushButton_fetch_metadataTab.setEnabled(False) | ||
| self.pushButton_update_metadataTab.setEnabled(False) | ||
| self.stackedWidget_noResults_metadataTab.setCurrentIndex(1) | ||
| self.label_noMetadata_metadataTab_2.setText("Network Error") |
| languages = results.get("languages") or [] | ||
| self.label_data_language_metadataTab.setText( | ||
| ", ".join(languages) if languages else "Unknown" | ||
| ) |
There was a problem hiding this comment.
I see that the languages here are correct, pulled from the languages array and joined with a comma, contrarily to the search results
This probably warrants creating a utility functiion to extract languages and return a string, that can be reused.
| cleaned = release_date.lstrip("+00")[:10] | ||
| parsed = None | ||
| for fmt in ("%Y-%m-%d", "%Y-%m", "%Y"): | ||
| try: | ||
| parsed = datetime.strptime(cleaned, fmt) | ||
| break | ||
| except ValueError: | ||
| pass | ||
| if parsed: | ||
| if fmt == "%Y-%m-%d": | ||
| release_date = parsed.strftime("%B %d, %Y") | ||
| elif fmt == "%Y-%m": | ||
| release_date = parsed.strftime("%B %Y") | ||
| else: | ||
| release_date = str(parsed.year) | ||
| else: | ||
| release_date = release_date.lstrip("+") |
There was a problem hiding this comment.
I think this whole date parsing routine can be improved.
I put together another approach using regepxs to handle the extended date representation (that +/-YY at the beginning, which is not necessarily "+00", although for Editions they should be very rare), and format it, defaulting to a locale-aware date-only format:
https://www.onlineide.pro/playground/share/cf958f35-b91a-412b-9d63-a4c8dd21bab2
That being said, There might be other options like using a library.
| authors.append(name) | ||
|
|
||
| if not authors: | ||
| authors = ["Unknown Author"] |
|
|
||
| release_date = bb_data.get("releaseEventDate") or "" | ||
| if release_date: | ||
| cleaned = release_date.lstrip("+00")[:10] |
There was a problem hiding this comment.
Same comment about dates as above.
Whatever the solution chosen, it should be implemented in a reusable method to avoid code duplication.
|
Hi @MonkeyDo, added the suggested changes. Let me know if there is anything else |
|
Also a point to note: the |
MonkeyDo
left a comment
There was a problem hiding this comment.
For the purposes of reviewing, clumping in 3 PRs into this one made things much more complicated.
I would much, much have prefered that fixes and improivements were applied directly to each PR, especially if the feedback was left in another PR.
Understand that a PR that add 1,488 line sof code and removes 689 lines is absolutely awful to review.
That beign said, I think this is ready to merge.
No description provided.