Skip to content

Instantly share code, notes, and snippets.

@alexmerkel
Created October 26, 2023 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmerkel/3a7a5afbd5154733491005380171e40c to your computer and use it in GitHub Desktop.
Save alexmerkel/3a7a5afbd5154733491005380171e40c to your computer and use it in GitHub Desktop.
Quick and dirty script to convert a LadyCycle csv export to a Drip import file
#!/usr/bin/env python3
import csv
INPUT = "my_exported_cycle_days.csv"
OUTPUT = "output.csv"
# --------------------------------------------------------------------------- #
def main():
dripHeaders = ["date", "temperature.value", "temperature.exclude", "temperature.time", "temperature.note", "bleeding.value", "bleeding.exclude", "mucus.feeling", "mucus.texture", "mucus.value", "mucus.exclude", "cervix.opening", "cervix.firmness", "cervix.position", "cervix.exclude", "note.value", "desire.value", "sex.solo", "sex.partner", "sex.condom", "sex.pill", "sex.iud", "sex.patch", "sex.ring", "sex.implant", "sex.diaphragm", "sex.none", "sex.other", "sex.note", "pain.cramps", "pain.ovulationPain", "pain.headache", "pain.backache", "pain.nausea", "pain.tenderBreasts", "pain.migraine", "pain.other", "pain.note", "mood.happy", "mood.sad", "mood.stressed", "mood.balanced", "mood.fine", "mood.anxious", "mood.energetic", "mood.fatigue", "mood.angry", "mood.other", "mood.note"]
dripLines = []
with open(INPUT) as f:
oldFile = csv.DictReader(f, delimiter='\t')
for row in oldFile:
l = dict.fromkeys(dripHeaders, "")
save = False
#Convert date
year = int(row["Jahr"])
month = int(row["Monat"])
day = int(row["Zeit"])
hour = int(row["Stunde"])
minute = int(row["Minute"])
l["date"] = "{:04d}-{:02d}-{:02d}".format(year, month, day)
#Convert temperture
if float(row["Temperatur"]) > 0:
l["temperature.value"] = row["Temperatur"]
l["temperature.time"] = "{:02d}:{:02d}".format(hour, minute)
l["temperature.exclude"] = "false"
save = True
#Convert bleeding
if row["Menstruationsblutung"] != "keine Blutung":
l["bleeding.value"] = convertBleeding(row["Menstruationsblutung"])
l["bleeding.exclude"] = "false"
save = True
elif row["Zwischenblutung"] != "keine Blutung":
l["bleeding.value"] = convertBleeding(row["Zwischenblutung"])
l["bleeding.exclude"] = "true"
save = True
elif row["Schmierblutung"] != "keine Blutung":
l["bleeding.value"] = convertBleeding(row["Schmierblutung"])
l["bleeding.exclude"] = "true"
save = True
#Convert mucus
l["mucus.feeling"], l["mucus.texture"], l["mucus.value"], l["mucus.exclude"], s = convertCervex(row["Zervixschleim Empfinden"], row["Zervixschleim Aussehen"], row["Zervixschleim ausgeklammert"])
if s:
save = True
#Convert sex
if row["Geschlechtsverkehr"] == "geschützter Geschlechtsverkehr":
save = True
l["sex.partner"] = "true"
l["sex.condom"] = "true"
l["sex.iud"] = "true"
elif row["Geschlechtsverkehr"] == "ungeschützter Geschlechtsverkehr":
save = True
l["sex.partner"] = "true"
#Convert libido
l["desire.value"] = convertLibido(row["Libido"])
#Convert pains
l["pain.cramps"] = "true" if row["Bauchkraempfe"] != "keine" or row["Bauschschmerzen"] != "keine" else ""
l["pain.backache"] = "true" if row["Rueckenschmerzen"] != "keine" else ""
l["pain.headache"] = "true" if row["Kopfschmerzen"] != "keine" else ""
l["pain.tenderBreasts"] = "true" if row["Erhoehte Empfindlichkeit der Brueste"] != "keine" or row["Spannen der Brueste"] != "keine" else ""
l["pain.nausea"] = "true" if row["Uebelkeit"] != "keine" else ""
#Convert mood
l["mood.fatigue"] = "true" if row["Müdigkeit\t Erschöpfung"] != "keine" else ""
l["mood.anxious"] = "true" if row["Nervosität"] != "keine" else ""
l["mood.sad"] = "true" if row["Depressive Verstimmung"] != "keine" or row["Stimmung"] == "schlecht" else ""
l["mood.angry"] = "true" if row["Reizbarkeit"] != "keine" else ""
l["mood.stressed"] = "true" if "hoch" in row["Stress Level"] else ""
l["mood.happy"] = "true" if "gut" in row["Stimmung"] else ""
#Append
if save:
dripLines.append(l)
with open(OUTPUT, 'w', newline='\n', encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=dripHeaders)
writer.writeheader()
dripLines = sorted(dripLines, key=lambda d: d['date'], reverse = True)
writer.writerows(dripLines)
# ########################################################################### #
# --------------------------------------------------------------------------- #
def convertBleeding(s):
if s == "keine Blutung":
return ""
if s == "leichte Blutung":
return "1"
if s == "mittlere Blutung":
return "2"
if s == "starke Blutung":
return "3"
raise ValueError(s)
# ########################################################################### #
# --------------------------------------------------------------------------- #
def convertCervex(feeling, texture, exclude):
save = False
if feeling.startswith("trocken"):
f = "0"
save = True
elif feeling.startswith("nichts"):
f = "1"
save = True
elif feeling.startswith("feucht"):
f = "2"
save = True
elif feeling.startswith("nass"):
f = "3"
save = True
else:
f = ""
if texture.startswith("nichts"):
t = "0"
save = True
elif texture.startswith("dicklich"):
t = "1"
save = True
elif texture.startswith("glasig"):
t = "2"
save = True
else:
t = ""
if t == 1:
v = "3" #S
elif t == "2":
v = "4" #S+
elif f == "0":
v = "0" #Trocken
elif f == "1":
v = "1" #Nichts
else:
v = ""
if save:
if exclude == "Nein":
e = "false"
else:
e = "true"
else:
e = ""
return f,t,v,e,save
# ########################################################################### #
# --------------------------------------------------------------------------- #
def convertLibido(l):
if "schwach" in l:
return "0"
if l == "mittel":
return "1"
if "stark" in l:
return "2"
return ""
# ########################################################################### #
# --------------------------------------------------------------------------- #
if __name__ == "__main__":
try:
main()
except (KeyboardInterrupt, EOFError):
print("Aborted!")
# ########################################################################### #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment