Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Récupère un fichier CSV et le convertit en fichier ADIF
- F4LEC Antonio Villanueva Segura
- Example CSV
- date,heure,call,freq,mode,RST_RX,points,RST_TX,my_call,
- 2025-02-23,16:52,F4JEC,14.207,USB,59,58
- 2025-02-23,16:46,F6AXN,14.118,USB,57,59
- """
- import csv
- from datetime import datetime
- def bande(freq_mhz):
- """ Renvoie la bande radioamateur selon la fréquence utilisée """
- if freq_mhz:
- #freq_mhz = float(freq)
- if 0.1357 <= freq_mhz <= 0.1378:
- band = "2200m"
- if 0.472 <= freq_mhz <= 0.479:
- band = "630m"
- if 1.8 <= freq_mhz <= 1.850:
- band = "160m"
- if 3.5 <= freq_mhz <= 3.8:
- band = "80m"
- if 5.3515 <= freq_mhz <= 5.3665:
- band = "60m"
- if 7.0 <= freq_mhz <= 7.2:
- band = "40m"
- if 10.100 <= freq_mhz <= 10.150:
- band = "30m"
- if 14.0 <= freq_mhz <= 14.350:
- band = "20m"
- if 18.068 <= freq_mhz <= 18.168:
- band = "17m"
- if 21.000 <= freq_mhz <= 21.450:
- band = "15m"
- if 24.890 <= freq_mhz <= 24.990:
- band = "12m"
- if 28.000 <= freq_mhz <= 29.700:
- band = "10m"
- if 50.000 <= freq_mhz <= 52.000:
- band = "6m"
- if 144.000 <= freq_mhz <= 146.000:
- band = "2m"
- if 430.000 <= freq_mhz <= 440.000:
- band = "70cm"
- if 1240 <= freq_mhz <= 1300:
- band = "23cm"
- if 2300 <= freq_mhz <= 2450:
- band = "13cm"
- return band
- def csv_to_adif(csv_file, adif_file):
- header = """<PROGRAMID:10>F4LEC_soft
- <ADIF_Ver:5>3.1.0
- <EOH>
- """
- with open(csv_file, 'r') as csvfile, open(adif_file, 'w') as adiffile:
- reader = csv.reader(csvfile)
- adiffile.write(header)
- for row in reader:
- date, time, callsign, freq, mode, rst_rx, rst_tx =row
- # Convertir la fréquence en MHz en bande
- if freq:
- freq_mhz = float(freq)
- band = bande(freq_mhz );
- # Formater la date et l'heure
- qso_date = datetime.strptime(date, "%Y-%m-%d").strftime("%Y%m%d")
- time_on = datetime.strptime(time, "%H:%M").strftime("%H%M")
- # Créer l'entrée ADIF
- adif_entry = f"""<CALL:{len(callsign)}>{callsign}<QSO_DATE:8>{qso_date}<TIME_ON:4>{time_on}<BAND:{len(band)}>{band}<FREQ:{len(freq)}>{freq}<MODE:{len(mode)}>LSB<RST_SENT:{len(rst_tx)}>{rst_tx}<RST_RCVD:{len(rst_rx)}>{rst_rx}<QSL_SENT:1>N<QSL_SENT_VIA:1>e<QSLMSG:11>TNX QSO 73s<APP_EQSL_AG:0><GRIDSQUARE:0><EQSL_QSL_RCVD:0><EQSL_QSLRDATE:0><EOR>"""
- adif_entry +='\n'
- print ("DEBUG :" ,adif_entry)
- adiffile.write(adif_entry)
- # Utilisation
- csv_file = "log.csv"
- adif_file = "adif.adi"
- csv_to_adif(csv_file, adif_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement