-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcc_uls_callsign_search.py
147 lines (110 loc) · 3.59 KB
/
fcc_uls_callsign_search.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
# FCC ULS Callsign Search
# Author: Jacob Henson
# Repository: https://github.com/cyberphilia/fcc_uls_callsign_search
# Callsign:W4NTS
# Quick Start: python .\fcc_uls_callsign_search.py
import os
import time
from ftplib import FTP
from zipfile import ZipFile
import callsign
import database
# from pathlib import Path
# data_folder = Path("temp/")
# file_to_open = data_folder / "raw_data.txt"
# print(file_to_open)
def get_ULS_Zip():
print('Downloading Zip')
ftp = FTP('wirelessftp.fcc.gov')
#ftp.login(user='username', passwd = 'password')
ftp.login()
ftp.cwd('/pub/uls/complete/')
filename = 'l_amat.zip'
localfile = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, localfile.write, 1024)
ftp.quit()
localfile.close()
print('Download complete')
def unzip_ULS(filename):
if os.path.exists("l_amat.zip"):
print('Unzipping file')
with ZipFile(filename, 'r') as zipObj:
zipObj.extractall('temp')
print('Unzipping complete')
def ULSZipCheck():
if os.path.exists("l_amat.zip"):
file_modified = os.path.getmtime('l_amat.zip')
current_time = time.time()
time_difference = current_time - file_modified
if time_difference > 604800: # 604800 one week in seconds
get_ULS_Zip()
else:
print('ULS Zip file not found.')
get_ULS_Zip()
unzip_ULS('l_amat.zip')
def print_menu():
print('FCC ULS Callsign Search')
print(' 0: Exit')
print(' 1: Search for Callsign')
print(' 2: Process callsign_input.txt')
# print(' 3: SQL Query')
print('')
def search(db, input):
rtn = ''
cs = callsign.Callsign(input)
rtn += 'Callsign: {}\n'.format(cs.callsign)
rtn += '==================\n'
rtn += 'Group: {}, Available To: {} \n\n'.format(cs.group,cs.available_to)
amateur = db.select_amateur(cs.callsign)
comments = db.select_comments(cs.callsign)
# entity = db.select_entity(cs.callsign)
history = db.select_history(cs.callsign)
if amateur:
rtn += 'Amateur: \n'
rtn += '------------------\n'
rtn += amateur +'\n'
if comments:
rtn += 'Comments: \n'
rtn += '------------------\n'
rtn += comments +'\n'
# if entity:
# rtn += 'Entity: \n'
# rtn += '------------------\n'
# rtn += entity +'\n'
if history:
rtn += 'History: \n'
rtn += '------------------\n'
rtn += history +'\n'
else:
rtn += 'History: None, {} Probably Available\n'.format(cs.callsign)
return rtn
def main():
ULSZipCheck()
# db = database.ULSDatabase('uls.db','temp/')
db = database.ULSDatabase(':memory:','temp/')
menu = True
while menu is not False:
print_menu()
option = input("Option:")
if option == '0':
menu = False
if option == '1':
callsign_input = input("Callsign?: ")
print()
print()
print(search(db,callsign_input))
if option == '2':
output_file= open('callsign_output.txt','w')
with open('callsign_input.txt', 'r') as reader:
for line in reader.readlines():
search_results = search(db,line.upper().strip())
print(search_results)
output_file.write(search_results)
output_file.close()
# print(line + '>>>>>')
# output_file.write(select_callsign(db_con,line.upper().strip())+'\n')
print()
print()
db.close_connection()
if __name__ == "__main__":
main()