File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88import json
99import os
10+ import time
1011import typing
1112from itertools import batched
1213
1617from user_agent import user_agent
1718
1819
19- def fetch_drupal_nodes (nids : list [str ]) -> list [drupal .Node ]:
20+ def fetch_drupal_nodes (nids : list [str ], retry = True ) -> list [drupal .Node ]:
2021 """
2122 Fetches a node from drupal.org by its id
2223 """
@@ -27,6 +28,13 @@ def fetch_drupal_nodes(nids: list[str]) -> list[drupal.Node]:
2728
2829 resp = requests .get (url , headers = {'user-agent' : user_agent })
2930
31+ if retry and resp .status_code == 429 :
32+ seconds = int (resp .headers .get ('Retry-After' , 0 ))
33+ print (f' |* (waiting { seconds } seconds before retrying)' )
34+ time .sleep (seconds )
35+
36+ return fetch_drupal_nodes (nids , retry = False )
37+
3038 if resp .status_code == 200 :
3139 items = typing .cast (drupal .ApiResponse [drupal .Node ], resp .json ())['list' ]
3240
You can’t perform that action at this time.
0 commit comments