# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():


import tweepy
import app.basic
import settings
from lib import userdb
          'user_id': '',
          'screen_name': '',
          'key': auth.access_token.key
        }

        # check if we have this user already or not in the system
        user = userdb.get_user_by_screen_name(screen_name)
        if user:
            # set the cookies based on account details
            self.set_secure_cookie("user_id_str", user['user']['id_str'])
            self.set_secure_cookie("username", user['user']['screen_name'])
            if 'email_address' not in user or ('email_address' in user and user['email_address'] == ''):
                bounce_to = '/user/%s/settings?1' % screen_name
        else:
            # need to create the account (so get more details from Twitter)
            auth = tweepy.OAuthHandler(consumer_key, consumer_secret, secure=True)
            api = tweepy.API(auth)
            user = api.get_user(screen_name)
            access_token['user_id'] = user.id
            access_token['screen_name'] = user.screen_name
            user_data = {
              'auth_type': 'twitter',
              'id_str': user.id_str,
              'username': user.screen_name,
              'fullname': user.name,
              'screen_name': user.screen_name,
              'profile_image_url': user.profile_image_url,
              'profile_image_url_https': user.profile_image_url_https,
            }
            # now save to mongo

# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():


# Path: app/twitter.py
import tweepy
import app.basic
import settings
from lib import userdb

          'user_id': '',
          'screen_name': '',
          'key': auth.access_token.key
        }

        # check if we have this user already or not in the system
        user = userdb.get_user_by_screen_name(screen_name)
        if user:
            # set the cookies based on account details
            self.set_secure_cookie("user_id_str", user['user']['id_str'])
            self.set_secure_cookie("username", user['user']['screen_name'])
            if 'email_address' not in user or ('email_address' in user and user['email_address'] == ''):
                bounce_to = '/user/%s/settings?1' % screen_name
        else:
            # need to create the account (so get more details from Twitter)
            auth = tweepy.OAuthHandler(consumer_key, consumer_secret, secure=True)
            api = tweepy.API(auth)
            user = api.get_user(screen_name)
            access_token['user_id'] = user.id
            access_token['screen_name'] = user.screen_name
            user_data = {
              'auth_type': 'twitter',
              'id_str': user.id_str,
              'username': user.screen_name,
              'fullname': user.name,
              'screen_name': user.screen_name,
              'profile_image_url': user.profile_image_url,
              'profile_image_url_https': user.profile_image_url_https,
            }
            # now save to mongo

            userdb.create_new_user(user_data, access_token)