Пример #1
0
    def createVagrantFile(self, path):
        with open("./data/.VagrantFile", 'r') as f:
            data = f.read()

        data = data.replace('~basebox~', self.xmlData.baseBox)

        # Replace files with files
        m = re.search('\~files\~\\n(.*)\\n.*\~files\~', data)
        fileConfig = m.group(1)
        fileConfigScript = ''
        for _file in self.xmlData.files:
            if (_file.src[0] == '/'):
                prefix = 'files'
            else:
                prefix = 'files/'
            fileConfigScript += fileConfig.replace(
                '~src~', prefix + _file.src).replace('~dest~', _file.dest) + "\n"
        data = data.replace(m.group(0), fileConfigScript)

        # Replace scripts with scripts
        m = re.search('\~shell\~\\n(.*)\\n.*\~shell\~', data)
        scriptConfig = m.group(1)
        scriptConfigScript = ''
        for _script in self.xmlData.scripts:
            if (_script[0] == '/'):
                prefix = 'files'
            else:
                prefix = 'files/'
            fileConfigScript += fileConfig.replace(
                '~src~', prefix + _script) + "\n  "
        data = data.replace(m.group(0), scriptConfigScript)

        with open(path + "/Vagrantfile", 'w') as f:
            f.write(data)
Пример #2
0
    def modifyVagrantFile(self, path, hostname):
        with open(path, 'r') as f:
            data = f.read()

        data = data.replace(
            '~hostname~', hostname.replace('_', '.') + '.' + self.domain)
        data = data.replace('~private_ips~', self.privateIP)
        with open(path, 'w') as f:
            f.write(data)
Пример #3
0
def criaDataFrame(lista0, lista1, lista2, lista3, lista4, lista5, lista6,
                  lista7, lista8, lista9, lista10):
    df = pd.DataFrame({
        "Data": lista0,
        "NumeroDoPremio": lista1,
        "Premio": lista2,
        "Dezenas": lista3,
        "Numero": lista4,
        "Certificado": lista5,
        "Nome": lista6,
        "Endereço": lista7,
        "Bairro": lista8,
        "Cidade": lista9,
        "PontoDeVenda": lista10
    })

    df.reset_index()
    df.to_csv(path_or_buf=criacsv(data.replace(" ", " _")))
    lista0.clear()
    lista1.clear()
    lista2.clear()
    lista3.clear()
    lista4.clear()
    lista5.clear()
    lista6.clear()
    lista7.clear()
    lista8.clear()
    lista9.clear()
    lista10.clear()
Пример #4
0
 def run(self):
     steps = []
     for index, step in enumrate(self.testcase['step']):
         try:
             url = self.elements['baseurl']['url'] + self.elements[
                 step['element']]['url']
             sort = self.elements[step['element']]['type']
             step['element'] = url.strip()
             if step['data']:
                 step['data'] = replace(str(step['data']))
             result_json = getattr(httpcaps,
                                   'http_requests')(step, self.junit, sort)
             if result_json['score'] != 'Pass':
                 self.step_fail += 1
             steps.append(result_json)
         except Exception as e:
             step['score'] = 'Fail'
             step['_resultinfo'] = 'exception: %s' % e
             self.step_error += 1
             logger.info(step)
             self.junit.failure('testdot:' + step['testdot'] + '-' +
                                'step:' + step['no'] + '-' + 'element:' +
                                step['element'] + '-' + 'error:%s' % e)
             self.error_detail += step['testdot'] + '--' + '{}'.format(e)
             steps.append(step)
             logger.error('error:interface and element not found%s' % e)
             logger.error('error:%s' % e)
     self.junit.suite(self.step_error, self.step_fail, len(self.testcase),
                      '')
     self.junit.settime()
     #记录生成的测试结果,生成测试报告excel版本
     self.testcase['step'] = steps
     return self.testcase
