コード例 #1
0
    def test_should_pprintjson_to_a_specified_file(self):
        obj = {"a": 1}

        with open("test1.json", "a+") as f:
            ppjson(obj, file=f)
            f.seek(0)
            result = f.read()
            self.assertTrue(obj, result)
コード例 #2
0
    def test_should_catch_error_if_file_is_not_atty(self):
        obj = {"a": 1}
        with captured_output() as (out, err):
            with self.assertRaises(Exception) as f:
                ppjson(obj, file="string")

            self.assertTrue(str(f.exception))
            self.assertEqual(out.getvalue(), "")
コード例 #3
0
    def test_should_pprintjson_variable_arguments(self):
        obj1 = {"a": 1}
        obj2 = {"b": 2}

        with captured_output() as (out, err):
            ppjson(obj1, obj2, file=sys.stdout)
            self.assertEqual(
                out.getvalue(),
                dumps(obj1, indent=4) + " " + dumps(obj2, indent=4) + "\n",
            )
コード例 #4
0
def set_vars():
    try:
        global product_instance_dir, json_cnf_fle, cnf, pp, cnf, version
        pp = pprint.PrettyPrinter(indent=3)
        product_instance_dir = path.abspath(path.join(__file__, "../../.."))
        do_read_conf_fle(product_instance_dir + '/.env')  # env agnostic
        env = os.environ['ENV_TYPE']
        version = os.environ['VERSION']

        with open(product_instance_dir + '/cnf/env/' + env +
                  '.env.json') as json_cnf_fle:
            cnf = json.load(json_cnf_fle)
            cnf['env']['VERSION'] = version
            cnf['env']['VER'] = version.replace('.', '')
        ppjson(cnf)

    except (IndexError) as error:
        print("ERROR in set_vars: ", str(error))
        traceback.print_stack()
        sys.exit(1)
コード例 #5
0
 def test_should_not_return_output_if_file_is_none(self):
     obj = {"a": 1}
     with captured_output() as (out, err):
         ppjson(obj, file=None)
         self.assertEqual(out.getvalue(), "")
コード例 #6
0
 def test_should_pprintjson_to_a_tty(self):
     obj = {"a": 1}
     with captured_output() as (out, err):
         ppjson(obj, file=sys.stdout)
         self.assertEqual(out.getvalue(), dumps(obj, indent=4) + "\n")
コード例 #7
0
 def login(self):
     Error.info(f"Iniciando session en Hushmail como [{self.email}]")
     self.session = requests.Session()
     try:
         session_start = self.session.get(self.loginUrlGet)
     except Exception as e:
         Error.e(1, "No es posible hacer la conexion a Hushmail")
         Error.warn(e)
         if self.errorReconect > 5:
             self.errorReconect = 0
             Error.e(1, "SALIENDO DEL SCRIPT".center(50, '.'))
             sys.exit()
         else:
             self.errorReconect += 1
             Error.info("Intentando reconectar".center(50, '.'))
             self.login()
     else:
         Error.executing("Recopilando Headers & Cookies",
                         self.listerrorExecutinModulo)
         soup = BeautifulSoup(session_start.text, 'html.parser')
         Error.executing("Parseando resultado",
                         self.listerrorExecutinModulo)
         form_token = soup.find('input', {'name': 'form_token'})['value']
         Error.executing("Obteniendo form_token para el login",
                         self.listerrorExecutinModulo)
         Error.executing("Aplicando nuevos Headers",
                         self.listerrorExecutinModulo)
         self.session.headers.update({
             "Accept":
             "application/json, text/javascript, */*; q=0.01",
             "Accept-Encoding":
             "gzip, deflate, br",
             "DNT":
             "1",
             "Host":
             "secure.hushmail.com",
             "Origin":
             "https://secure.hushmail.com",
             # "Referer":"https://secure.hushmail.com/preview/hushmail/",
             "Referer":
             self.loginUrlGet,
             "Content-Type":
             "application/x-www-form-urlencoded; charset=UTF-8",
             "X-Hush-Ajax-Start-Time":
             str(int(time.time() * 1000)),
             "X-Requested-With":
             "XMLHttpRequest"
         })
         Error.executing("Construyendo url-encode para el formulario",
                         self.listerrorExecutinModulo)
         dataPost = {
             "form_token": form_token,
             # "form_token":"e1ceed8e70107ef3ee6adb69e3d2cd39_546b90918696",
             "__hushform_extra_fields": "",
             "next_webapp_page": "",
             "hush_domain": "hushmail.com",
             "hush_username": self.email,
             # "hush_username":"******",
             "hush_passphrase": self.password,
             # "hush_passphrase":"edens.123.321",
             "hush_remember_me": "",
             "hush_authcode": "",
             "hush_authenticated": "",
             "hush_customerid": "0000000000000000",
             "processAjax": "authenticationform",
             "formPage": "loginpage",
         }
         try:
             create_request = self.session.post(self.loginUrlPost,
                                                data=dataPost,
                                                allow_redirects=True)
         except Exception as e:
             Error.e(1, "No es posible hacer la conexion a Hushmail")
             if self.errorReconect > 5:
                 self.errorReconect = 0
                 Error.e(1, "SALIENDO DEL SCRIPT".center(50, '.'))
                 sys.exit()
             else:
                 self.errorReconect += 1
                 Error.info("Intentando reconectar".center(50, '.'))
                 self.login()
         else:
             response = create_request.json()
             if response['formValidation']:
                 Error.ok(f"{self.email} Ha iniciado session correctamente")
             else:
                 Error.e(
                     1,
                     f"No fue posible crear la session como [{self.email}]")
                 ppjson(response)
