Created
November 16, 2017 07:16
-
-
Save return0927/0aaaebd5dee15411cfd8412b54c1a545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime, timedelta | |
class _IRIS: | |
def __init__(self): | |
self.api = "http://service.iris.edu/irisws/timeseries/1/query" \ | |
"?output=plot" \ | |
"&ref=direct" \ | |
"&width=600" \ | |
"&height=200" \ | |
"&net=%s" \ | |
"&sta=%s" \ | |
"&loc=--" \ | |
"&start=%s" \ | |
"&dur=180" \ | |
"&cha=%s" | |
self.seismometer = { | |
"Network": "KG", | |
"Station": "TJN" | |
} | |
def updateSeismometer(self, network, station): | |
self.seismometer['Network'] = network | |
self.seismometer['Station'] = station | |
def getTime(self): | |
return (datetime.utcnow()-timedelta(minutes=3)).strftime("%Y-%m-%dT%H:%M:%S") | |
def getImage(self, debug=False): | |
try: | |
url = self.api % ( | |
self.seismometer['Network'], | |
self.seismometer['Station'], | |
self.getTime(), | |
"BHZ" | |
) | |
if debug: print(url) | |
resp = requests.get(url) | |
return [False, resp.content] | |
except Exception as ex: | |
return [True, ex] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment