File tree 2 files changed +20
-11
lines changed
2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 75
75
api_comments = cache [user_name ]['response' ]
76
76
else :
77
77
# Make API request for user comments
78
- url = f'https://api.pushshift.io/reddit/comment/search?html_decode=true&after=0&author={ user_name } &size=500'
79
- try :
80
- with requests .Session () as session :
81
- response = session .get (url )
82
- # Add a sleep of 7 seconds after each API request
83
- time .sleep (7 )
84
- api_comments = response .json ()['data' ]
85
- except (requests .exceptions .RequestException , json .JSONDecodeError ) as e :
86
- print (
87
- f"Error occurred while making the API request: { e } " )
88
- api_comments = []
78
+ url = f'https://api.pushshift.io/reddit/comment/search?author={ user_name } &size=250'
79
+ retries = 4
80
+ for i in range (retries ):
81
+ try :
82
+ with requests .Session () as session :
83
+ response = session .get (url )
84
+ # Add a sleep of 7 seconds after each API request
85
+ time .sleep (7 )
86
+ api_comments = response .json ()['data' ]
87
+ break
88
+ # Add 3 retries
89
+ except (requests .exceptions .RequestException , json .JSONDecodeError ) as e :
90
+ if i == retries - 1 :
91
+ print (
92
+ f"Error occurred while making the API request: { e } " )
93
+ api_comments = []
94
+ else :
95
+ print (
96
+ f"Retrying API request. Attempt { i + 1 } of { retries } ." )
97
+ time .sleep (10 )
89
98
90
99
# Store response in cache
91
100
cache [user_name ] = {
You can’t perform that action at this time.
0 commit comments