Exemple #1
0
 def get_workbooks(self):
     if self.temp_path is None:
         return
     filenames = []
     for name in os.listdir(self.temp_path):
         d = name.split('-',1)
         d.append(name)
         filenames.append(d)
     filenames.sort()
     for i,filename,pathname in filenames:
         yield (
             # We currently don't open with on_demand=True here
             # as error filters should be lastish in the chain
             # so there's not much win.
             # However, if we did, getting rid of the temp dirs
             # becomes a problem as, on Windows, they can't be
             # deleted until the xlrd.Book object is done with
             # and we don't know when that might be :-(
             xlrd.open_workbook(
                 os.path.join(self.temp_path,pathname),
                 formatting_info=1,
                 on_demand=False,
                 ragged_rows=True
                 ),
             filename
             )
Exemple #2
0
 def get_workbooks(self):
     """
     If the data to be processed is not stored in files or if
     special parameters need to be passed to :func:`xlrd.open_workbook`
     then this method must be overriden.
     Any implementation must return an iterable sequence of tuples.
     The first element of which must be an :class:`xlrd.Book` object and the
     second must be the filename of the file from which the book
     object came.
     """
     for path in self.get_filepaths():
         yield (
             xlrd.open_workbook(
                 path,
                 formatting_info=1,
                 on_demand=True,
                 ragged_rows=True),
             os.path.split(path)[1]
             )
Exemple #3
0
    msg = MIMEMultipart()
    msg['From'] = send_from
    msg['To'] = send_to
    msg['Subject'] = unicode(subject, 'utf-8')

    msg.attach(MIMEText(text))

    with open(files, "rb") as fil:
        part = MIMEApplication(fil.read(), Name=basename(files))

    part['Content-Disposition'] = 'attachment; filename="%s"' % basename(files)
    msg.attach(part)

    smtp.sendmail(send_from, send_to, msg.as_string())
    # smtp.quit()


w = xlrd.open_workbook("/home/jonatas/Downloads/email.xlsx")
s = w.sheet_by_index(0)

for r in range(s.nrows):
    c = s.row_values(r)

    if (re.match("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", c[1])):
        print(c[1])
        send_mail(
            "*****@*****.**", c[1],
            "Currículo estudante de enfermagem",
            'Sou Débora de Andrade Turíbio, estudante de enfermagem cursando o quinto semestre. Desejo adquirir experiência e oportunidade para poder entrar no mercado de trabalho da saúde, alcançando os objetivos profissionais.',
            "./debora.pdf")
Exemple #4
0
def check_file(fname, verbose, do_punc=False, fmt_info=0, encoding='ascii', onesheet=''):
    print
    print fname
    if do_punc:
        checker = ispunc
    else:
        checker = None
    try:
        book = open_workbook(fname, formatting_info=fmt_info, on_demand=True)
    except TypeError:
        try:
            book = open_workbook(fname, formatting_info=fmt_info)
        except TypeError:
            # this is becoming ridiculous
            book = open_workbook(fname)
    totold = totnew = totnotnull = 0
    if onesheet is None or onesheet == "":
        shxrange = range(book.nsheets)
    else:
        try:
            shxrange = [int(onesheet)]
        except ValueError:
            shxrange = [book.sheet_names().index(onesheet)]
    for shx in shxrange:
        sheet = book.sheet_by_index(shx)
        ngoodrows = number_of_good_rows(sheet, checker)
        ngoodcols = number_of_good_cols(sheet, checker, nrows=ngoodrows)
        oldncells = sheet.nrows * sheet.ncols
        newncells = ngoodrows * ngoodcols
        totold += oldncells
        totnew += newncells
        nnotnull = 0
        sheet_density_pct_s = ''
        if verbose >= 2:
            colxrange = range(ngoodcols)
            for rowx in xrange(ngoodrows):
                rowtypes = sheet.row_types(rowx)
                for colx in colxrange:
                    if rowtypes[colx] not in null_cell_types:
                        nnotnull += 1
            totnotnull += nnotnull
            sheet_density_pct = (nnotnull * 100.0) / max(1, newncells)
            sheet_density_pct_s = "; den = %5.1f%%" % sheet_density_pct
        if verbose >= 3:
            # which rows have non_empty cells in the right-most column?
            lastcolx = sheet.ncols - 1
            for rowx in xrange(sheet.nrows):
                cell = sheet.cell(rowx, lastcolx)
                if cell.ctype != XL_CELL_EMPTY:
                    print "%s (%d, %d): type %d, value %r" % (
                        cellname(rowx, lastcolx), rowx, lastcolx, cell.ctype, cell.value)
        if (verbose
            or ngoodrows != sheet.nrows
            or ngoodcols != sheet.ncols
            or (verbose >= 2 and ngoodcells and sheet_density_pct < 90.0)
            ):
            if oldncells:
                pctwaste = (1.0 - float(newncells) / oldncells) * 100.0
            else:
                pctwaste = 0.0
            shname_enc = safe_encode(sheet.name, encoding)
            print "sheet #%2d: RxC %5d x %3d => %5d x %3d; %4.1f%% waste%s (%s)" \
                % (shx, sheet.nrows, sheet.ncols,
                    ngoodrows, ngoodcols, pctwaste, sheet_density_pct_s, shname_enc)
        if hasattr(book, 'unload_sheet'):
            book.unload_sheet(shx)
    if totold:
        pctwaste = (1.0 - float(totnew) / totold) * 100.0
    else:
        pctwaste = 0.0
    print "%d cells => %d cells; %4.1f%% waste" % (totold, totnew, pctwaste)