コード例 #1
0
def compress_image(src_path, dst_path, w=80, h=80):
    print('压缩图片...')
    src_fn_set = set(os.listdir(src_path))
    dst_fn_set = set(os.listdir(dst_path))
    fn_set = src_fn_set - dst_fn_set
    if len(fn_set) == 0:
        print('无可更新图片', end='\n**********\n')
        return

    from PIL import Image
    for fn in fn_set:
        src_ffn = os.path.join(src_path, fn)
        dst_ffn = os.path.join(dst_path, fn)

        larger_img = Image.open(src_ffn)
        small_img = larger_img.resize((w, h), resample=Image.ANTIALIAS)
        small_img.save(dst_ffn)

        print(src_ffn)
        print(dst_ffn)
    print('压缩图片完成', end='\n**********\n')
コード例 #2
0
    def __init__(self, window):

        self.wind = window
        self.wind.title('Vitasis Laboratorio Médico')
        self.wind.configure(background='gray')
        self.wind.geometry('1200x823')
        self.wind.resizable(0, 0)

        #carga de la imagen
        img = Image.open('logo QR.png')
        self._image_logo = ImageTk.PhotoImage(img)
        widget = tk.Label(self.wind, image=self._image_logo).grid(row=0,
                                                                  column=0,
                                                                  sticky=W)

        #Pestañas
        self._tab_control = ttk.Notebook(self.wind)
        self._tab_control.grid(row=1, column=0)
        self.tab1 = tkinter.Frame(self._tab_control, bg='gray')
        self._tab_control.add(
            self.tab1,
            text='Vitasis',
        )

        #contenedor 3 estudios
        frame = LabelFrame(self.tab1,
                           text='Estudios de laboratorio',
                           labelanchor=N)
        frame.grid(row=2, column=0, pady=5, padx=5, ipadx=30, sticky=W)
        frame.configure(background='gray')

        self.menu_desplegable()
        Label(frame, text='Pruebas Clinicas 1', bg='gray').grid(row=1,
                                                                column=0,
                                                                pady=10,
                                                                sticky=W + E)
        self.prueba = tk.StringVar(frame)
        self.prueba.set(
            '---------------------------------------------------------------')
        #pruebas = self.menu_p
        pruebas = ('ANTIDOPING EN ORINA', 'BIOMETRIA HEMATICA COMPLETA BHC',
                   'COPROPARASITOSCOPICO EN SERIE DE 3',
                   'EXAMEN GENERAL DE ORINA', 'ESPERMATOBIOSCOPIA DIRECTA',
                   'EXUDADO FARINGEO CON ANTIBIOGRAMA', 'GLUCOSA DESTROXIS',
                   'GLUCOSA', 'GONADOTROFINA CORIONICA FRACCION BETA',
                   'GRUPO SANGUINEO Y FACTOR RH', 'HEMOGLOBINA GLUCOSILADA',
                   'PAPANICOLAU', 'PRUEBA INMUNOLOGICA DE EMBARAZO',
                   'GLUCOSA,COLESTEROL Y TRIGLICERIDOS',
                   'QUIMICA DE 4 ELEMENTOS', 'QUIMICA DE 5 ELEMENTOS',
                   'QUIMICA DE 6 ELEMENTOS', 'QUIMICA DE 12 ELEMENTOS',
                   'QUIMICA DE 18 ELEMENTOS', 'QUIMICA DE 25 ELEMENTOS',
                   'QUIMICA DE 32 ELEMENTOS', 'REACCIONES FEBRILES',
                   'TAMIZ METABOLICO NEONATAL CON AMINOACIDOS COMPLETO',
                   'TIEMPOS DE COAGULACION TTPA,TP, TS, TT', 'UROCULTIVO',
                   'VDRL', 'VIH PRUEBA DE TAMIZAJE',
                   'PERFIL HORMONAL FEMENINO BASICO',
                   'PERFIL HORMONAL GINECOLOGICO', 'PERFIL LIPIDOS',
                   'PERFIL PRENATAL', 'PERFIL PROSTATICO', 'PERFIL REUMATICO',
                   'PERFIL TIROIDEO COMPLETO')
        self.menu_prueba = tk.OptionMenu(frame, self.prueba,
                                         *pruebas).grid(row=1,
                                                        column=1,
                                                        sticky=W + E,
                                                        pady=10)

        #contenedor desglose de costos
        self.frame5 = LabelFrame(self.tab1,
                                 text='Costo a pagar',
                                 labelanchor=N)
        self.frame5.grid(row=2, column=1, pady=10, padx=5, sticky=N)
        self.frame5.configure(background='gray')

        Label(self.frame5, text=' ', bg='gray').grid(row=1,
                                                     column=1,
                                                     pady=10,
                                                     sticky=W)
        message8 = Label(self.frame5,
                         text='',
                         fg='black',
                         font=('Verdana', 12),
                         bg='gray')
        message8.grid(row=1, column=1, pady=10, padx=10, sticky=W)
        message8['text'] = 'Subtotal'

        Label(self.frame5, text=' ', bg='gray').grid(row=1,
                                                     column=2,
                                                     pady=10,
                                                     sticky=W)
        self.message9 = Label(self.frame5,
                              text='',
                              fg='black',
                              font=('Verdana', 12),
                              bg='gray')
        self.message9.grid(row=1, column=2, pady=10, padx=10, sticky=W)
        self.subtotal = 0
        self.message9['text'] = '$ {}.0'.format(self.subtotal)

        Button(self.frame5, text='Pagar').grid(
            row=6, columnspan=3, pady=10, padx=10, sticky=W +
            E)  #command = self.ventana_paciente command = self.sumas
        Button(self.frame5,
               text='Generar Recibo').grid(row=7,
                                           columnspan=3,
                                           pady=10,
                                           padx=10,
                                           sticky=W +
                                           E)  #command = self.ventana_paciente
コード例 #3
0
def imageRecognition():
    # 图像识别
    path = r"C:\Users\BJB00936\Desktop\钢化膜.jpg"
    image = Image.open(path)
    text = pytesseract.image_to_string(image,lang="chi_sim+eng",config="--psm 6 --oem 3 -c tessedit_char_whitelist=0123456789")
    print(text)
コード例 #4
0
def click():  #function to activate when button clicked
    entered_url = entry.get()

    # Accessing house listing
    try:
        res = requests.get(entered_url)
    except:
        return Label(
            window,
            text=
            "Hmm... Are you sure that was a URL? (Has to start with https://)",
            background='#FBEAEB',
            foreground='#2F3C7E').grid(row=5, column=0)

    Label(window,
          text="Information successfully scraped from ",
          background='#FBEAEB',
          foreground='#2F3C7E').grid(row=5, column=0)
    Label(window, text=entered_url, background='#FBEAEB',
          foreground='#2F3C7E').grid(row=6, column=0)

    # Screenshoting listing
    driver = webdriver.Chrome(
        executable_path='./dependencies/chromedriver/chromedriver.exe')
    driver.get(entered_url)
    driver.save_screenshot("./resources/House.png")

    # Adjusting image for compatibility with excel (replaces screnshoted image with new one, then creates a formatted version with row name)
    old_house_pic = "./resources/House.png"
    house_pic = Image.open(old_house_pic)
    new_house_pic = house_pic.resize((320, 193), Image.ANTIALIAS)
    formatted_house_pic = new_house_pic.convert('RGB')
    formatted_house_pic.save("./resources/formatted_house" +
                             str(sheet.max_row) + ".jpg")
    driver.quit()

    #Scraping all necessary info from pure html
    pure_html = bs4.BeautifulSoup(res.text, "html.parser")
    result = (pure_html.get_text())

    try:
        priceREG = re.compile(r'(\$)(\d+,)?(\d{3},\d{3})(.\d+)?')
        price = priceREG.search(result)
        theprice = (price.group())
    except AttributeError:
        theprice = ('No price found')

    try:
        phoneREG = re.compile(
            r'((\d{3})|(\(\d{3}\)))(\s|\-|\.)(\d{3})(\s|\-|\.)(\d{4})')
        phone = phoneREG.search(result)
        thephone = (phone.group())
    except AttributeError:
        thephone = ('No phone found')

    try:
        addressREG = re.compile(
            r'(\d{1,4})(\s)([a-zA-Z])+(\s)([a-zA-Z]+)(.|,)(\s)([a-zA-Z]+)')
        address = addressREG.search(result)
        theaddress = (address.group())
    except AttributeError:
        theaddress = ('No address found')

    try:
        bedsREG1 = re.compile(
            r'(Bedrooms|beds|bd|bds|bed|bedroom|bedrooms|Bdrms|Bdrm)(:)?(\s)(\d)(\+\d)?'
        )
        beds1 = bedsREG1.search(result)
        thebeds = (beds1.group())
    except AttributeError:
        try:
            bedsREG2 = re.compile(
                r'(\d)((\+)(\d))?(\s)(Bedrooms|beds|bd|bds|bed|bedroom|bedrooms|Bdrms|Bdrm)'
            )
            beds2 = bedsREG2.search(result)
            thebeds = (beds2.group())
        except AttributeError:
            thebeds = ('No beds found')

    try:
        bathsREG1 = re.compile(
            r'(Baths|baths|Bathrooms|bathrooms|bth|Bth|Bath|bath)(:)?(\s)(\d)(\+\d)?'
        )
        baths1 = bathsREG1.search(result)
        thebaths = (baths1.group())
    except AttributeError:
        try:
            bathsREG2 = re.compile(
                r'(\d)((\+)(\d))?(\s)(Baths|baths|Bathrooms|bathrooms|bth|Bth|Bath|bath)'
            )
            baths2 = bathsREG2.search(result)
            thebaths = (baths2.group())
        except AttributeError:
            thebaths = ('No baths found')

    try:
        sqftREG = re.compile(r'(\d)+(\s)((S|s)q(F|f)t|(S|s)q(\.)? (F|f)t)')
        sqft = sqftREG.search(result)
        thesqft = (sqft.group())
    except AttributeError:
        thesqft = ('No sqft found')

    # Saves values as strings (only accepted as so by openpyxl)
    finaladdress = str(theaddress)
    lst_for_house_data = [
        str(theprice),
        str(thesqft),
        str(thebeds),
        str(thebaths),
        str(thephone)
    ]

    # Outputs info to excel (begins with address as this skips 2 rows)
    house_image = openpyxl.drawing.image.Image("./resources/formatted_house" +
                                               str(sheet.max_row) + ".jpg")
    sheet.add_image(house_image, 'A' + str(sheet.max_row + 2))
    sheet.cell(row=(sheet.max_row + 2),
               column=6).font = openpyxl.styles.Font(size=18)
    sheet.cell(row=(sheet.max_row), column=6).value = finaladdress

    # Coninues writing, but through a loop since they all skip one row
    for i in lst_for_house_data:
        sheet.cell(row=(sheet.max_row + 1),
                   column=6).font = openpyxl.styles.Font(size=18)
        sheet.cell(row=(sheet.max_row), column=6).value = i

    try:
        wb.save('./My Houses.xlsx')
        Label(window,
              text="Saved onto My Houses.xlsx",
              background='#FBEAEB',
              foreground='#2F3C7E',
              width=65).grid(row=7, column=0)

    except PermissionError:
        Label(
            window,
            text=
            "Data was not saved onto My Houses.xlsx. Did you close the file before scraping?",
            background='#FBEAEB',
            foreground='#2F3C7E').grid(row=7, column=0)
