Another Ham Radio Logbook -- Web, Multi-user multiple-logbook, with eQSL upload support
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

adif.py 899B

123456789101112131415161718192021222324252627282930313233
  1. import re
  2. import datetime
  3. # Comes from https://web.bxhome.org/content/adifpy
  4. ADIF_REC_RE = re.compile(br"<(.*?):(\d+).*?>([^<\t\f\v]+)")
  5. def parse(s):
  6. raw = re.split(b"<eor>|<eoh>(?i)", s)
  7. logbook = []
  8. for record in raw[1:-1]:
  9. qso = {}
  10. tags = ADIF_REC_RE.findall(record)
  11. for tag in tags:
  12. qso[tag[0].lower().decode("utf-8")] = tag[2][: int(tag[1])].decode("utf-8")
  13. logbook.append(qso)
  14. return logbook
  15. def save(fn, data):
  16. fh = open(fn, "w")
  17. fh.write("ADIF.PY by OK4BX\nhttp://web.bxhome.org\n<EOH>\n")
  18. for qso in data:
  19. for key in sorted(qso):
  20. value = qso[key]
  21. fh.write("<%s:%i>%s " % (key.upper(), len(value), value))
  22. fh.write("<EOR>\n")
  23. fh.close()
  24. def conv_datetime(adi_date, adi_time):
  25. return datetime.datetime.strptime(adi_date + adi_time.ljust(6, "0"), "%Y%m%d%H%M%S")