Commit 371c3237 authored by Mijian Xu's avatar Mijian Xu 😷
Browse files

conti request

parent 5c725553
......@@ -70,20 +70,43 @@ class BQMail():
def query_events(self, **kwargs):
self.query.get_events(**kwargs)
def write_mail(self, arrange='station', time_before=0, time_after=1000,
mark='o', channel='BH?', location='', time_sleep=2):
def send_mail(self, arrange='station', time_sleep=2, **kwargs):
locs = locals()
locs.pop('arrange')
locs.pop('self')
locs.pop('time_sleep')
print(locs)
if arrange == 'station':
self.station_mail(**locs)
for label, msg in zip(self.labels, self.msgs):
succ = sendmail(self.mailname, msg, server=self.server,
password=self.password)
if succ:
print('successfully send {}'.format(label))
time.sleep(time_sleep)
self.station_mail(**kwargs)
elif arrange == 'continue':
self.conti_mail(**kwargs)
else:
raise ValueError('variable arrange must be in \'station\' and \'continue\'')
print(self.msgs)
for label, msg in zip(self.labels, self.msgs):
succ = sendmail(self.mailname, msg, server=self.server,
password=self.password)
if succ:
print('successfully send {}'.format(label))
time.sleep(time_sleep)
# with open('msg.{}'.format(label), 'w') as f:
# f.write(msg)
def conti_mail(self, starttime=UTCDateTime(2000, 1, 1),
endtime=UTCDateTime.now(), time_val_in_hours=24,
channel='BH?', location=''):
self.query.get_conti(starttime, endtime, hours=time_val_in_hours)
for sdt, edt in self.query.conti_time:
label = sdt.strftime('%Y.%m.%d')
self.labels.append(label)
msg = self.header
msg += '.LABEL {}\n.END\n'.format(label)
for net in self.query.stations:
for sta in net:
msg += '{} {} {} {} 1 {} {}\n'.format(
sta.code, net.code, sdt.strftime('%Y %m %d %H %M %S'),
edt.strftime('%Y %m %d %H %M %S'), channel, location)
self.msgs.append(msg)
def station_mail(self, time_before=0, time_after=1000,
mark='o', channel='BH?', location=''):
......
from obspy.clients.fdsn import Client
from obspy import UTCDateTime
from datetime import timedelta
import pandas as pd
import argparse
import sys
......@@ -26,6 +27,14 @@ class Query():
def get_stations(self, **kwargs):
self.stations = self.client.get_stations(**kwargs)
def get_conti(self, starttime, endtime, hours=24):
self.conti_time = []
nowtime = starttime
while nowtime < endtime:
nexttime = nowtime + timedelta(hours=hours)
self.conti_time.append([nowtime, nexttime])
nowtime = nexttime
def get_events():
parser = argparse.ArgumentParser(description="Get seismic events from IRIS WS")
......@@ -174,10 +183,11 @@ def get_stations():
if __name__ == "__main__":
query = Query()
query.get_events(minmagnitude=7, catalog='GCMT')
query.get_stations(network='3J')
# query.get_events(minmagnitude=7, catalog='GCMT')
# query.get_stations(network='3J')
# query.get_stations(network='3J', minlatitude=20,
# minlongitude=97, maxlatitude=40,
# maxlongitude=110)
print(query.events)
print(query.stations)
query.get_conti(UTCDateTime(2011,1,1), UTCDateTime(2011,2,1))
print(query.conti_time)
# print(query.stations)
......@@ -2,8 +2,9 @@ from bqmail.mail import BQMail
from obspy import UTCDateTime
bq = BQMail('gomijianxu@163.com', server='smtp.163.com', password='nanwai99', username='mijian')
bq.query_events(starttime=UTCDateTime(2010, 1, 1), endtime=UTCDateTime(2018, 1, 1),
minmagnitude=5.5, catalog='GCMT')
bq.query_stations(network='CB', station='LZH')
bq.write_mail(time_before=0, time_after=1000)
# bq.query_events(starttime=UTCDateTime(2010, 1, 1), endtime=UTCDateTime(2018, 1, 1),
# minmagnitude=5.5, catalog='GCMT')
bq.query_stations(network='CB', station='*')
bq.send_mail(starttime=UTCDateTime(2015, 1, 1), endtime=UTCDateTime(2015, 2, 1), arrange='continue')
# bq.write_mail(time_before=0, time_after=1000)
# bq.write_mail(mark="P", time_before=-100, time_after=300)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment