提交 86dc745a 编辑于 作者: Mijian Xu's avatar Mijian Xu 😷
浏览文件

Search by channel

上级 31e7d68b
......@@ -10,12 +10,13 @@
def Usage():
print('Usage:')
print('python bqmail.py -Nnetwork -Sstation -Yyear1/month1/day1/year2/month2/day2 -Cdatetimefile head.cfg')
print('python bqmail.py -Nnetwork -Sstation -Yyear1/month1/day1/year2/month2/day2 -Bsec_begin/sec_end -Cdatetimefile head.cfg')
import datetime
import os, re
import sys, getopt
from smtplib import SMTP
try:
import configparser
config = configparser.ConfigParser()
......@@ -25,7 +26,7 @@ except:
try:
opts,args = getopt.getopt(sys.argv[1:], "hN:S:C:")
opts,args = getopt.getopt(sys.argv[1:], "hN:S:C:Y:B:")
except:
print('arguments are not found!')
Usage()
......@@ -44,6 +45,8 @@ for op, value in opts:
elif op == "-C":
datetimefile = value
iscustom = 1
elif op == "-B":
timerange = value
elif op == "-h":
Usage()
sys.exit(1)
......@@ -71,6 +74,7 @@ if isyrange:
datemin=datetime.datetime(year1,mon1,day1)
datemax=datetime.datetime(year2,mon2,day2)
event=[]
config.read(head)
......@@ -80,6 +84,10 @@ INST = config.get("info","INST")
EMAIL = config.get("info","EMAIL")
MEDIA = config.get("info","MEDIA")
ALTERNATEMEDIA = config.get("info","ALTERNATEMEDIA")
hosts = config.get("smtp","hosts")
port = config.get("smtp","port")
passwd = config.get("smtp","passwd")
recipient = 'breq_fast@iris.washington.edu'
if isyrange:
LABEL = 'IRIS_'+str(year1)+"_"+str(year2)+"_"+network+"_"+station
else:
......@@ -89,12 +97,13 @@ if iscustom:
for evenum in EVENT:
evenum = evenum.strip('\n')
evenum_sp = re.split(',|\s',evenum)
# print(evenum_sp)
event.append(evenum_sp)
else:
trange_sp = timerange.split('/')
btime = float(trange_sp[0])
etime = float(trange_sp[1])
EVENT = open(eventlst,'r+')
for evenum in EVENT:
evenum_split = evenum.split()
year=int(evenum_split[0])
......@@ -108,30 +117,36 @@ else:
lon=float(evenum_split[8])
dep=float(evenum_split[9])
mw=float(evenum_split[10])
date = datetime.datetime(year,mon,day,hour,min)
dt = datetime.timedelta(hours=1)
dateend = date + dt
date = datetime.datetime(year,mon,day,hour,min) + datetime.timedelta(seconds=btime)
dateend = datetime.datetime(year,mon,day,hour,min) + datetime.timedelta(seconds=etime)
if datemin <= date <= datemax:
event.append([date.strftime('%Y'),date.strftime('%m'),date.strftime('%d'),date.strftime('%H'),date.strftime('%M'),dateend.strftime('%Y'),dateend.strftime('%m'),dateend.strftime('%d'),dateend.strftime('%H'),dateend.strftime('%M')])
OUT = open(network+'_'+station+'.bq','w+')
OUT.write('.NAME '+NAME+'\n')
OUT.write('.INST '+INST+'\n')
OUT.write('.MAIL\n')
OUT.write('.EMAIL '+EMAIL+'\n')
OUT.write('.PHONE\n')
OUT.write('.FAX\n')
OUT.write('.MEDIA '+MEDIA+'\n')
OUT.write('.ALTERNATE MEDIA '+ALTERNATEMEDIA+'\n')
OUT.write('.ALTERNATE MEDIA '+ALTERNATEMEDIA+'\n')
OUT.write('.LABEL '+LABEL+'\n')
OUT.write('.END\n')
head = ("From: %s\r\nTo: %s\r\n\r\n" % (EMAIL, recipient))
msg = head
msg += '.NAME '+NAME+'\n'
msg += '.INST '+INST+'\n'
msg += '.MAIL\n'
msg += '.EMAIL '+EMAIL+'\n'
msg += '.PHONE\n'
msg += '.FAX\n'
msg += '.MEDIA '+MEDIA+'\n'
msg += '.ALTERNATE MEDIA '+ALTERNATEMEDIA+'\n'
msg += '.ALTERNATE MEDIA '+ALTERNATEMEDIA+'\n'
msg += '.LABEL '+LABEL+'\n'
msg += '.END\n'
if not iscustom:
for row in event:
OUT.write(station+' '+network+' '+row[0]+' '+row[1]+' '+row[2]+' '+row[3]+' '+row[4]+' 00.0 '+row[5]+' '+row[6]+' '+row[7]+' '+row[8]+' '+row[9]+' 00.0 1 BH?\n')
msg += station+' '+network+' '+row[0]+' '+row[1]+' '+row[2]+' '+row[3]+' '+row[4]+' 00.0 '+row[5]+' '+row[6]+' '+row[7]+' '+row[8]+' '+row[9]+' 00.0 1 BH?\n'
else:
for row in event:
OUT.write(station+' '+network+' '+row[0]+' '+row[1]+' '+row[2]+' '+row[3]+' '+row[4]+' '+row[5]+' '+row[6]+' '+row[7]+' '+row[8]+' '+row[9]+' '+row[10]+' '+row[11]+' 1 BH?\n')
os.system('mail breq_fast@iris.washington.edu <'+network+'_'+station+'.bq')
msg += station+' '+network+' '+row[0]+' '+row[1]+' '+row[2]+' '+row[3]+' '+row[4]+' '+row[5]+' '+row[6]+' '+row[7]+' '+row[8]+' '+row[9]+' '+row[10]+' '+row[11]+' 1 BH?\n'
smtp = SMTP(host=hosts, port=port)
smtp.set_debuglevel(0)
smtp.login(EMAIL, passwd)
smtp.sendmail(EMAIL, 'breq_fast@iris.washington.edu', msg)
smtp.quit()
print("Successful sending the mail of "+network+"."+station+" to IRIS DMC!!!")
os.system('rm '+network+'_'+station+'.bq')
[lst]
eventlst = ./EventCMT.dat
[info]
NAME = huihuang
NAME = bqmail
INST = NJU
EMAIL = oldyellow9451@163.com
EMAIL = xxxxxx@xxx.com
MEDIA = Electronic (FTP)
ALTERNATEMEDIA = Electronic (FTP)
[smtp]
hosts = smtp.xxx.com
port = 25
passwd = xxxxxxxx
......@@ -11,14 +11,16 @@ import sys, getopt
import glob
def Usage():
print('Usage: python searchlalo.py -Rlon1/lon2/lat1/lat2 -Dlat/lon/dis1/dis2 -K')
print('Usage: python searchlalo.py -Rlon1/lon2/lat1/lat2 -Dlon/lat/dis1/dis2 -Yyear1/mon1/day1/year2/mon2/day2 -Cchannel -K')
print('-R -- Search range.')
print('-D -- Search by distance.')
print('-Y -- Date range')
print('-C -- Channel (e.g., BHZ)')
print('-K -- Output Google Earth kml file.')
try:
opts,args = getopt.getopt(sys.argv[1:], "hR:D:KO:")
opts,args = getopt.getopt(sys.argv[1:], "hR:D:KO:Y:C:")
except:
print('arguments are not found!')
Usage()
......@@ -26,6 +28,8 @@ except:
iskml = 0
islalo = 0
isyrange = 0
ischan = 0
for op, value in opts:
if op == "-R":
lat_lon = value
......@@ -34,6 +38,12 @@ for op, value in opts:
iskml = 1
elif op == "-D":
lat_lon = value
elif op == "-Y":
yrange = value
isyrange = 1
elif op == "-C":
chan = value
ischan = 1
elif op == "-h":
Usage()
sys.exit(1)
......@@ -63,7 +73,23 @@ else:
lat2 = str(90)
lalo = lon+'_'+lat+'_'+lat_lon_split[2]
url = 'http://ds.iris.edu/cgi-bin/xmlstationinfo?minlat='+lat1+'&maxlat='+lat2+'&minlon='+lon1+'&maxlon='+lon2
if isyrange:
yrange_sp = yrange.split("/")
year1 = yrange_sp[0]
mon1 = yrange_sp[1]
day1 = yrange_sp[2]
year2 = yrange_sp[3]
mon2 = yrange_sp[4]
day2 = yrange_sp[5]
if ischan:
url = 'http://ds.iris.edu/cgi-bin/xmlstationinfo?minlat='+lat1+'&maxlat='+lat2+'&minlon='+lon1+'&maxlon='+lon2+'&timewindow='+year1+'/'+mon1+'/'+day1+'-'+year2+'/'+mon2+'/'+day2+'&chan='+chan
else:
url = 'http://ds.iris.edu/cgi-bin/xmlstationinfo?minlat='+lat1+'&maxlat='+lat2+'&minlon='+lon1+'&maxlon='+lon2+'&timewindow='+year1+'/'+mon1+'/'+day1+'-'+year2+'/'+mon2+'/'+day2
elif ischan:
url = 'http://ds.iris.edu/cgi-bin/xmlstationinfo?minlat='+lat1+'&maxlat='+lat2+'&minlon='+lon1+'&maxlon='+lon2+'&chan='+chan
else:
url = 'http://ds.iris.edu/cgi-bin/xmlstationinfo?minlat='+lat1+'&maxlat='+lat2+'&minlon='+lon1+'&maxlon='+lon2
response = rq.urlopen(url)
html = str(response.read())
find_re = re.compile(r'<station\s.+?"\s/>',re.DOTALL)
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册