-
Notifications
You must be signed in to change notification settings - Fork 0
/
airspyhf_shedule.py
executable file
·166 lines (146 loc) · 4.69 KB
/
airspyhf_shedule.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/python3
import os
from airspyhf import *
from ctypes import *
import time
import sys
import argparse
import configparser
import re
class Station:
name = "NoName"
frequency = 4000000
time = 0
duration = 300 #in seconds
day = []
month = []
def __init__(self):
pass
def readConfig(self,config):
if "name" in config:
self.name = config["name"]
if "frequency" in config:
self.frequency = int(config["frequency"])
if "time" in config:
m = re.match(r"(?P<hour>[0-9]{1,2}):(?P<minute>[0-9]{1,2})",config["time"]).groupdict()
m_hour = int(m["hour"])
m_minute = int(m["minute"])
#what format should be time
self.time = m_hour*3600+m_minute*60
if "duration" in config:
s_duration = str(config["duration"])
# Supported
# 6m
# 1h30m
# 1m30s
# 0m1s
# 0h5m10s
m = re.match(r"((?P<hour>[0-9]{1,2})h)?((?P<minute>[0-9]{1,2})m)?((?P<second>[0-9]{1,2})s)?",s_duration).groupdict()
print(m)
time_in_sec = 0
if m["hour"]:
time_in_sec += int(m["hour"])*3600
if m["minute"]:
time_in_sec += int(m["minute"])*60
if m["second"]:
time_in_sec += int(m["second"])
self.duration = time_in_sec
if "day" in config:
self.day = []
if config["day"] == "every":
self.day = [1,2,3,4,5,6,7]
else:
#Supported
# lowercase mon,tue,wen,thu,fri,sat,sun
days = config["day"].lower().split(",")
if "mon" in days:
self.day.append(1)
if "tur" in days:
self.day.append(2)
if "wen" in days:
self.day.append(3)
if "thu" in days:
self.day.append(4)
if "fri" in days:
self.day.append(5)
if "sat" in days:
self.day.append(6)
if "sun" in days:
self.day.append(7)
if "month" in config:
self.month = []
#Supported
#jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
month = config["month"].lower().split(",")
if "jan" in month:
self.month.append(1)
if "feb" in month:
self.month.append(2)
if "mar" in month:
self.month.append(3)
if "apr" in month:
self.month.append(4)
if "may" in month:
self.month.append(5)
if "jun" in month:
self.month.append(6)
if "jul" in month:
self.month.append(7)
if "aug" in month:
self.month.append(8)
if "sep" in month:
self.month.append(9)
if "oct" in month:
self.month.append(10)
if "nov" in month:
self.month.append(11)
if "dec" in month:
self.month.append(12)
def __str__(self):
return f"{self.name} freq:{self.frequency} time:{self.time} day:{self.day} month:{self.month}"
class StationCollection:
stations = []
def __init__(self):
pass
def addStation(self,station:Station):
self.stations.append(station)
def listall(self):
print("List of stations")
for s in self.stations:
print(s)
def listToday(self):
print("Today will broadcast")
class RadioConfig:
samplerate = 192000
def __init__(self):
pass
def readConfig(self, config):
if "samplerate" in config:
self.samplerate = int(config["samplerate"])
parser = argparse.ArgumentParser()
parser.add_argument("-c","--configfile")
parser.add_argument("-d","--debug",help="Output extra logs to see whats happening")
args = parser.parse_args()
debug = False
if args.debug:
debug = True
config = configparser.ConfigParser()
if args.configfile:
config.read(args.configfile)
else:
config.read("number.ini")
print(config.sections())
radio_config = RadioConfig()
station_config = StationCollection()
for section in config.sections():
#print(section)
if section == "radio":
radio_config.readConfig(config[section])
elif section[0:7] == "station":
station = Station()
station.readConfig(config[section])
station_config.addStation(station)
#print list of all stations
station_config.listall()
#print list of todays stations to record
station_config.listToday()