Пример #5
0
def raspa():
    listaSorteios = []
    time.sleep(5)
    print("DATAAAAAAAA: ", data)

    listaDeSorteios = []
    for i in range(4):
        divSorteio = driver.find_element_by_xpath(
            "/html/body/div[1]/div/div/article/div/div[1]/div[2]/div/div/div/div/div/div/div[1]/div[2]"
        )
        divSorteio = divSorteio.get_attribute('outerHTML')
        divSorteio = BeautifulSoup(divSorteio, 'html.parser')
        # print(divSorteio)
        listaDeSorteios.append(divSorteio)

    for i in range(int(len(listaDeSorteios))):
        print(len(listaDeSorteios))
        listaContemplados = []
        dezenas = []

        sorteio = listaDeSorteios[i]
        numeroDoPremio = sorteio.h4.text

        premio = sorteio.find('div', class_='row row-bufferTop10').div.p.text
        dezenasSorteadas = sorteio.findAll('span',
                                           class_='numberDicker pull-left')
        contemplados = sorteio.findAll(
            'div', class_='col-md-6 col-sm-6 col-xs-12 contemplated')

        print(
            '\n**********************************************************************************\n'
        )
        print(numeroDoPremio)
        print(premio)
        for i in range(len(dezenasSorteadas)):
            dezenas.append(dezenasSorteadas[i].text)
        print('Dezenas Soreteadas: ', dezenas)

        for k in range(len(contemplados)):
            informacoes = contemplados[k].ul.findAll('li')
            #nome = informacoes[2].text
            numero = informacoes[0].text
            certificado = informacoes[1].strong.text
            nome = informacoes[2].text
            endereco = informacoes[3].text
            bairro = informacoes[4].text
            cidade = informacoes[5].strong.text
            pontoDeVenda = informacoes[6].strong.text

        if pontoDeVenda == '':
            pontoDeVenda = "null"

        numeroDoPremioS.append(numeroDoPremio)
        premioS.append(premio)

        strDezenas = ' '.join(e for e in dezenas)
        print(strDezenas)
        dezenasSorteadaS.append(strDezenas)

        dataS.append(data)
        numeroS.append(numero)
        certificadoS.append(certificado)
        nomeS.append(nome)
        enderecoS.append(endereco)
        bairroS.append(bairro)
        cidadeS.append(cidade)
        pontoDeVendaS.append(pontoDeVenda)

        print(
            "Contemplado Número: {}\nCertificado: {}\nNome: {}\nEndereço: {}\nBairro: {}\nCidade: {}\nPonto de venda: {}\n"
            .format(numero, certificado, nome, endereco, bairro, cidade,
                    pontoDeVenda))

        contemplado = {
            "Numero": numero,
            "Certificado": certificado,
            "Nome": nome,
            "Endereço": endereco,
            "Bairro": bairro,
            "Cidade": cidade,
            "PontoDeVenda": pontoDeVenda
        }
        listaContemplados.append(contemplado)

    sorteio = {
        "Data": data,
        "NumeroDoPremio": numeroDoPremio,
        "Premio": premio,
        "Dezenas": dezenas,
        "Contemplados": listaContemplados
    }

    listaSorteios.append(sorteio)

    serilaized = json.dumps(listaSorteios, indent=3, ensure_ascii=False)
    jsonarq = criajsonarq(data.replace(" ", "_"))
    jsonarq.write(serilaized)
    jsonarq.close()

    print("Largura das listas: \n" + "dataS: {}\n".format(len(dataS)) +
          "numeroDoPremioS: {}\n".format(len(numeroDoPremioS)) +
          "premioS: {}\n".format(len(premioS)) +
          "dezenasSorteadaS: {}\n".format(len(dezenasSorteadaS)) +
          "certificadoS: {}\n".format(len(certificadoS)) +
          "nomeS: {}\n".format(len(nomeS)) +
          "bairroS: {}\n".format(len(bairroS)) +
          "cidadeS: {}\n".format(len(cidadeS)) +
          "pontoDeVendaS: {}\n".format(len(pontoDeVendaS)))

    criaDataFrame(dataS, numeroDoPremioS, premioS, dezenasSorteadaS, numeroS,
                  certificadoS, nomeS, enderecoS, bairroS, cidadeS,
                  pontoDeVendaS)
