File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 1
1
from collections import defaultdict
2
2
from datetime import datetime , timedelta
3
3
from typing import Optional
4
+ from time import sleep
4
5
5
6
import requests
6
7
@@ -40,10 +41,17 @@ def read(self, inputs):
40
41
for idx in range (0 , len (mbids ), batch_size ):
41
42
recording_mbids = mbids [idx : idx + batch_size ]
42
43
43
- response = requests .get (
44
- f"https://api.listenbrainz.org/1/feedback/user/{ self .user_name } /get-feedback-for-recordings" ,
45
- params = {"recording_mbids" : "," .join (recording_mbids )}
46
- )
44
+ while True :
45
+ response = requests .get (
46
+ f"https://api.listenbrainz.org/1/feedback/user/{ self .user_name } /get-feedback-for-recordings" ,
47
+ params = {"recording_mbids" : "," .join (recording_mbids )}
48
+ )
49
+ if response .status_code == 429 :
50
+ sleep (2 )
51
+ continue
52
+
53
+ break
54
+
47
55
response .raise_for_status ()
48
56
data = response .json ()["feedback" ]
49
57
if len (data ) == 0 :
Original file line number Diff line number Diff line change 1
1
from collections import defaultdict
2
2
from datetime import datetime , timedelta
3
3
from typing import Optional
4
+ from time import sleep
4
5
5
6
import requests
6
7
@@ -45,6 +46,10 @@ def _fetch_recent_listens_index(self):
45
46
f"https://api.listenbrainz.org/1/user/{ self .user_name } /listens" ,
46
47
params = {"min_ts" : min_ts , "count" : 100 }
47
48
)
49
+ if response .status_code == 429 :
50
+ sleep (2 )
51
+ continue
52
+
48
53
response .raise_for_status ()
49
54
data = response .json ()["payload" ]
50
55
if len (data ["listens" ]) == 0 :
Original file line number Diff line number Diff line change
1
+ from time import sleep
2
+
1
3
import requests
2
4
import ujson
3
5
@@ -40,9 +42,16 @@ def read(self, inputs):
40
42
41
43
self .debug ("- debug %d recordings" % len (recordings ))
42
44
43
- r = requests .post (self .SERVER_URL % len (recordings ), json = data )
44
- if r .status_code != 200 :
45
- raise PipelineError ("Cannot fetch recordings from ListenBrainz: HTTP code %d" % r .status_code )
45
+ while True :
46
+ r = requests .post (self .SERVER_URL % len (recordings ), json = data )
47
+ if r .status_code == 429 :
48
+ sleep (2 )
49
+ continue
50
+
51
+ if r .status_code != 200 :
52
+ raise PipelineError ("Cannot fetch recordings from ListenBrainz: HTTP code %d" % r .status_code )
53
+
54
+ break
46
55
47
56
try :
48
57
rows = ujson .loads (r .text )
You can’t perform that action at this time.
0 commit comments