Skip to content

Commit 2b38cc6

Browse files
committed
Add try-catch while loops to api calls
1 parent 8264394 commit 2b38cc6

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

project.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ def __init__(self,projection, user):
6565

6666
def get_frequencies(self):
6767
print "Processing User " + self.userName
68-
for comment in self.userObject.get_comments(limit=self.projection.thing_limit):
69-
self.subredditFrequencies.add_frequency(str(comment.subreddit.display_name.strip(' ').lower()), 1.0)
68+
while True:
69+
try:
70+
#for comment in self.userObject.get_comments(limit=100):
71+
for comment in self.userObject.get_comments(limit=self.projection.thing_limit):
72+
self.subredditFrequencies.add_frequency(str(comment.subreddit.display_name.strip(' ').lower()), 1.0)
73+
if str(comment.subreddit.display_name.strip(' ').lower()) is str(self.projection.subreddit.display_name.strip(' ').lower()):
74+
self.projection.totalComments += 1
75+
self.totalComments += 1
76+
break
77+
except:
78+
print "error..."
7079

71-
if str(comment.subreddit.display_name.strip(' ').lower()) is str(self.projection.subreddit.display_name.strip(' ').lower()):
72-
self.projection.totalComments += 1
7380

74-
self.totalComments += 1
7581

7682
class Projection:
7783
def __init__(self, subredditName, thing_limit):
@@ -85,7 +91,12 @@ def __init__(self, subredditName, thing_limit):
8591
self.commentorNames = []
8692

8793
def get_comments(self):
88-
self.comments = list(self.subreddit.get_comments(limit=self.thing_limit))
94+
while True:
95+
try:
96+
self.comments = list(self.subreddit.get_comments(limit=self.thing_limit))
97+
break
98+
except:
99+
print "error..."
89100

90101
def register_subreddit_frequency (self, subredditName, frequency):
91102
if subredditName in self.subredditFrequencies.frequencies:

0 commit comments

Comments
 (0)