コード例 #5
0
            window,
            text=
            "Data was not saved onto My Houses.xlsx. Did you close the file before scraping?",
            background='#FBEAEB',
            foreground='#2F3C7E').grid(row=7, column=0)


# Creating excel workbook
wb = openpyxl.Workbook()
sheet = wb.active

# GUI formatting
window = Tk()
window.configure(background='#FBEAEB')
window.title("HouseScrape")
img = Image.open("./resources/houselogo.gif")
window.iconbitmap("./resources/home-146585_1280.ico")
img = img.resize((100, 100), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
Label(window, image=photoImg, background='#FBEAEB').grid(row=0,
                                                         column=0,
                                                         sticky=N)
Label(window,
      text="HouseScrape",
      font=("Arial Rounded MT", 30, "bold"),
      background='#FBEAEB',
      foreground='#2F3C7E').grid(row=1, column=0, sticky=N)
Label(window,
      text="Please enter a URL of an online house listing",
      background='#FBEAEB',
      foreground='#2F3C7E',
コード例 #6
0
def getAsignacionesExcel(request,id_operario=None):
    if(id_operario!='0'):
        operario=Operario.objects.get(Q(id=id_operario))
        asignaciones=AsignacionDet.objects.filter(operario_id=operario.id)
        asigAux={}
        listaAsignaciones=[]
        total=0
        diasLibres=getDiaLibre(id_operario)
        cantAsignaciones=0
        for a in asignaciones:
            cantAsignaciones+=1
            total=total+int(a.totalHoras)


        diaLibre1=diasLibres[0]["nombre"]
        hora=diasLibres[0]["hEntrada"].split(':')
        hora1=hora[0]+':'+hora[1]
        diaLibre2=diasLibres[len(diasLibres)-1]["nombre"]
        hora=diasLibres[len(diasLibres)-1]["hSalida"].split(':')
        hora2=hora[0]+':'+hora[1]


        response = HttpResponse(
            content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        )
        response['Content-Disposition'] = 'attachment; filename={operario}-asignaciones.xlsx'.format(
            operario=str(operario.nombre)+" "+str(operario.apellido) + " - "+str(operario.nroLegajo)
        )
        workbook = Workbook()
        worksheet = workbook.active
        worksheet.title = 'Asignaciones operario - ' + operario.nombre + ' '+operario.apellido+' - '+operario.nroLegajo
        worksheet.row_dimensions[1].height=20
        worksheet.column_dimensions['A'].width=25
        worksheet.column_dimensions['B'].width=20
        worksheet.column_dimensions['C'].width=20
        worksheet.column_dimensions['D'].width=20
        worksheet.column_dimensions['E'].width=25
        worksheet.column_dimensions['F'].width=20
        worksheet.column_dimensions['G'].width=20
        worksheet.column_dimensions['H'].width=20
        worksheet.column_dimensions['I'].width=20
        worksheet.column_dimensions['J'].width=20
        color=PatternFill(start_color='86273e',end_color='86273e',fill_type='solid')

        columns = [
        'Reporte de operario'
        ]
        row_num = 1
        worksheet.row_dimensions[row_num].font=Font(bold=True,color='86273e',size=22)
        worksheet.merge_cells('A1:B2')
        
        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title
        row_num = 2

        worksheet.merge_cells('F1:G3')
        png = r'.\Operarios\static\logo.png'
        img = Image.open(png)
        img = img.resize((220,65),Image.NEAREST)
        img.save(png)        
        img = openpyxl.drawing.image.Image(png)
        worksheet.add_image(img, 'F1')
        worksheet.merge_cells('F4:G4')
        worksheet["F4"]=datetime.today().strftime('%d/%m/%Y')
        worksheet["F4"].font=Font(bold=True)
        worksheet["F4"].alignment=Alignment(horizontal='center')
        
        columns = [
            'Nombre',
            'Apellido',
            'Legajo'
        ]
        row_num += 1

        worksheet.row_dimensions[row_num].font=Font(bold=True,color='86273e')
        worksheet.row_dimensions[row_num].alignment=Alignment(horizontal='center')
        # Assign the titles for each cell of the header
        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title

        row = [
            operario.nombre,
            operario.apellido,
            operario.nroLegajo,
        ]
        row_num += 1
        worksheet.row_dimensions[row_num].alignment=Alignment(horizontal='center')
        for col_num, cell_value in enumerate(row, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = cell_value


        columns = [
        'Día libre inicio',
        'hora',
        'Día libre fin',
        'hora'
        ]
        row_num += 1
        worksheet.row_dimensions[row_num].font=Font(bold=True,color='86273e')
        worksheet.row_dimensions[row_num].alignment=Alignment(horizontal='center')
        
        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title
        
        row = [
            diaLibre1,
            hora1,
            diaLibre2,
            hora2
        ]
        row_num += 1
        worksheet.row_dimensions[row_num].alignment=Alignment(horizontal='center')
        for col_num, cell_value in enumerate(row, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = cell_value
        
        thin_border = Border(left=Side(style='thin'), 
                    right=Side(style='thin'), 
                    top=Side(style='thin'), 
                    bottom=Side(style='thin'))

            
        for j in range(3,7):
            for i in range(1,5):
                worksheet.cell(row=j, column=i).border = thin_border
                worksheet.cell(row=j, column=i).alignment=Alignment(horizontal='center')
                if(j==3 or j==5):
                    worksheet.cell(row=j, column=i).font=Font(bold=True,color='86273e')
        
        worksheet.cell(row=3, column=4).border = None
        worksheet.cell(row=4, column=4).border = None


        columns = []
        row_num += 1
        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title
        
        columns = []
        row_num += 1
        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title

        total=str(total)+" hrs"
        columns = [
            'Total horas asignadas:',
            total
        ]
        row_num += 1
        worksheet["A9"].font=Font(bold=True,size=12,color='86273e')
        worksheet["B9"].font=Font(bold=True,size=12,color='000000')
        worksheet["B9"].alignment=Alignment(horizontal='left')

        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title

        thin_border = Border(left=Side(style='thin'), 
                    right=Side(style='thin'), 
                    top=Side(style='thin'), 
                    bottom=Side(style='thin'))

        

        #Titulos para la tabla
        columns = [
            'Nro',
            'Punto de servicio',
            'Total Horas',
            'Lunes',
            'Martes',
            'Miércoles',
            'Jueves',
            'Viernes',
            'Sábado',
            'Domingo'
        ]
        row_num += 1
        for i in range(1,len(columns)+1):
            worksheet.cell(row=row_num, column=i).border = thin_border
            worksheet.cell(row=row_num, column=i).alignment=Alignment(horizontal='center')
            worksheet.cell(row=row_num, column=i).font=Font(bold=True,color='86273e') 
        for col_num, column_title in enumerate(columns, 1):
            cell = worksheet.cell(row=row_num, column=col_num)
            cell.value = column_title

        i=1
        for a in asignaciones:
            cab=AsignacionCab.objects.get(id=a.asignacionCab_id)
            puntoServ=cab.puntoServicio.NombrePServicio
            if(a.lunEnt and a.lunSal):
                lunes=str(a.lunEnt)+" a "+str(a.lunSal)
            else:
                lunes=""
            if(a.marEnt and a.marSal):
                martes=str(a.marEnt)+" a "+str(a.marSal)
            else:
                martes=""
            if(a.mieEnt and a.mieSal):
                miercoles=str(a.mieEnt)+" a "+str(a.mieSal)
            else:
                miercoles=""
            if(a.jueEnt and a.jueSal):
                jueves=str(a.jueEnt)+" a "+str(a.jueSal)
            else:
                jueves=""
            if(a.vieEnt and a.vieSal):
                viernes=str(a.vieEnt)+" a "+str(a.vieSal)
            else:
                viernes=""
            if(a.sabEnt and a.sabSal):
                sabado=str(a.sabEnt)+" a "+str(a.sabSal)
            else:
                sabado=""
            if(a.domEnt and a.domSal):
                domingo=str(a.domEnt)+" a "+str(a.domSal)
            else:
                domingo=""
            row = [
                i,
                puntoServ,
                a.totalHoras,
                lunes,
                martes,
                miercoles,
                jueves,
                viernes,
                sabado,
                domingo
            ]
            row_num += 1
            

            for col_num, cell_value in enumerate(row, 1):
                cell = worksheet.cell(row=row_num, column=col_num)
                cell.value = cell_value
            i=i+1
            for j in range(1,len(columns)+1):
                worksheet.cell(row=row_num, column=j).border = thin_border
                worksheet.cell(row=row_num, column=j).alignment=Alignment(horizontal='center')    

        workbook.save(response)
        return response