Skip to content

Commit f81bb0b

Browse files
author
Konstantinacc
committed
Added comments in handle_library_comment function.
1 parent 99daad6 commit f81bb0b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

codebender_testing/disqus.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,42 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
8989
def handle_library_comment(self, library, current_date, log):
9090
url = '/library/' + library
9191
identifier = 'ident:' + url
92+
9293
if url not in log:
9394
log[url] = {}
9495
try:
9596
log[url]['comment'] = False
97+
98+
""" Returns a Paginator object that matches the desired criteria:
99+
`self.disqus.api.threads.list`: Returns a list containg all urls in which Disqus loaded.
100+
`forum`: Looks up a forum by short name.
101+
`thread`: Looks up a thread by ID BUT you may pass us the 'ident' query type instead of
102+
an ID by including 'forum'. Filters results returned from `self.disqus.api.threads.list`
103+
and returns only those which match `forum` and `thread`.
104+
IMPORTANT: If `thread` is not found, all threads are returned!!!
105+
"""
96106
paginator = disqusapi.Paginator(self.disqus.api.threads.list,
97107
forum=FORUM,
98-
thread=identifier, method='GET')
108+
thread=identifier)
99109
if paginator:
100110
comment_updated = False
101111
new_message = self.messages['library'].replace('TEST_DATE', current_date)
102-
for page in paginator:
103-
post_id, existing_message = self.get_posts(page['id'])
112+
113+
for thread in paginator:
114+
115+
# Check if library has already a comment.
116+
post_id, existing_message = self.get_posts(thread['id'])
117+
118+
#If library already has a comment, update it.
104119
if post_id and existing_message:
105120
log[url]['comment'] = self.update_post(post_id, new_message)
106121
comment_updated = True
107122
break
108123

124+
#If library doesn't have a comment, create it.
109125
if not comment_updated:
110126
log[url]['comment'] = self.create_post(identifier, new_message)
127+
111128
except Exception as error:
112129
print 'Error:', error
113130
log[url]['comment'] = False

0 commit comments

Comments
 (0)