-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·127 lines (106 loc) · 5.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
# Copyright [2021] [László Párkányi]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pandas as pd
# returns tone (none, Tone or TSQL), rRtoneFreq (uplink), cToneFreq (downlink)
# if no frequency is present, the value is replaced by 88.5 (default in CHIRP)
def is_tone(ctcss_freqs):
rtonefreq = ctcss_freqs.partition("/")[2]
ctonefreq = ctcss_freqs.partition("/")[0]
# The 3 modes of operation:
# empty: no CTCSS or DL only
# Tone: only UL
# TQSL: UL and DL CTCSS
if rtonefreq == "--":
return "", "88.5", "88.5"
elif ctonefreq == "--":
return "Tone", rtonefreq, "88.5"
else:
return "TSQL", rtonefreq, ctonefreq
def calculate_ctcss(repeaters):
Tones, cToneFreqs, rToneFreqs = [], [], []
for i in repeaters.Ctone:
Tone, rToneFreq, cToneFreq = is_tone(i)
Tones.append(Tone)
cToneFreqs.append(cToneFreq)
rToneFreqs.append(rToneFreq)
repeaters["Tone"] = Tones
repeaters["rToneFreq"] = rToneFreqs
repeaters["cToneFreq"] = cToneFreqs
repeaters = repeaters.drop(["Ctone"], axis=1)
return repeaters
def trunc_mode(repeaters):
modes = []
for i in repeaters.Mode:
modes.append(i.partition("/")[0])
return modes
def get_repeaters(link):
repeaters = pd.read_html(link, encoding='utf8', match='Echolink')[0]
repeaters = (repeaters[~repeaters.Állapot.str.contains("inaktív")]) # sorting out inactive repeaters
repeaters = repeaters.drop(["Csat. új", "Csat. régi", "Echolink", "QTH Lokátor",
"ASL", "Állapot"], axis=1) # letting go of unnecessary columns
repeaters = repeaters.rename({"Hívójel": "Name", "QTH/Név": "Comment", "Lejövő [kHz]": "Frequency",
"Elt.[kHz]": "Offset", "Üzemmód": "Mode", "CTCSS DL/UL [Hz]": "Ctone",
"Felmenő [kHz]": "Uplink"}, axis=1)
repeaters = calculate_ctcss(repeaters)
repeaters["Offset"] = (repeaters.Frequency - repeaters.Uplink) / 1000
repeaters = repeaters.drop(["Uplink"], axis=1)
repeaters["Frequency"] = repeaters.Frequency / 1000
repeaters["Mode"] = trunc_mode(repeaters)
repeaters["Duplex"] = '-'
repeaters["DtcsCode"] = '023'
repeaters["DtcsPolarity"] = 'NN'
repeaters["TStep"] = '5.00'
repeaters["Skip"] = ''
repeaters["URCALL"] = ''
repeaters["RPT1CALL"] = ''
repeaters["RPT2CALL"] = ''
repeaters["DVCODE"] = ''
# repeaters = repeaters.rename(dict(zip(repeaters.index, range(4, repeaters.shape[0] + 5))))
return repeaters
def generate_csv(repeaters):
for r in repeaters:
print(r)
if __name__ == '__main__':
repeatercsv = open("repeater.csv", "w+")
call_dataframe = pd.DataFrame({"Name": ["2M CALL", "2M SSTV", "70CM CALL", "70CM SSTV"],
"Frequency": ["145.500000", "144.500000", "433.500000", "433.400000"],
"Duplex": ["", "", "", ""],
"Offset": ["0.000000", "0.000000", "0.000000", "0.000000"],
"Tone": ["", "", "", ""],
"rToneFreq": ["88.5", "88.5", "88.5", "88.5"],
"cToneFreq": ["88.5", "88.5", "88.5", "88.5"],
"DtcsCode": ["023", "023", "023", "023"],
"DtcsPolarity": ["NN", "NN", "NN", "NN"],
"Mode": ["FM", "FM", "FM", "FM"],
"TStep": ["5.00", "5.00", "5.00", "5.00"],
"Skip": ["", "", "", ""],
"Comment": ["2m-es hivofrekvencia", "2m-es SSTV hivofrekvencia",
"70cm-es hivofrekvencia", "70cm-es SSTV hivofrekvencia"],
"URCALL": ["", "", "", ""],
"RPT1CALL": ["", "", "", ""],
"RPT2CALL": ["", "", "", ""],
"DVCODE": ["", "", "", ""]})
repeater_dataframe = pd.concat([call_dataframe,get_repeaters('http://ha2to.orbel.hu/content/repeaters/hu/index.html')],
ignore_index=True)
repeater_dataframe.index.name = "Location"
repeater_dataframe = repeater_dataframe.rename(
dict(zip(repeater_dataframe.index, range(1, repeater_dataframe.shape[0] + 1))))
repeater_dataframe.to_csv(repeatercsv)
# HTTP Header
print("Content-Type:application/octet-stream; name = \"repeaters.csv\"\r\n")
print("Content-Disposition: attachment; filename = \"repeaters.csv\"\r\n\n")
repeatercsv.seek(0)
print(repeatercsv.read())
repeatercsv.close()