def SaveRain(observationdate, rainfall):
    try:
        cur.execute(
            """INSERT INTO rain (observationdate, precipitation)
                     SELECT %(obsdate)s, %(rain)s
                     WHERE NOT EXISTS (
                         SELECT * FROM rain WHERE observationdate = %(obsdate)s
                     );""", {
                'obsdate': observationdate,
                'rain': rainfall
            })
        conn.commit()

    except:
        mailer.NotificationMail(
            notificationlist, 'Weather Portal Error - rain',
            'Database error saving rain observations. See rain.py, weatherdb.py and mailx.'
        )
def SaveWind(observationdate, windspeed, winddirection):
    try:
        cur.execute(
            """INSERT INTO wind (observationdate, speed, direction)
                     SELECT %(obsdate)s, %(speed)s, %(dir)s
                     WHERE NOT EXISTS (
                         SELECT * FROM wind WHERE observationdate = %(obsdate)s
                     );""", {
                'obsdate': observationdate,
                'speed': windspeed,
                'dir': winddirection
            })
        conn.commit()

    except:
        mailer.NotificationMail(
            notificationlist, 'Weather Portal Error - wind',
            'Database error saving wind observations. See wind.py, weatherdb.py and mailx.'
        )
def SaveRiver(observationdate, flowrate, height):
    try:
        cur.execute(
            """INSERT INTO river (observationdate, flowrate, height)
                     SELECT %(obsdate)s, %(flow)s, %(ht)s
                     WHERE NOT EXISTS (
                         SELECT * FROM river WHERE observationdate = %(obsdate)s
                     );""", {
                'obsdate': observationdate,
                'flow': flowrate,
                'ht': height
            })
        conn.commit()

    except:
        mailer.NotificationMail(
            notificationlist, 'Weather Portal Error - river',
            'Database error saving river observations. See river.py, weatherdb.py and mailx.'
        )
def SaveSalinity(observationdate, salinity, turbidity):
    try:
        cur.execute(
            """INSERT INTO turbidity (observationdate, salinity, turbidity) 
                  SELECT %(obsdate)s, %(sal)s, %(turb)s
                  WHERE NOT EXISTS (
                      SELECT * FROM turbidity WHERE observationdate = %(obsdate)s
                  );""", {
                'obsdate': observationdate,
                'sal': salinity,
                'turb': turbidity
            })
        conn.commit()

    except:
        mailer.NotificationMail(
            notificationlist, 'Weather Portal Error - salinity',
            'Database error saving salinity/turbidity observations. See salinity.py, weatherdb.py and mailx.'
        )
def SaveWaves(observationdate, height, direction, period):
    try:
        cur.execute(
            """INSERT INTO waves (observationdate, height, direction, period)
                     SELECT %(obsdate)s, %(ht)s, %(dir)s, %(per)s
                     WHERE NOT EXISTS (
                         SELECT * FROM waves WHERE observationdate = %(obsdate)s
                     );""", {
                'obsdate': observationdate,
                'ht': height,
                'dir': direction,
                'per': period
            })
        conn.commit()

    except:
        mailer.NotificationMail(
            notificationlist, 'Weather Portal Error - waves',
            'Database error saving wave observations. See waves.py, weatherdb.py and mailx.'
        )
Beispiel #6
0
import mailer

notificationlist = [CSV_EMAIL_LIST_WITH_SINGLE_QUOTES]
#req = urllib2.Request("http://www.prh.noaa.gov/hnl/graphics/gtwo_gsat.gif")
try:
    req = urllib2.Request("http://www.ssd.noaa.gov/goes/west/hi/rb-l.jpg")
    response = urllib2.urlopen(req)
    #BASE_DIR = '/home/dgraham/Documents/'
    BASE_DIR = '/var/www/html/mokupapapa/weather/'
    output = open(BASE_DIR + 'new_file.jpg','wb')
    output.write(response.read())
    output.close()
    #IOError:
    newmd5 = hashlib.md5(open(BASE_DIR + 'new_file.jpg').read()).hexdigest()
    #print(str(newmd5))

    oldmd5 = hashlib.md5(open(BASE_DIR + 'sat_img.jpg').read()).hexdigest()
    #print(str(oldmd5))

    if(newmd5 != oldmd5):
        os.remove(BASE_DIR + 'sat_img.jpg')
        os.rename(BASE_DIR + 'new_file.jpg', BASE_DIR + 'sat_img.jpg')
        #mailer.NotificationMail(['*****@*****.**'], 'New Satellite Image', 'Got a new satellite image')
    else:
        os.remove(BASE_DIR + 'new_file.jpg')
        #mailer.NotificationMail(['*****@*****.**'], 'Old Satellite Image', 'Got an old satellite image')

except Exception as e:
    msg = 'Processing error saving satellite image. See satellite.py and mailx. URL requested was = http://www.ssd.noaa.gov/goes/west/hi/rb-l.jpg'
    mailer.NotificationMail(notificationlist, 'Satellite Ingester Error', msg + ' - ' + str(repr(e)))
Beispiel #7
0
        "http://waterservices.usgs.gov/nwis/iv/?format=json&sites=16704000&parameterCd=00060"
    )
    response = urllib2.urlopen(url)
    the_page = response.read()
    the_json = json.loads(the_page)
    river_flow = the_json["value"]["timeSeries"][0]["values"][0]["value"][0][
        "value"]
    '''Retrieves the Wailuku River height in feet'''
    url = urllib2.Request(
        "http://waterservices.usgs.gov/nwis/iv/?format=json&sites=16704000&parameterCd=00065"
    )
    response = urllib2.urlopen(url)
    the_page = response.read()
    the_json = json.loads(the_page)
    river_height = the_json["value"]["timeSeries"][0]["values"][0]["value"][0][
        "value"]

    #calculate the response timestamp from the time
    datestring = the_json["value"]["timeSeries"][0]["values"][0]["value"][0][
        "dateTime"]
    obsdate = datetime.datetime(int(datestring[:4]), int(datestring[5:7]),
                                int(datestring[8:10]), int(datestring[11:13]),
                                int(datestring[14:16]), int(datestring[17:19]))

    weatherdb.SaveRiver(obsdate, river_flow, river_height)

except Exception as e:
    msg = 'Processing error saving river observations. See river.py and mailx. URL requested was = ' + url
    mailer.NotificationMail(notificationlist, 'Weather Portal Error - river',
                            msg + ' - ' + str(repr(e)))
Beispiel #8
0
#get current datetime in UTC (+10 hours)
dt = datetime.datetime.now() + datetime.timedelta(hours=10)
datest = dt.strftime("%Y%m%d")
url = 'http://opendap.co-ops.nos.noaa.gov/axis/webservices/wind/response.jsp?stationId=1617760&beginDate=' + datest + '&endDate=' + datest + '&unit=Meters&timeZone=0&format=xml&Submit=Submit'
try:
    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    the_page = response.read()
    the_xml = html.parse(url)
    root = the_xml.xpath('.//data/*')
    lastelt = root[-1]
    timestamp = lastelt.findtext("timestamp")
    obsdate = datetime.datetime(int(timestamp[:4]), int(timestamp[5:7]),
                                int(timestamp[8:10]), int(timestamp[11:13]),
                                int(timestamp[14:16]))
    windspeed = decimal.Decimal(lastelt.findtext("ws"))
    winddir = int(lastelt.findtext("wd"))
    #IOError

except Exception as e:
    msg = 'Processing error saving wind observations. See wind.py and mailx. URL requested was = ' + url
    mailer.NotificationMail(notificationlist, 'Wind Ingester Error',
                            msg + ' - ' + str(repr(e)))

else:
    try:
        weatherdb.SaveWind(obsdate, windspeed, winddir)

    except:
        raise
Beispiel #9
0
    url = 'http://cdip.ucsd.edu/cgi-bin/pm_download?station=188&year=' + dt.strftime(
        "%Y") + '&month=' + dt.strftime(
            "%m") + '&public=public&stream_label=p1'

    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    the_page = response.read()

    #split the url response into lines which gives us an array from which we then remove excess whitespace
    lines = the_page.split('\n')
    lines = [line.strip() for line in lines]

    #the first four lines are headers and the last line is empty
    for line in lines[4:-1]:
        splitter = re.split('\s+', line)
        obsdate = datetime.datetime(int(splitter[0]), int(splitter[1]),
                                    int(splitter[2]), int(splitter[3]),
                                    int(splitter[4]))
        wave_height = splitter[5]
        wave_direction = splitter[7]
        wave_period = splitter[6]
        weatherdb.SaveWaves(obsdate, wave_height, wave_direction, wave_period)

    #mailer.NotificationMail(notificationlist, 'Weather Portal - waves', 'Waves worked.')

except Exception as e:
    msg = 'Processing error saving wave observations. See waves.py and mailx. URL requested was = ' + url
    mailer.NotificationMail(notificationlist, 'Weather Portal Error - waves',
                            msg + str(repr(e)))