def __init__(self, debug=False, IGDataPath=None):

        self.debug = None
        self.IGDataPath = None
        self.username = None
        self.uuid = None
        self.waterfall_id = None
        self.token = None
        self.userAgent = None
        self.settings = None
        self.proxy = None  # Full Proxy
        self.proxyHost = None  # Proxy Host and Port
        self.proxyAuth = None  # Proxy User and Pass

        self.username = ''
        self.debug = debug
        self.uuid = SignatureUtils.generateUUID(True)
        self.waterfall_id = SignatureUtils.generateUUID(True)

        if IGDataPath is not None:
            self.IGDataPath = IGDataPath
        else:
            self.IGDataPath = os.path.join(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'data'), '')

        self.userAgent = 'Instagram ' + Constants.VERSION + ' Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)'
    def usernameSuggestions(self, email, name):
        data = json.dumps(
            OrderedDict([
                ('name', SignatureUtils.generateUUID(True)),
                ('waterfall_id', SignatureUtils.generateUUID(True)),
                ('email', email),
                ('_csrftoken', 'missing'),
            ]))

        return UsernameSuggestionsResponse(
            self.request('accounts/username_suggestions/',
                         SignatureUtils.generateSignature(data))[1])
    def checkEmail(self, email):

        data = json.dumps(
            OrderedDict([
                ('qe_id', SignatureUtils.generateUUID(True)),
                ('waterfall_id', SignatureUtils.generateUUID(True)),
                ('email', email),
                ('_csrftoken', 'missing'),
            ]))

        return CheckEmailResponse(
            self.request('users/check_email/',
                         SignatureUtils.generateSignature(data))[1])
    def createAccount(self, username, password, email, name=''):
        """
        Register account.
        :type username: str
        :param username:
        :type password: str
        :param password:
        :type email: str
        :param email:

        :rtype: object
        :return: Registration data
        """

        token = self.getCsfrtoken()
        data = json.dumps(
            OrderedDict([
                ('allow_contacts_sync', 'true'),
                ('phone_id', self.uuid),
                ('_csrftoken', token),
                ('username', username),
                ('first_name', name),
                ('guid', self.uuid),
                ('device_id',
                 SignatureUtils.generateDeviceId(
                     hashlib.md5(username + password).hexdigest())),
                ('email', email),
                ('force_sign_up_code', ''),
                ('waterfall_id', self.waterfall_id),
                ('qs_stamp', ''),
                ('password', password),
            ]))

        result = self.request('accounts/create/',
                              SignatureUtils.generateSignature(data))
        header = result[0]
        response = AccountCreationResponse(result[1])

        if response.isAccountCreated():
            self.username_id = response.getUsernameId()
            self.settings.set('username_id', self.username_id)
            match = re.search(r'^Set-Cookie: csrftoken=([^;]+)', header,
                              re.MULTILINE)
            token = match.group(1) if match else ''
            self.settings.set('token', token)

        return response
    def checkUsername(self, username):
        """
        Checks if the username is already taken (exists).
        :type username: str
        :param username:
        :rtype: object
        :return: Username availability data
        """
        data = json.dumps(
            OrderedDict([
                ('_uuid', self.uuid),
                ('username', username),
                ('_csrftoken', 'missing'),
            ]))

        self.username = username
        self.settings = Settings(
            os.path.join(self.IGDataPath, self.username,
                         'settings-' + username + '.dat'))
        return CheckUsernameResponse(
            self.request('users/check_username/',
                         SignatureUtils.generateSignature(data))[1])