def upload_batterystats(filename, username, password, bucket_name=BUCKET_NAME, bucket_desc=BUCKET_DESC):
    """
        Works with CSVs generated by the Android app 'Battery Log' (https://play.google.com/store/apps/details?id=kr.hwangti.batterylog)
    """

    zapi = pyzenobase.ZenobaseAPI(username, password)
    bucket = zapi.create_or_get_bucket(bucket_name, description=bucket_desc)
    bucket_id = bucket["@id"]

    events = []
    with open(filename, newline="") as f:
        reader = csv.reader(f)
        header = next(reader)
        for row in reader:
            events.append({header[i]: row[i] for i in range(len(header))})

    print("Read {} events".format(len(events)))
    for event in events:
        # Transform data
        event["timestamp"] = pyzenobase.fmt_datetime(datetime.strptime(event.pop("datetime"), "%Y-%m-%d %H:%M:%S"), timezone="Europe/Stockholm")
        event["tag"] = event.pop("status")
        event["percentage"] = float(event.pop("level"))
        event["temperature"] = {"@value": float(event.pop("temperature")), "unit": "C"}
        event.pop("voltage")

    print("Checking that events are valid...")
    events = [pyzenobase.ZenobaseEvent(event) for event in events]
    print("Uploading...")
    zapi.create_events(bucket_id, events)
    zapi.close()
    print("Done!")