henrydatei / wikifolio-api

A Python API-Wrapper for the unofficial wikifolio API
GNU General Public License v3.0
17 stars 4 forks source link

Init does not seem to work anymore #6

Closed FabianFaP closed 1 year ago

FabianFaP commented 1 year ago

Good evening,

first of all, thanks a lot for your effort to generate and maintain this nice and useful api. Unfortunately, it seems that the init-function does not work anymore since last week. The returned json from the request now only seems to be {'returnUrl': '/de/de/blog'}. Did you also observe this behavior, or am I doing something wrong?

henrydatei commented 1 year ago

This is new to me, I’ll check this in the next days

FabianFaP commented 1 year ago

@henrydatei, I just had another look at the problem, and it seems that it luckily is not a big deal. There is actually no problem with the principal login request, only with the determination of the wikifolio id in _get_wikifolio_id. The reason is that apparently some not correctly escaped ampersands (&) have been added on the wikifolio pages. This can simply be fixed by:

diff --git a/python/wikifolio-api/wikifolio.py b/python/wikifolio-api/wikifolio.py
index 0a951719..047839d8 100644
--- a/python/wikifolio-api/wikifolio.py
+++ b/python/wikifolio-api/wikifolio.py
@@ -50,7 +50,8 @@ class Wikifolio:
             cookies=self.cookie,
         )
         r.raise_for_status()
-        html = etree.fromstring(r.text)
+        save_text = r.text.replace ('&', '&')
+        html = etree.fromstring(save_text)
         result = json.loads(html.xpath('//*[@id="__NEXT_DATA__"]/text()')[0])
         self.wikifolio_id = result["props"]["pageProps"]["data"]["wikifolio"]["id"]
         self.rawData = result#

With this small change, everything works properly again.

quantomas commented 1 year ago

It's correct: Wikifolio has added an ad window (german text containing the "&") a few day ago. I have solved the issue in the similar way as @FabianFaP. I can make a PR if you wish :)

henrydatei commented 1 year ago

Yes, please do make a PR and test it, then it's less work for me :smile:

FabianFaP commented 1 year ago

@quantomas and @henrydatei that sounds great, thanks a lot for the quick responses! @quantomas thanks for making the PR, if you need any support with that just let me know.

quantomas commented 1 year ago

Yes, please do make a PR and test it, then it's less work for me 😄

I don't need to test. I've been using the new "version" for several days for my "tasks". Everything is fine, because the problem is exactly identified : german unallowed special char "&" 😀 . PR will be made soon...