-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamlicensenotify.py
73 lines (64 loc) · 2.06 KB
/
hamlicensenotify.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
#!/usr/bin/python2
import sys
from lxml import html
import requests
import argparse
import datetime
import smtplib
from email.mime.text import MIMEText
parser = argparse.ArgumentParser(description='App to search FCC ULS for callsign')
parser.add_argument('fccfrn',
help='A required FCC ULS Number')
parser.add_argument('--msgto',
help='Comma separated email addresses to send the notification to', required=True)
parser.add_argument('--msgfrom',
help='Email address to send the message from', required=True)
parser.add_argument('--msgsubject',
help='Email subject for the notification', required=True)
args = parser.parse_args()
urlsearch = 'http://wireless2.fcc.gov/UlsApp/UlsSearch/searchAdvanced.jsp'
urlresult = 'http://wireless2.fcc.gov/UlsApp/UlsSearch/results.jsp'
today = datetime.date.today()
todaydate = today.strftime('%-m/%d/%Y')
page = requests.get(urlsearch)
headers = {
"Cookie": page.headers["set-cookie"],
"Content-Type": "application/x-www-form-urlencoded",
"Referer": urlsearch
}
data = {
'fiUlsServiceSearchByType':100,
'fiRadioServiceMatchAllInd':'some',
'radioservicecode':'HA',
'fiUlsFRN':args.fccfrn,
'statusAll':'Y',
'ulsAuthTypeAll':'Y',
'ulsToDate':todaydate,
'feqSearchType':'any',
'fiRowsPerPage':10,
'ulsSortBy':'uls_l_callsign',
'ulsOrderBy':'ASC',
'hiddenForm':'hiddenForm',
'jsValidated':'true',
'searchType':'ULN'
}
page = requests.post(urlresult, data = data, headers = headers)
#print page.content
#print 'End Content'
tree = html.fromstring(page.content)
licenses = tree.xpath('//table[@summary="License search results"]/tr')
text = ''
for license in licenses:
if 'align' in license.attrib.keys():
callsign = license[1][0].text
licenseename = license[2].text.strip()
text = text + "\n%s %s" % (callsign, licenseename)
if text != '':
msgto = args.msgto.split(",")
msg = MIMEText(text)
msg['Subject'] = args.msgsubject
msg['From'] = args.msgfrom
msg['To'] = ",".join(msgto)
s = smtplib.SMTP('localhost')
s.sendmail(msg['From'],msgto,msg.as_string())
s.quit()