def post(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_vote = False if not can_vote: msg = {'error': 'You have already upvoted this post.'} else: user = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post['votes'] += 1 post['voted_users'].append(user['user']) postsdb.save_post(post) msg = {'votes': post['votes']} # send email notification to post author author = userdb.get_user_by_screen_name(post['user']['username']) if 'email_address' in author.keys(): subject = "[#usvconversation] @%s just bumped up your post: %s" % (self.current_user, post['title']) text = "Woo!\n\n%s" % template_helpers.post_permalink(post) logging.info('sent email to %s' % author['email_address']) self.send_email('*****@*****.**', author['email_address'], subject, text) self.api_response(msg)
def get(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_vote = False if not can_vote: msg = {'error': 'You have already upvoted this post.'} else: user = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post['votes'] += 1 post['voted_users'].append(user['user']) postsdb.save_post(post) msg = {'votes': post['votes']} # send email notification to post author author = userdb.get_user_by_screen_name(post['user']['username']) if 'email_address' in author.keys(): subject = "[#usvconversation] @%s just bumped up your post: %s" % (self.current_user, post['title']) text = "Woo!\n\n%s" % template_helpers.post_permalink(post) logging.info('sent email to %s' % author['email_address']) self.send_email('*****@*****.**', author['email_address'], subject, text) self.api_response(msg)
def get(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {"error": "You must be logged in to bump.", "redirect": True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post["voted_users"]: if u["username"] == self.current_user: can_vote = False if not can_vote: msg = {"error": "You have already upvoted this post."} else: user = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post["votes"] += 1 post["voted_users"].append(user["user"]) postsdb.save_post(post) msg = {"votes": post["votes"]} # send email notification to post author author = userdb.get_user_by_screen_name(post["user"]["username"]) if "email_address" in author.keys(): subject = "[#usvconversation] @%s just bumped up your post: %s" % ( self.current_user, post["title"], ) text = "Woo!\n\nhttp://%s" % template_helpers.post_permalink(post) logging.info("sent email to %s" % author["email_address"]) self.send_email("*****@*****.**", author["email_address"], subject, text) self.api_response(msg)
def get_thread_details(post): api_link = 'https://disqus.com/api/3.0/threads/details.json' info = { 'api_key': settings.get('disqus_public_key'), 'thread:link': template_helpers.post_permalink(post), 'forum': settings.get('disqus_short_code'), } return do_api_request(api_link, 'GET', info)
def subscribe_to_all_your_threads(username): account = userdb.get_user_by_screen_name(username) # todo: get disqus_user_id # temp: nick's ID if 'disqus' not in account: print 'ERROR: no disqus user ID' return print 'subscribing to disqus threads for user %s' % username #make sure all your threads are registered w disqus posts = postsdb.get_posts_by_screen_name(username, per_page=25, page=1) for post in posts: print template_helpers.post_permalink(post) if 'disqus_thread_id_str' not in post.keys() or post.get( 'disqus_thread_id_str') == "": thread_details = create_thread(post, account['disqus']['access_token']) try: thread_id = thread_details['response']['id'] except: thread = get_thread_details(post) thread_id = thread['response']['id'] post['disqus_thread_id_str'] = thread_id postsdb.save_post(post) subscribe_to_thread( post.get('disqus_thread_id_str'), account['disqus']['access_token']) ''' threads = get_all_threads(account['disqus']['user_id'])['response'] my_threads = [] for thread in threads: if 'link' not in thread or thread['link'] is None: continue if thread['link'].find('http://localhost') >= 0: continue my_threads.append(thread) if 'disqus' in account: for thread in my_threads: subscribe_to_thread(thread['id'], account['disqus']['access_token']) print 'subscribed to thread: %s' % thread['title'] return ''' return
def subscribe_to_all_your_threads(username): account = userdb.get_user_by_screen_name(username) # todo: get disqus_user_id # temp: nick's ID if 'disqus' not in account: print 'ERROR: no disqus user ID' return print 'subscribing to disqus threads for user %s' % username #make sure all your threads are registered w disqus posts = postsdb.get_posts_by_screen_name(username, per_page=25, page=1) for post in posts: print template_helpers.post_permalink(post) if 'disqus_thread_id_str' not in post.keys() or post.get('disqus_thread_id_str') == "": thread_details = create_thread(post, account['disqus']['access_token']) try: thread_id = thread_details['response']['id'] except: thread = get_thread_details(post) thread_id = thread['response']['id'] post['disqus_thread_id_str'] = thread_id postsdb.save_post(post) subscribe_to_thread(post.get('disqus_thread_id_str'), account['disqus']['access_token']) ''' threads = get_all_threads(account['disqus']['user_id'])['response'] my_threads = [] for thread in threads: if 'link' not in thread or thread['link'] is None: continue if thread['link'].find('http://localhost') >= 0: continue my_threads.append(thread) if 'disqus' in account: for thread in my_threads: subscribe_to_thread(thread['id'], account['disqus']['access_token']) print 'subscribed to thread: %s' % thread['title'] return ''' return
def create_thread(post, access_token): api_link = 'https://disqus.com/api/3.0/threads/create.json' url = "http://" + template_helpers.post_permalink(post) thread_info = { 'forum': settings.get('disqus_short_code'), 'title': post['title'].encode('utf-8'), 'identifier':post['slug'], 'url': url, 'api_secret':settings.get('disqus_secret_key'), 'api_key': settings.get('disqus_public_key'), 'access_token': access_token } return do_api_request(api_link, 'POST', thread_info)
def create_thread(post, access_token): api_link = 'https://disqus.com/api/3.0/threads/create.json' url = template_helpers.post_permalink(post) thread_info = { 'forum': settings.get('disqus_short_code'), 'title': post['title'].encode('utf-8'), 'identifier':post['slug'], 'url': url, 'api_secret':settings.get('disqus_secret_key'), 'api_key': settings.get('disqus_public_key'), 'access_token': access_token } return do_api_request(api_link, 'POST', thread_info)