-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmis.py
More file actions
62 lines (54 loc) · 1.61 KB
/
Copy pathmis.py
File metadata and controls
62 lines (54 loc) · 1.61 KB
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
from urllib3 import PoolManager
from re import search as re_search
from csv import reader as csv_reader
DATA_KEYS = ['名称', '都道府県', '無線局の目的', '免許の年月日']
class Station():
def __init__(
self,
name,
location,
purpose,
expiry_date
):
self.name = name
self.location = location
self.purpose = purpose,
self.expiry_date = expiry_date
self.callsign = re_search(
"[A-Z,0-9]+",
self.name
)[0]
def into_json(self):
return {
self.callsign: {
"name": self.name,
"location": self.location,
"purpose": self.purpose,
"expiry_date": self.expiry_date,
}
}
def search(
station_type,
callsign=None,
prefecture=None,
freq_from=None,
freq_to=None,
owner_name=None
):
raw_datas = PoolManager().request(
"GET",
f"https://www.tele.soumu.go.jp/musen/SearchServlet?MA={callsign}&SelectID=1&SelectOW=0{station_type}&HC={prefecture}&FF={freq_from}&TF={freq_to}&NA={owner_name}&DC=100&SK=2&pageID=5&SC=1&CONFIRM=1"
).data.decode("shift-jis")
result = [
line for line in csv_reader(
raw_datas.splitlines()
)
if line != []
]
result = result[
# get index of ['名称', '都道府県', '無線局の目的', '免許の年月日'] . Lists after that will be the results we're looking for.
result.index(DATA_KEYS) + 1:
]
return [
Station(*station_data) for station_data in result
]