コード例 #8
0
 def checkGenericRequestError(self):
     self.session = requests.Session()
     Error.info("Intentando encontrar solucion a errores")
     formData2 = {
         'email': self.email,
         'password': self.password,
         'username': self.username,
         'first_name': self.nombre,
         'opt_into_one_tap': 'false'
     }
     self.session.headers.update(self.headers)
     self.session.cookies.update(self.cookies)
     Error.executing("Accediendo al attempt", self.listerrorExecutinModulo)
     try:
         check = self.session.post(self.webCreateUrlAttempt,
                                   data=formData2,
                                   allow_redirects=True)
     except Exception as e:
         Error.e(
             1,
             f"No es posible hacer la conexion a {self.listerrorExecutinModulo}"
         )
         Error.warn(e)
         if self.errorReconect > self.errorMaxReconect:
             self.errorReconect = 0
             self.changeProxy()
             self.checkGenericRequestError()
             return False
         else:
             self.errorReconect += 1
             Error.info("Intentando reconectar".center(50, '.'))
             self.checkGenericRequestError()
             return False
     else:
         if check.status_code == 200:
             Error.info(f"Estatus code: {check.status_code}".center(
                 widthCenter, '.'))
             jsoncheck = check.json()
             new_username = jsoncheck["username_suggestions"]
             errorType = jsoncheck["error_type"]
             Error.e(
                 1,
                 f"Tipo de error: {Fore.RED}{errorType}{Style.RESET_ALL}")
             if errorType == 'form_validation_error':
                 if 'errors' in jsoncheck:
                     jsoncheckerrors = jsoncheck['errors']
                     for err in jsoncheckerrors:
                         Error.e(
                             1,
                             f"Error en: [{err}]".center(widthCenter, '-'))
                         if err in ['email', 'username']:
                             for item in jsoncheckerrors[err]:
                                 m = item['message']
                                 c = item['code']
                                 Error.e(
                                     1,
                                     f"[{Fore.RED}{c}{Style.RESET_ALL}]: {m}"
                                 )
                                 if c == 'username_is_taken':
                                     self.username = random.choice(
                                         new_username)
                                     Error.executing(
                                         f"Actualizando username a: {self.username}",
                                         self.listerrorExecutinModulo)
                                     return True
                                 elif c == 'email_is_taken':
                                     self.emailIsTaken()
                                     return True
                 self.postCreateAccount()
             else:
                 Error.e(1, "".center(widthCenter, '-'))
                 ppjson(jsoncheck)
                 Error.e(1, "".center(widthCenter, '-'))
                 return False
         elif check.status_code == 429:
             Error.warn(f"Estatus code: {check.status_code}".center(
                 widthCenter, '.'))
             self.waitrefresh()
             return False
         else:
             Error.warn(check.text)
             time.sleep(10)
     return False
コード例 #9
0
ファイル: test.py プロジェクト: edensfj/botcreatoremail
        'tos_version': 'row',
        'opt_into_one_tap': 'false'
    }
    Error.executing(f"GRNERANDO CUENTA DE INSTAGRAM [{username}] ", ip)
    resp2 = s.post(webCreateUrl, data=formData, allow_redirects=True)
    jsonr = resp2.json()
    Error.executing(resp2.status_code, "STATUS")
    Error.executing(jsonr, "RESPONSE")
    if 'checkpoint_url' in jsonr:
        Error.ok(
            "EXITO: Cuenta creada, Email:{} username:{} password: {}".format(
                email, username, "temp_password"))
        sql = Sql()
        sql.query(
            f"INSERT INTO emails(nombre,email,hasinstagram,istemp) VALUES('{user['fullname']}','{email}','1','1')"
        )
        sql.db.commit()
        idemail = sql.cursor.lastrowid
        usedby = idemail
        payload = {
            "username": username,
            "password": "******",
            "createdby": "0",
            "usedby": usedby,
        }
        sql.createInstagramAccont(**payload)
    ppjson(jsonr)
    sys.exit()
    # timesleep = int(random.randrange(20))
    # time.sleep(3)
コード例 #10
0
ファイル: tojson.py プロジェクト: edensfj/botcreatoremail
        username = "******".join(select) + str(randomNumber) + randomLetters
        fname = select[0]
        lname = select[1]
        fullname = " ".join(select)
        password = hashlib.md5(
            str(str(time.time()) + username).encode('utf-8')).hexdigest()
        Users.append({
            "fname": fname,
            "lname": lname,
            "fullname": fullname,
            "username": username.lower(),
            "password": password,
            "country": "CO",
            "age": random.randrange(18, 50)
        })
ppjson(Users)

# my_data_file = open(file_json)
# nombres = json.loads(my_data_file.read());
# Users = []
# select = random.sample(nombres, 2)
# randomNumber = random.randrange(10,99)
# randomLetters = ''.join(random.choice(string.ascii_lowercase) for i in range(3))
# username = "******".join(select)+str(randomNumber)+randomLetters
# fname = select[0]
# lname = select[1]
# fullname = " ".join(select)
# password =  hashlib.md5(str(str(time.time())+username).encode('utf-8')).hexdigest()
#
#
# Users.append({