Example #1
0
def process_paste(text, has_header_row=True):
    """
    Return results for a pasted table
    """
    rows = text.splitlines()
    csv_rows = []

    for r in rows:
        groups = re.findall(r'"(.*?)+"|\t', r)
        if len(groups) == 3:
            csv.rows.append((groups[0], groups[2]))
        elif len(groups) == 1:
            csv_rows.append((r.split('\t')[0], r.split('\t')[1]))
        else:
            return None

    headers = csv_rows.pop(0) if has_header_row else ['source', 'target']
    file_path = filehandler.write_to_csv(headers, csv_rows)
    file_size = os.stat(file_path).st_size
    logger.debug('[CTD] File size: %d bytes', file_size)

    results = ctd.get_summary(file_path)
    results['has_multiple_sheets'] = False
    results['filename'] = 'Your Pasted Data'

    filehandler.delete_files([file_path])
    return results
Example #2
0
def process_paste(text, has_header_row=True):
    """
    Return results for a pasted table
    """
    rows = text.splitlines()
    csv_rows = []

    for r in rows:
        groups = re.findall(r'"(.*?)+"|\t', r)
        if len(groups) == 3:
            csv.rows.append((groups[0], groups[2]))
        elif len(groups) == 1:
            csv_rows.append((r.split('\t')[0], r.split('\t')[1]))
        else:
            return None

    headers = csv_rows.pop(0) if has_header_row else ['source', 'target']
    file_path = filehandler.write_to_csv(headers, csv_rows)
    file_size = os.stat(file_path).st_size
    logger.debug('[CTD] File size: %d bytes', file_size)

    results = ctd.get_summary(file_path)
    results['has_multiple_sheets'] = False
    results['filename'] = 'Your Pasted Data'

    filehandler.delete_files([file_path])
    return results
Example #3
0
def process_link(sheet):
    file_paths = filehandler.open_workbook(sheet)
    results = []
    for f in file_paths:
        summary = wtfcsvstat.get_summary(f)
        if 'bad_formatting' not in summary:
            summary['sheet_name'] = _get_sheet_name(f)
            summary['filename'] = sheet.sheet1.title
        results.append(summary)
    filehandler.delete_files(file_paths)
    return results
Example #4
0
def process_link(sheet):
    file_paths = filehandler.open_workbook(sheet)
    results = []
    for f in file_paths:
        summary = wtfcsvstat.get_summary(f)
        if 'bad_formatting' not in summary:
            summary['sheet_name'] = _get_sheet_name(f)
            summary['filename'] = sheet.sheet1.title
        results.append (summary)
    filehandler.delete_files(file_paths)
    return results
Example #5
0
def process_upload(csv_file):
    file_path = filehandler.open_doc(csv_file)
    file_size = os.stat(file_path).st_size # because browser might not have sent content_length
    logger.debug("Upload: %d bytes", file_size)
    file_paths = filehandler.convert_to_csv(file_path)
    results = []
    for f in file_paths:
        summary = wtfcsvstat.get_summary(f)
        if 'bad_formatting' not in summary:
            summary['sheet_name'] = _get_sheet_name(f)
            summary['filename'] = csv_file.filename
        results.append(summary)
    filehandler.delete_files(file_paths)
    return results
Example #6
0
def process_upload(csv_file):
    file_path = filehandler.open_doc(csv_file)
    file_size = os.stat(
        file_path
    ).st_size  # because browser might not have sent content_length
    logger.debug("Upload: %d bytes", file_size)
    file_paths = filehandler.convert_to_csv(file_path)
    results = []
    for f in file_paths:
        summary = wtfcsvstat.get_summary(f)
        if 'bad_formatting' not in summary:
            summary['sheet_name'] = _get_sheet_name(f)
            summary['filename'] = csv_file.filename
        results.append(summary)
    filehandler.delete_files(file_paths)
    return results
Example #7
0
def process_upload(file, has_header_row=True):
    """
    Return results for an uploaded file
    """
    file_path = filehandler.open_doc(file)
    file_name = file.filename
    file_size = os.stat(file_path).st_size
    logger.debug('[CTD] File size: %d bytes', file_size)

    csv_paths = filehandler.convert_to_csv(file_path)
    results = ctd.get_summary(csv_paths[0], has_header_row) # only use first sheet
    results['has_multiple_sheets'] = True if len(csv_paths) > 1 else False
    results['filename'] = file_name

    filehandler.delete_files(csv_paths)
    return results
Example #8
0
def process_upload(file, has_header_row=True):
    """
    Return results for an uploaded file
    """
    file_path = filehandler.open_doc(file)
    file_name = file.filename
    file_size = os.stat(file_path).st_size
    logger.debug('[CTD] File size: %d bytes', file_size)

    csv_paths = filehandler.convert_to_csv(file_path)
    results = ctd.get_summary(csv_paths[0],
                              has_header_row)  # only use first sheet
    results['has_multiple_sheets'] = True if len(csv_paths) > 1 else False
    results['filename'] = file_name

    filehandler.delete_files(csv_paths)
    return results