def get(self, screen_name, section="shares"): user = userdb.get_user_by_screen_name(screen_name) if not user: raise tornado.web.HTTPError(404) view = "profile" #section = self.get_argument('section', 'shares') tag = self.get_argument('tag', '') per_page = int(self.get_argument('per_page', 10)) page = int(self.get_argument('page',1)) if section == 'mentions': # get the @ mention list for this user posts = mentionsdb.get_mentions_by_user(screen_name.lower(), per_page, page) elif section =='bumps': posts = postsdb.get_posts_by_bumps(screen_name, per_page, page) else: if tag == '': posts = postsdb.get_posts_by_screen_name(screen_name, per_page, page) else: posts = postsdb.get_posts_by_screen_name_and_tag(screen_name, tag, per_page, page) # also get the list of tags this user has put in tags = tagsdb.get_user_tags(screen_name) self.render('user/profile.html', user=user, screen_name=screen_name, posts=posts, section=section, page=page, per_page=per_page, tags=tags, tag=tag, msg=None, view=view)
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 subscribe_to_all_your_threads(username): account = userdb.get_user_by_screen_name(username) # subscribe this author to all of their previous posts author_posts = postsdb.get_posts_by_screen_name(username, per_page=1000, page=1) for post in author_posts: thread_id = 0 try: # Attempt to create the thread. thread_details = disqus.create_thread(post['title'], post['slug'], account['disqus_access_token']) thread_id = thread_details['response']['id'] except: try: # trouble creating the thread, try to just get the thread via the slug thread_details = disqus.get_thread_details(post.slug) thread_id = thread_details['response']['id'] except: thread_id = 0 if thread_id != 0: # Subscribe a user to the thread specified in response disqus.subscribe_to_thread(thread_id, account['disqus_access_token']) logging.info("subscribed user to %s" % post['title'])
def get(self, screen_name, section="shares"): user = userdb.get_user_by_screen_name(screen_name) if not user: raise tornado.web.HTTPError(404) view = "profile" #section = self.get_argument('section', 'shares') tag = self.get_argument('tag', '') per_page = int(self.get_argument('per_page', 10)) page = int(self.get_argument('page', 1)) if section == 'mentions': # get the @ mention list for this user posts = mentionsdb.get_mentions_by_user(screen_name.lower(), per_page, page) elif section == 'bumps': posts = postsdb.get_posts_by_bumps(screen_name, per_page, page) else: if tag == '': posts = postsdb.get_posts_by_screen_name( screen_name, per_page, page) else: posts = postsdb.get_posts_by_screen_name_and_tag( screen_name, tag, per_page, page) # also get the list of tags this user has put in tags = tagsdb.get_user_tags(screen_name) self.render('user/profile.html', user=user, screen_name=screen_name, posts=posts, section=section, page=page, per_page=per_page, tags=tags, tag=tag, msg=None, view=view)