Esempio n. 1
0
def _extract_cell_value(cell, book):
    if cell.ctype == xlrd.XL_CELL_DATE:
        time_tuple = xlrd.xldate_as_tuple(cell.value, book.datemode)
        return utc(datetime.datetime(*time_tuple)).isoformat()
    elif cell.ctype == xlrd.XL_CELL_ERROR:
        raise ParseError("Error encountered in cell")
    return cell.value
Esempio n. 2
0
def _extract_cell_value(cell, book):
    if cell.ctype == xlrd.XL_CELL_DATE:
        time_tuple = xlrd.xldate_as_tuple(cell.value, book.datemode)
        return utc(datetime.datetime(*time_tuple)).isoformat()
    elif cell.ctype == xlrd.XL_CELL_ERROR:
        logging.warn("Encountered errors in cells when parsing excel file")
        return EXCEL_ERROR
    return cell.value
Esempio n. 3
0
def _extract_cell_value(cell, book):
    if cell.ctype == xlrd.XL_CELL_DATE:
        time_tuple = xlrd.xldate_as_tuple(cell.value, book.datemode)
        return utc(datetime.datetime(*time_tuple)).isoformat()
    elif cell.ctype == xlrd.XL_CELL_EMPTY:
        return None
    elif cell.ctype == xlrd.XL_CELL_NUMBER:
        # Convert to int where possible to match CSV parsing
        return int(cell.value) if cell.value % 1 == 0 else cell.value
    elif cell.ctype == xlrd.XL_CELL_ERROR:
        logging.warn("Encountered errors in cells when parsing excel file")
        return EXCEL_ERROR
    return cell.value
Esempio n. 4
0
def up(db):
    for name in db.collection_names():
        log.info("Migrating collection: {0}".format(name))
        collection = db.get_repository(name)
        query = {
            "_timestamp": {"$exists": True},
            "_week_start_at": {"$exists": False}
        }
        for document in collection.find(query):
            document['_timestamp'] = utc(document['_timestamp'])
            record = Record(document)

            collection.save(record.to_mongo())
Esempio n. 5
0
def up(db):
    for name in db.collection_names():
        log.info("Migrating collection: {0}".format(name))
        collection = db[name]
        query = {"_timestamp": {"$exists": True}, "_month_start_at": {"$exists": False}}
        for document in collection.find(query):
            document["_timestamp"] = utc(document["_timestamp"])
            if "_week_start_at" in document:
                document.pop("_week_start_at")
            if "_updated_at" in document:
                document.pop("_updated_at")
            record = Record(document)

            collection.save(record.to_mongo())
Esempio n. 6
0
def up(db):
    for name in db.collection_names():
        log.info("Migrating collection: {0}".format(name))
        collection = db[name]
        query = {
            "_timestamp": {
                "$exists": True
            },
            "_week_start_at": {
                "$exists": False
            }
        }
        for document in collection.find(query):
            document['_timestamp'] = utc(document['_timestamp'])
            record = Record(document)

            collection.save(record.to_mongo())
def up(db):
    for name in db.collection_names():
        log.info("Migrating collection: {0}".format(name))
        collection = db.get_repository(name)
        query = {
            "_timestamp": {"$exists": True},
            "_day_start_at": {"$exists": False}
        }
        is_capped = name.endswith('_realtime')
        if not is_capped:
            for document in collection.find(query):
                document['_timestamp'] = utc(document['_timestamp'])
                attrs = ['_updated_at', '_week_start_at', '_month_start_at']
                for attr in attrs:
                    if attr in document:
                        document.pop(attr)
                record = Record(document)

                collection.save(record.to_mongo())
Esempio n. 8
0
def datetimes_to_strings(record):
    for key, value in record.items():
        if isinstance(value, datetime.datetime):
            record[key] = unicode(utc(value).isoformat())

    return record
Esempio n. 9
0
def datetimes_to_strings(record):
    for key, value in record.items():
        if isinstance(value, datetime.datetime):
            record[key] = utc(value).isoformat()

    return record