]>
git.gir.st - subscriptionfeed.git/blob - app/update-subscriptions.py
3 . /opt/yt/venv/bin/activate
13 webhook
= cf
[ 'websub' ][ 'public_uri' ]
14 lease
= cf
[ 'websub' ][ 'lease' ]
15 hmackey
= cf
[ 'websub' ][ 'hmac_key' ]
17 with sqlite3
. connect ( cf
[ 'global' ][ 'database' ]) as conn
:
20 SELECT DISTINCT s.channel_id
21 FROM subscriptions AS s LEFT JOIN websub AS w
22 ON s.channel_id = w.channel_id
23 WHERE subscribed_until < datetime('now', '+12 hours')
24 OR subscribed_until IS NULL
25 ORDER BY subscribed_until
28 for ( channel_id
,) in c
. fetchall ():
29 if '-v' in sys
. argv
: sys
. stderr
. write ( f
'updating {channel_id} \n ' )
31 version
, timestamp
, nonce
, sig
= "v1" , int ( time
. time ()), 0 , "x" # TODO:sig,nonce
32 r
= requests
. post ( "https://pubsubhubbub.appspot.com/subscribe" , data
={
33 "hub.callback" : f
" {webhook} /websub/ {version} / {timestamp} / {nonce} / {channel_id} / {sig} " ,
34 "hub.topic" : f
"https://www.youtube.com/xml/feeds/videos.xml?channel_id= {channel_id} " ,
35 # XXX: https://www.youtube.com/xml/feeds/videos.xml?playlist_id=PL...
36 "hub.verify" : "async" , # nonstandard?
37 "hub.mode" : "subscribe" ,
38 "hub.lease_seconds" : lease
,
39 "hub.secret" : hmackey
,
41 if '-v' in sys
. argv
and not r
. ok
: sys
. stderr
. write ( f
'FAILED {channel_id} : {r.text} \n ' )
43 # mark the channel as subscription pending (auto-updates timestamp):
44 # NOTE: the callback happens even before the response of the postf call. we then overwrite the final state with the pending state again, so this is commented out.
45 #$dbh->prepare("INSERT OR REPLACE INTO websub (channel_id, pending)
46 # VALUES (?, 1)")->execute($channel_id);