]>
git.gir.st - subscriptionfeed.git/blob - app/utils/update-subscriptions.py
3 . /opt/yt/venv/bin/activate
11 sys
. path
. insert ( 0 , "/opt/yt/app/" )
12 from common
. common
import *
14 webhook
= cf
[ 'websub' ][ 'public_uri' ]
15 lease
= cf
[ 'websub' ][ 'lease' ]
16 hmackey
= cf
[ 'websub' ][ 'hmac_key' ]
18 with sqlite3
. connect ( cf
[ 'global' ][ 'database' ]) as conn
:
21 SELECT DISTINCT s.channel_id
22 FROM subscriptions AS s LEFT JOIN websub AS w
23 ON s.channel_id = w.channel_id
24 WHERE subscribed_until < datetime('now', '+12 hours')
25 OR subscribed_until IS NULL
26 ORDER BY subscribed_until
29 for ( channel_id
,) in c
. fetchall ():
30 if '-v' in sys
. argv
: sys
. stderr
. write ( f
'updating {channel_id} \n ' )
32 version
, timestamp
, nonce
, sig
= "v1" , int ( time
. time ()), 0 , "x" # TODO:sig,nonce
33 r
= requests
. post ( "https://pubsubhubbub.appspot.com/subscribe" , data
={
34 "hub.callback" : f
" {webhook} /websub/ {version} / {timestamp} / {nonce} / {channel_id} / {sig} " ,
35 "hub.topic" : f
"https://www.youtube.com/xml/feeds/videos.xml?channel_id= {channel_id} " ,
36 # XXX: https://www.youtube.com/xml/feeds/videos.xml?playlist_id=PL...
37 "hub.verify" : "async" , # nonstandard?
38 "hub.mode" : "subscribe" ,
39 "hub.lease_seconds" : lease
,
40 "hub.secret" : hmackey
,
42 if '-v' in sys
. argv
and not r
. ok
: sys
. stderr
. write ( f
'FAILED {channel_id} : {r.text} \n ' )
44 # mark the channel as subscription pending (auto-updates timestamp):
45 # 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.
46 #$dbh->prepare("INSERT OR REPLACE INTO websub (channel_id, pending)
47 # VALUES (?, 1)")->execute($channel_id);