Пример #6
0
    def onMessage(self, mid, author_id, message_object, thread_id, thread_type,
                  ts, metadata, msg, **kwargs):
        # self.markAsDelivered(author_id, thread_id)
        # self.markAsRead(author_id)
        # self.setTypingStatus
        print thread_type
        user = client.fetchUserInfo(author_id)[author_id]
        print user.gender
        if message_object.text is not None:
            print("{} send message to {}: {}".format(
                user.first_name.encode("utf-8"), thread_id,
                message_object.text.encode('utf-8')))
            if "-rm" in message_object.text and thread_type.name == "GROUP":
                print "ID"
                print message_object.mentions[0].thread_id
                uid = message_object.mentions[0].thread_id
                client.removeUserFromGroup(user_id=uid, thread_id=thread_id)
                return

            if message_object.text.lower() in Key_stop:
                if message_object.text == "-stop":
                    self.sendMessage(" Bot đã dừng",
                                     thread_id=thread_id,
                                     thread_type=thread_type)
                else:
                    if user.gender == FEMALE:
                        self.sendMessage("Yêu " +
                                         user.first_name.encode("utf-8") +
                                         " Ahihi",
                                         thread_id=thread_id,
                                         thread_type=thread_type)
                    else:
                        self.sendMessage(user.name.encode("utf-8") +
                                         " tao không gay nhé",
                                         thread_id=thread_id,
                                         thread_type=thread_type)
                BlockUser.append(thread_id)
                if thread_id in Success:
                    Success.remove(thread_id)
                return
            if message_object.text.lower() in Key_restart:
                if message_object.text == "-restart":
                    self.sendMessage("Đã khởi động lại bot",
                                     thread_id=thread_id,
                                     thread_type=thread_type)
                else:
                    self.sendMessage("Đạt ghét " +
                                     user.first_name.encode("utf-8") +
                                     " rồi đấy",
                                     thread_id=thread_id,
                                     thread_type=thread_type)
                if thread_id in BlockUser:
                    BlockUser.remove(thread_id)
                else:
                    Success.append(thread_id)
                return

        if author_id != self.uid:
            if message_object.text is not None:
                #dự báo thời tiết
                if "-wt" in message_object.text:
                    WT = "====================="
                    message_object.text = message_object.text.replace(
                        "-wt", "")
                    WT = WT + "\nBạn vừa tra cứu thời tiết ở " + message_object.text.encode(
                        "utf-8")
                    link = 'https://api.trolyfacebook.com/thoitiet/?noidung={{%s}}' % (
                        message_object.text.encode('utf-8'))
                    print link
                    response = urllib.urlopen(link)
                    json1 = json.loads(response.read())
                    arr = json1["messages"]
                    for i in arr:
                        if i != arr[0]:
                            WT = WT + "\n" + i['text'].encode('utf-8')
                    WT = WT + "\n====================="
                    print WT
                    self.sendMessage(WT,
                                     thread_id=thread_id,
                                     thread_type=thread_type)
                    return
            if message_object.text.lower() == '-help':
                self.sendMessage(guide,
                                 thread_id=thread_id,
                                 thread_type=thread_type)
                return
            if thread_id in BlockUser:
                print "Block"
                return
            if (thread_type.name == "USER" or thread_id in Success):
                if message_object.text is not None:
                    link = 'http://api.simsimi.com/request.p?key=bb18d9b6-e162-4e26-820b-fe9657924d9e&lc=vn&ft=11.0&text=' + message_object.text.encode(
                        'utf-8')
                    response = urllib.urlopen(link)
                    json1 = json.loads(response.read())
                    # print json1
                    if json1["result"] == 100:
                        messtesst = json1["response"].encode('utf-8')
                    else:
                        i = random.randint(0, len(data.arrEmoji) - 1)
                        messtesst = data.arrEmoji[i]
                        print data.arrEmoji
                    messtesst = data.replace(messtesst)
                    if thread_id in GuileUser:
                        messtesst = messtesst
                    else:
                        messtesst = messtesst + guide
                        GuileUser.append(thread_id)
                    # log.info("Message from {} in {} ({}) with: {}!".format(author_id, thread_id, thread_type.name, message_object.text.encode('utf-8')))
                    # print thread_type.name
                    self.sendMessage(messtesst,
                                     thread_id=thread_id,
                                     thread_type=thread_type)
                    pass
                else:
                    type_mess = data.check_type(msg)
                    log.debug(type_mess)
                    try:
                        if message_object.sticker is not None:
                            # print "stcker"
                            i = random.randint(0, len(data.arrstickerID) - 1)
                            self.send(
                                Message(sticker=Sticker(data.arrstickerID[i])),
                                thread_id=thread_id,
                                thread_type=thread_type)
                            return
                    except KeyError:
                        pass
                    try:
                        if type_mess == IMG_TYPE:
                            # print "image"
                            i = random.randint(0, len(data.arrImageLink) - 1)
                            client.sendLocalImage(data.arrImageLink[i],
                                                  message=Message(text='hehe'),
                                                  thread_id=thread_id,
                                                  thread_type=thread_type)
                            return
                        elif type_mess == GIF_TYPE:
                            client.sendRemoteImage(
                                'https://media.giphy.com/media/lGAfVlN0gat4A/giphy.gif',
                                message=Message(text='Heyyyyy!!!'),
                                thread_id=thread_id,
                                thread_type=thread_type)
                            return
                            pass
                        else:
                            client.sendRemoteImage(
                                'https://media.giphy.com/media/lGAfVlN0gat4A/giphy.gif',
                                message=Message(text='Heyyyyy!!!'),
                                thread_id=thread_id,
                                thread_type=thread_type)
                            pass
                    except KeyError:
                        pass
                    self.sendMessage(messtesst,
                                     thread_id=thread_id,
                                     thread_type=thread_type)
                    pass