Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on client.py example #8

Open
elyase opened this issue Mar 21, 2021 · 1 comment
Open

Clarification on client.py example #8

elyase opened this issue Mar 21, 2021 · 1 comment

Comments

@elyase
Copy link

elyase commented Mar 21, 2021

Hi, thanks a lot for the library! I am trying to use the subscriber example and being new to websub I am a bit lost on what the different urls or concepts refer to. Taking as example the towardsdatascience blog on Medium I have several urls:

Mediums WebSub endpoint: https://medium.superfeedr.com
Callback url (where client.py is running): http://967560ffa8a4.ngrok.io
Blog url (is this the topic?): https://towardsdatascience.com/

Could you clarify which variables in client.py correspond to the above URLs?

PD: can I assume that anytime a new article is published on that blog the on_topic_change endpoint will run? Also do I need to do something to stay subscribed forever or do I need to run a cron job to renew?

@marten-de-vries
Copy link
Owner

You can indeed take client_example.py as a starting point. In your case, app.config['SERVER_NAME'] = '967560ffa8a4.ngrok.io'. Yes, you'll get notified of changes using on_topic_change. I'd also monitor on_success and on_error. The default example uses a discovery mechanism to find the hub url and topic url, but it appears that won't work with towarddatascience.com, as it doesn't include the required metadata in its html. So you need to specify these manually, e.g.:

# actual subscription - only needs to run once.
subscriber.subscribe(hub_url='https://medium.superfeedr.com', topic_url='https://towardsdatascience.com/')

I'm not sure about the topic url either, as discovery won't work here. Medium should be able to tell you what it is or should have documented that somewhere. The blog url is a reasonable guess though.

Yes, you need to run the following function every once in a while. If you don't, the hub will drop your subscription after a while:

def cleanup_and_renew_all():
    subscriber.cleanup()
    # 100 days, to make sure every single subscription is renewed
    subscriber.renew_close_to_expiration(24 * 60 * 60 * 100)

You can for example do that using celery, but your cron job approach could work as well I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants