fgebhart / zeit-on-tolino

Service to auto-upload the ZEIT 🗞 e-paper to your tolino cloud library 📚
MIT License
14 stars 23 forks source link

add option not to assert that the title was found #50

Closed Dronakurl closed 5 months ago

Dronakurl commented 5 months ago

Thank you again for this great code. I want to reuse this for another project to use the tolino upload functionality. Sometimes, there are special characters in the title, like ampersands &, and this always throws an error as the & are somehow masked in the html code of the site. It would be great if it could be an option (set by a secret) to disable the assert

For interest, this is the code to use zeit-on-tolino as a package for tolino upload:

    epub_filename = "path/to/epub/file"
    title = "great story & cool characters"
    sys.path.insert(0, "./zeit-on-tolino/")
    env_vars = importlib.import_module("zeit_on_tolino.env_vars")
    tolino = importlib.import_module("zeit_on_tolino.tolino")
    web = importlib.import_module("zeit_on_tolino.web")
    env_vars.verify_env_vars_are_set()
    env_vars.verify_configured_partner_shop_is_supported()
    webdriver = web.get_webdriver()
    tolino._login(webdriver)
    tolino._upload(webdriver, epub_filename, title)
    webdriver.quit()

My other project uses this to pull bedtime stories from a public website and put them as epub on my tolino. I asked the owner of the website if I could publish the code and they declined, so I want to respect that and use it only for me personally.

fgebhart commented 5 months ago

Hi and thanks for the pro-active contribution.

However, I tend to prefer to keep the functionality of this application to the minimum required functionality and avoid adding code that is not strictly needed. I anyway have very little time for maintaining OSS so I want to avoid introducing technical dept which needs to revisited later on again.

The suggested approach introduces complexity that is not really needed from the perspective of zeit-on-tolino. However, maybe we can think of an approach that modifies zeit-on-tolino in way that it does not increase complexity, but at the same time allows you to achieve your goal. How about one of the following approaches:

  1. sanitize the epub name we assert for. If we can figure out which special characters are removed or which modification is applied to the epub name in the HTML representation, we could potentially apply it to the epub name which we assert for. E.g. remove ampersands before the assertion, etc... That might pave the way for your goal and might make the code of zeit-on-tolino even more robust.
  2. Raise specific Exception instead of assertion: Instead of the assertion, we could raise an specific exception which could potentially be caught in your consume code downstream. However, the assertion could probably also be caught, couldn't it?
  3. Extract tolino upload functionality to separate library: To be honest, I also thought about other use cases where I would have liked to re-use the upload functionality to tolino from this repo. I know this is somehow overkill for your proposed change, but yet wanted to mention it here, because we could of course think about forking this repo and publishing the upload functionality to e.g. PyPI. Subsequently, I could imaging that the generic upload code would likely be easier for reuse in other projects.

Let me know what you think. Feel free to open a issue to discuss in more detail.

Dronakurl commented 5 months ago

It is embarrassing: I didn't think about catching the assertion error. That's an easy fix. I also thought about number 3: Would you be interested, if I look into this? It is sad, that there is no other way to upload to tolino than by selenium.

fgebhart commented 5 months ago

I didn't think about catching the assertion error. That's an easy fix.

Happy to hear. Should indeed be an easy fix :slightly_smiling_face:

I also thought about number 3: Would you be interested, if I look into this?

Yes, certainly. Feel free to give it a try. I'm happy to provide guidance and support (if not too much) in case needed. As mentioned, feel free to open a dedicated issue for it, if you want. In my mind the target should be a standalone repo which publishes the tolino upload functionality to PyPI. If this is achieved, I could refactor the zeit-on-tolino repo and reduce the number of lines quite a bit.

It is sad, that there is no other way to upload to tolino than by selenium.

Indeed. A documented API would make things much easier. However, that is not very common these days. One could of course think about reverse-engineering their API and try communicating with it directly, but I did not want to go down that rabbit hole.