Progress: rethinking the implementation

Kelvin Wangonya - May 15 '20 - - Dev Community

Initially, I wanted to have python (somehow) directly manipulate the DOM based on the state of document.monetization.state. I didn't know if it was possible but I figured there must be a way because, well, it's python.

After trying out a couple of ways, I realized it's just not as simple as I thought to access document from python and still keep the project free from a whole bunch of dependencies. As a solution, I think I have to include a small js script to provide an interface between what's going on in the browser and the backend.

I've been a bit hesitant to take this approach because I wanted to keep it all python, but this seems like the best thing to do for now.

While this whole thing can be done much easier in Javascript, I still feel like it's worth providing a python implementation for people who would like to include monetization to their flask/django projects without having to write the javascript themselves.

So, the idea remains the same. I still want to be able to do

from monetize import check_state

@app.route('/monetized')
def monetized_page():
    state = check_state()
    if state == 'started':
        # implement logic to offer monetized content
    else:
        # do something else
Enter fullscreen mode Exit fullscreen mode

It's just how to achieve it that's changing.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player