In [13]:
import sqlite3
import os.path
import csv
import json
import numpy as np
import requests
from bs4 import BeautifulSoup

db_name = 'sample.db'

In [14]:
if os.path.isfile(db_name):
    os.remove(db_name)

conn = sqlite3.connect(db_name)
c = conn.cursor()        
          
# create ooi instruments
c.execute('''CREATE TABLE ooi_instruments
(
  ref_code text NOT NULL,
  array_code text NOT NULL,
  site_prefix text NOT NULL,  
  site_suffix text NOT NULL,
  node_type_code text NOT NULL,
  node_site_seq text NOT NULL,
  port_number text NOT NULL,
  instrument_class text NOT NULL,
  instrument_series text NOT NULL,
  instrument_seq text NOT NULL,
  latitude real,
  longitude real
)''')


Out[14]:
<sqlite3.Cursor at 0x112b5b3b0>

In [15]:
lat_lon_dict = {}
with open('platform_ports.csv', 'rb') as csvfile:
    csvreader = csv.reader(csvfile, delimiter=';', quotechar='|')
    for row in csvreader:
        #CE01ISSM-MF004-01-DOSTAD999
        datarow = ""
        valarray = []   
        array = row[0]
        site_prefix = "0"+row[1]
        site_suffix = row[2]
        node_type_code = row[3]
        
        try:
            lat = float(row[5])
            lon = float(row[6])
        except:
            lat = '-999'
            lon = '-999'
        
        loc = "".join([array,site_prefix,site_suffix])
        if loc not in lat_lon_dict:
            lat_lon_dict[loc]= {"lat":lat,"lon":lon}
            print "".join([array,site_prefix,site_suffix]),lat,lon


CE04OSBP 44.37 124.95
CE02SHSM 44.64 124.31
CE02SHSP 44.64 124.31
CE05MOAS -999 -999
CP05MOAS -999 -999
GS05MOAS -999 -999
GA05MOAS -999 -999
GI05MOAS -999 -999
CE06ISSM 47.13 124.27
CE06ISSP 47.13 124.27
CP03ISSP 40.36 70.88
CP04OSPM 39.94 70.88
CP04OSSM 39.94 70.88
GA01SUMO -42.991 42.5104
GA03FLMA -42.5073 42.8905
GA03FLMB -42.5073 42.1303
GP02HYPM 50.0706 144.798
GI01SUMO 60.6136 38.2581
GI02HYPM 60.5732 38.2581
GP03FLMA 49.9795 144.254
GP03FLMB 50.3316 144.401
GS01SUMO -54.4704 89.2796
GS03FLMB -54.0814 88.894
RS03ECAL 45.948 129.981
RS03INT1 45.9357 130.015
RS03INT2 45.9357 130.014
CE04OSHY 44.37 124.95
GP05MOAS -999 -999
CE01ISSM 44.66 124.1
CE01ISSP 44.66 124.1
CE02SHBP 44.64 124.31
CE04OSSM 44.37 124.95
CE07SHSM 46.99 124.57
CE07SHSP 46.99 124.57
CE09OSPM 46.85 124.97
CE09OSSM 46.85 124.97
CP01CNSM 40.14 70.78
CP01CNSP 40.14 70.78
CP02PMCI 40.23 70.88
CP02PMCO 40.1 70.88
CP02PMUI 40.37 70.78
CP02PMUO 39.94 70.78
CP03ISSM 40.36 70.88
GA02HYPM -42.9222 42.5104
GI03FLMA 60.4582 38.4407
GI03FLMB 60.4582 38.0755
GS02HYPM -54.407 89.2796
GS03FLMA -54.0814 89.6652
RS01SBVM 44.554 125.352
RS01SLBS 44.554 125.352
RS01SUM1 44.568 125.15
RS01SUM2 44.57 125.147
RS03AXBS 46.1082 129.618
RS03AXVM 46.067 129.603
RS03CCAL 45.9762 130.02
RS03ASHS 45.9362 130.014

In [16]:
json_data=open('ref_list.json')
data = json.load(json_data)
for r in data:
    array_code = r[0:2]
    site_prefix = r[2:4]
    site_suffix = r[4:8]
    #skip one
    node_type_code = r[9:10]
    node_site_seq = r[10:14]
    #skip on
    port_number = r[15:17]
    #skip on
    instrument_class = r [18:23]
    instrument_series = r [23:24]
    instrument_seq = r [24:27]
    
    loc = "".join([array_code,site_prefix,site_suffix])
    lat = lat_lon_dict[loc]["lat"]
    lon = lat_lon_dict[loc]["lon"]
    
    ref = "','".join([r,array_code,site_prefix,site_suffix,node_type_code,node_site_seq,port_number,instrument_class,instrument_series,instrument_seq,str(lat),str(lon)])
    #ref = "".join([array_code,site_prefix,site_suffix,node_type_code,node_site_seq,port_number,instrument_class,instrument_series,instrument_seq])   
    #print ref    
    print r
    query = "INSERT INTO ooi_instruments VALUES ('"+ref+"')"
    c.execute(query)
    
conn.commit()


CE01ISSM-MF004-01-DOSTAD999
CE01ISSM-MF004-02-PHSEND999
CE01ISSM-MF004-03-OPTAAD999
CE01ISSM-MF004-04-PCO2WB999
CE01ISSM-MF004-05-ADCPTM999
CE01ISSM-MF005-01-CTDBPC999
CE01ISSM-MF005-02-ZPLSCC999
CE01ISSM-MF005-03-VEL3DD999
CE01ISSM-MF005-04-PRESFA999
CE01ISSM-MF005-05-CAMDSA999
CE01ISSM-RI002-01-DOSTAD999
CE01ISSM-RI002-02-VELPTA999
CE01ISSM-RI002-03-PHSEND999
CE01ISSM-RI002-05-PCO2WB999
CE01ISSM-RI003-01-CTDBPC999
CE01ISSM-RI003-02-FLORTD999
CE01ISSM-RI003-03-OPTAAD999
CE01ISSM-RI003-04-NUTNRB999
CE01ISSM-RI003-05-SPKIRB999
CE01ISSM-SB001-01-VELPTA999
CE01ISSP-SP001-02-DOSTAJ999
CE01ISSP-SP001-04-OPTAAJ999
CE01ISSP-SP001-05-VELPTJ999
CE01ISSP-SP001-06-NUTNRJ999
CE01ISSP-SP001-07-SPKIRJ999
CE01ISSP-SP001-08-FLORTJ999
CE01ISSP-SP001-09-CTDPFJ999
CE01ISSP-SP001-10-PARADJ999
CE02SHBP-LJ01D-05-ADCPTB104
CE02SHBP-LJ01D-06-CTDBPN106
CE02SHBP-LJ01D-06-DOSTAD106
CE02SHBP-LJ01D-07-VEL3DC108
CE02SHBP-LJ01D-08-OPTAAD106
CE02SHBP-LJ01D-09-PCO2WB103
CE02SHBP-LJ01D-10-PHSEND103
CE02SHBP-LJ01D-11-HYDBBA106
CE02SHBP-LJ01D-12-CAMDSB107
CE02SHBP-MJ01C-07-ZPLSCB101
CE02SHSM-RI002-01-DOSTAD999
CE02SHSM-RI002-02-VELPTA999
CE02SHSM-RI002-03-PHSEND999
CE02SHSM-RI002-05-CTDBPC999
CE02SHSM-RI003-01-ADCPTA999
CE02SHSM-RI003-02-OPTAAD999
CE02SHSM-RI003-03-NUTNRB999
CE02SHSM-RI003-04-SPKIRB999
CE02SHSM-RI003-05-FLORTD999
CE02SHSM-SB001-01-METBKA999
CE02SHSM-SB001-03-PCO2AA999
CE02SHSM-SB001-04-FDCHPA999
CE02SHSM-SB001-05-VELPTA999
CE02SHSM-SB001-06-WAVSSA999
CE02SHSP-SP001-01-CTDPFJ999
CE02SHSP-SP001-01-DOSTAJ999
CE02SHSP-SP001-02-VELPTJ999
CE02SHSP-SP001-04-OPTAAJ999
CE02SHSP-SP001-05-NUTNRJ999
CE02SHSP-SP001-06-SPKIRJ999
CE02SHSP-SP001-07-FLORTJ999
CE02SHSP-SP001-08-PARADJ999
CE04OSBP-LJ01C-05-ADCPSI103
CE04OSBP-LJ01C-06-CTDBPO108
CE04OSBP-LJ01C-06-DOSTAD108
CE04OSBP-LJ01C-07-VEL3DC107
CE04OSBP-LJ01C-08-OPTAAC104
CE04OSBP-LJ01C-09-PCO2WB104
CE04OSBP-LJ01C-10-PHSEND107
CE04OSBP-LJ01C-11-HYDBBA105
CE04OSBP-LJ01C-12-CAMDSB106
CE04OSHY-DP01B-01-CTDPFL105
CE04OSHY-DP01B-02-VEL3DA105
CE04OSHY-DP01B-04-FLORTA103
CE04OSHY-DP01B-06-DOSTAD105
CE04OSHY-PC01B-05-PHSENA106
CE04OSHY-PC01B-08-ZPLSCB102
CE04OSHY-PC01B-12-PCO2WA105
CE04OSHY-PC01B-4A-CTDPFA109
CE04OSHY-PC01B-4A-DOSTAD109
CE04OSHY-SF01B-02-VELPTD106
CE04OSHY-SF01B-03-FLORTD104
CE04OSHY-SF01B-04-NUTNRA102
CE04OSHY-SF01B-05-PCO2WA102
CE04OSHY-SF01B-06-PARADA102
CE04OSHY-SF01B-07-SPKIRA102
CE04OSHY-SF01B-08-CTDPFA107
CE04OSHY-SF01B-08-DOFSTA107
CE04OSHY-SF01B-09-OPTAAD105
CE04OSHY-SF01B-2B-PHSENA108
CE04OSSM-RI002-01-DOSTAD999
CE04OSSM-RI002-02-VELPTA999
CE04OSSM-RI002-03-PHSEND999
CE04OSSM-RI002-05-CTDBPC999
CE04OSSM-RI003-01-ADCPTC999
CE04OSSM-RI003-02-OPTAAD999
CE04OSSM-RI003-03-NUTNRB999
CE04OSSM-RI003-04-SPKIRB999
CE04OSSM-RI003-05-FLORTD999
CE04OSSM-SB001-01-METBKA999
CE04OSSM-SB001-03-PCO2AA999
CE04OSSM-SB001-05-VELPTA999
CE04OSSM-SB001-06-WAVSSA999
CE05MOAS-GL001-01-PARADM999
CE05MOAS-GL001-02-FLORTM999
CE05MOAS-GL001-03-ADCPAM999
CE05MOAS-GL001-04-DOSTAM999
CE05MOAS-GL001-05-CTDGVM999
CE05MOAS-GL002-01-PARADM999
CE05MOAS-GL002-02-FLORTM999
CE05MOAS-GL002-03-ADCPAM999
CE05MOAS-GL002-04-DOSTAM999
CE05MOAS-GL002-05-CTDGVM999
CE05MOAS-GL003-01-PARADM999
CE05MOAS-GL003-02-FLORTM999
CE05MOAS-GL003-03-ADCPAM999
CE05MOAS-GL003-04-DOSTAM999
CE05MOAS-GL003-05-CTDGVM999
CE05MOAS-GL004-01-PARADM999
CE05MOAS-GL004-02-FLORTM999
CE05MOAS-GL004-03-ADCPAM999
CE05MOAS-GL004-04-DOSTAM999
CE05MOAS-GL004-05-CTDGVM999
CE05MOAS-GL005-01-PARADM999
CE05MOAS-GL005-02-FLORTM999
CE05MOAS-GL005-03-ADCPAM999
CE05MOAS-GL005-04-DOSTAM999
CE05MOAS-GL005-05-CTDGVM999
CE05MOAS-GL006-01-PARADM999
CE05MOAS-GL006-02-FLORTM999
CE05MOAS-GL006-03-ADCPAM999
CE05MOAS-GL006-04-DOSTAM999
CE05MOAS-GL006-05-CTDGVM999
CE06ISSM-MF004-01-DOSTAD999
CE06ISSM-MF004-02-PHSEND999
CE06ISSM-MF004-03-OPTAAD999
CE06ISSM-MF004-04-PCO2WB999
CE06ISSM-MF004-05-ADCPTM999
CE06ISSM-MF005-01-CTDBPC999
CE06ISSM-MF005-02-ZPLSCC999
CE06ISSM-MF005-03-VEL3DD999
CE06ISSM-MF005-04-PRESFA999
CE06ISSM-MF005-05-CAMDSA999
CE06ISSM-RI002-01-DOSTAD999
CE06ISSM-RI002-02-VELPTA999
CE06ISSM-RI002-03-PHSEND999
CE06ISSM-RI002-05-PCO2WB999
CE06ISSM-RI003-01-CTDBPC999
CE06ISSM-RI003-02-FLORTD999
CE06ISSM-RI003-03-OPTAAD999
CE06ISSM-RI003-04-NUTNRB999
CE06ISSM-RI003-05-SPKIRB999
CE06ISSM-SB001-01-VELPTA999
CE06ISSP-SP001-02-DOSTAJ999
CE06ISSP-SP001-04-OPTAAJ999
CE06ISSP-SP001-05-VELPTJ999
CE06ISSP-SP001-06-NUTNRJ999
CE06ISSP-SP001-07-SPKIRJ999
CE06ISSP-SP001-08-FLORTJ999
CE06ISSP-SP001-09-CTDPFJ999
CE06ISSP-SP001-10-PARADJ999
CE07SHSM-MF004-01-DOSTAD999
CE07SHSM-MF004-02-PHSEND999
CE07SHSM-MF004-03-OPTAAD999
CE07SHSM-MF004-04-PCO2WB999
CE07SHSM-MF004-05-CTDBPC999
CE07SHSM-MF005-01-PRESFB999
CE07SHSM-MF005-02-CAMDSA999
CE07SHSM-MF005-03-ZPLSCC999
CE07SHSM-MF005-04-ADCPTC999
CE07SHSM-MF005-05-VEL3DD999
CE07SHSM-RI002-01-DOSTAD999
CE07SHSM-RI002-02-VELPTA999
CE07SHSM-RI002-03-PHSEND999
CE07SHSM-RI002-05-CTDBPC999
CE07SHSM-RI003-01-ADCPTA999
CE07SHSM-RI003-02-OPTAAD999
CE07SHSM-RI003-03-NUTNRB999
CE07SHSM-RI003-04-SPKIRB999
CE07SHSM-RI003-05-FLORTD999
CE07SHSM-SB001-01-METBKA999
CE07SHSM-SB001-03-PCO2AA999
CE07SHSM-SB001-05-VELPTA999
CE07SHSM-SB001-06-WAVSSA999
CE07SHSP-SP001-01-DOSTAJ999
CE07SHSP-SP001-02-VELPTJ999
CE07SHSP-SP001-04-OPTAAJ999
CE07SHSP-SP001-05-NUTNRJ999
CE07SHSP-SP001-06-SPKIRJ999
CE07SHSP-SP001-07-FLORTJ999
CE07SHSP-SP001-08-CTDPFJ999
CE07SHSP-SP001-09-PARADJ999
CE09OSPM-WF001-01-VEL3DK999
CE09OSPM-WF001-02-DOFSTK999
CE09OSPM-WF001-03-CTDPFK999
CE09OSPM-WF001-04-FLORTK999
CE09OSPM-WF001-05-PARADK999
CE09OSSM-MF004-01-DOSTAD999
CE09OSSM-MF004-02-OPTAAC999
CE09OSSM-MF004-03-PCO2WB999
CE09OSSM-MF004-04-ADCPSJ999
CE09OSSM-MF004-05-PHSEND999
CE09OSSM-MF005-00-ZPLSCC000
CE09OSSM-MF005-01-CTDBPE999
CE09OSSM-MF005-02-PRESFC999
CE09OSSM-MF005-03-CAMDSA999
CE09OSSM-MF005-04-VEL3DD999
CE09OSSM-RI002-01-DOSTAD999
CE09OSSM-RI002-02-VELPTA999
CE09OSSM-RI002-03-PHSEND999
CE09OSSM-RI002-05-CTDBPC999
CE09OSSM-RI003-01-ADCPTC999
CE09OSSM-RI003-02-OPTAAD999
CE09OSSM-RI003-03-NUTNRB999
CE09OSSM-RI003-04-SPKIRB999
CE09OSSM-RI003-05-FLORTD999
CE09OSSM-SB001-01-METBKA999
CE09OSSM-SB001-03-PCO2AA999
CE09OSSM-SB001-05-VELPTA999
CE09OSSM-SB001-06-WAVSSA999
CP01CNSM-MF004-01-ADCPTF999
CP01CNSM-MF004-02-OPTAAD999
CP01CNSM-MF004-03-DOSTAD999
CP01CNSM-MF004-04-VELPTA999
CP01CNSM-MF004-05-PHSEND999
CP01CNSM-MF005-01-PCO2WB999
CP01CNSM-MF005-02-CTDBPD999
CP01CNSM-MF005-03-ZPLSCC999
CP01CNSM-MF005-04-PRESFB999
CP01CNSM-RI002-02-OPTAAD999
CP01CNSM-RI002-03-CTDBPC999
CP01CNSM-RI002-04-VELPTA999
CP01CNSM-RI003-01-NUTNRB999
CP01CNSM-RI003-02-DOSTAD999
CP01CNSM-RI003-03-PHSEND999
CP01CNSM-RI003-04-SPKIRB999
CP01CNSM-RI003-05-FLORTD999
CP01CNSM-SB001-01-METBKA999
CP01CNSM-SB001-02-METBKA999
CP01CNSM-SB001-03-PCO2AA999
CP01CNSM-SB001-04-WAVSSA999
CP01CNSM-SB001-05-FDCHPA999
CP01CNSP-SP001-02-OPTAAJ999
CP01CNSP-SP001-03-NUTNRJ999
CP01CNSP-SP001-05-VELPTJ999
CP01CNSP-SP001-06-DOSTAJ999
CP01CNSP-SP001-07-SPKIRJ999
CP01CNSP-SP001-08-CTDPFJ999
CP01CNSP-SP001-09-FLORTJ999
CP01CNSP-SP001-10-PARADJ999
CP02PMCI-RI001-01-ADCPTG999
CP02PMCI-WF001-01-VEL3DK999
CP02PMCI-WF001-02-DOFSTK999
CP02PMCI-WF001-03-CTDPFK999
CP02PMCI-WF001-04-FLORTK999
CP02PMCI-WF001-05-PARADK999
CP02PMCO-RI001-01-ADCPTG999
CP02PMCO-WF001-01-VEL3DK999
CP02PMCO-WF001-02-DOFSTK999
CP02PMCO-WF001-03-CTDPFK999
CP02PMCO-WF001-04-FLORTK999
CP02PMCO-WF001-05-PARADK999
CP02PMUI-RI001-01-ADCPTG999
CP02PMUI-WF001-01-VEL3DK999
CP02PMUI-WF001-02-DOFSTK999
CP02PMUI-WF001-03-CTDPFK999
CP02PMUI-WF001-04-FLORTK999
CP02PMUI-WF001-05-PARADK999
CP02PMUO-RI001-01-ADCPSL999
CP02PMUO-WF001-01-VEL3DK999
CP02PMUO-WF001-02-DOFSTK999
CP02PMUO-WF001-03-CTDPFK999
CP02PMUO-WF001-04-FLORTK999
CP02PMUO-WF001-05-PARADK999
CP03ISSM-MF004-01-DOSTAD999
CP03ISSM-MF004-03-VELPTA999
CP03ISSM-MF004-04-CTDBPD999
CP03ISSM-MF004-05-PHSEND999
CP03ISSM-MF005-01-PCO2WB999
CP03ISSM-MF005-02-PRESFB999
CP03ISSM-MF005-03-ADCPTF999
CP03ISSM-MF005-04-OPTAAD999
CP03ISSM-MF005-05-ZPLSCC999
CP03ISSM-RI002-01-PHSEND999
CP03ISSM-RI002-02-OPTAAD999
CP03ISSM-RI002-03-SPKIRB999
CP03ISSM-RI002-04-DOSTAD999
CP03ISSM-RI003-01-NUTNRB999
CP03ISSM-RI003-03-VELPTA999
CP03ISSM-RI003-04-CTDBPC999
CP03ISSM-RI003-05-FLORTD999
CP03ISSM-SB001-01-METBKA999
CP03ISSM-SB001-03-PCO2AA999
CP03ISSP-SP001-02-OPTAAJ999
CP03ISSP-SP001-03-NUTNRJ999
CP03ISSP-SP001-05-VELPTJ999
CP03ISSP-SP001-06-DOSTAJ999
CP03ISSP-SP001-07-SPKIRJ999
CP03ISSP-SP001-08-CTDPFJ999
CP03ISSP-SP001-09-FLORTJ999
CP03ISSP-SP001-10-PARADJ999
CP04OSPM-WF001-01-VEL3DK999
CP04OSPM-WF001-02-DOFSTK999
CP04OSPM-WF001-03-CTDPFK999
CP04OSPM-WF001-04-FLORTK999
CP04OSPM-WF001-05-PARADK999
CP04OSSM-MF004-01-DOSTAD999
CP04OSSM-MF004-03-VELPTB999
CP04OSSM-MF004-04-CTDBPE999
CP04OSSM-MF004-05-PHSEND999
CP04OSSM-MF005-01-PCO2WB999
CP04OSSM-MF005-02-PRESFC999
CP04OSSM-MF005-03-ADCPSJ999
CP04OSSM-MF005-04-OPTAAD999
CP04OSSM-MF005-05-ZPLSCC999
CP04OSSM-RI002-01-PHSEND999
CP04OSSM-RI002-02-OPTAAD999
CP04OSSM-RI002-03-SPKIRB999
CP04OSSM-RI002-04-DOSTAD999
CP04OSSM-RI003-01-NUTNRB999
CP04OSSM-RI003-03-VELPTA999
CP04OSSM-RI003-04-CTDBPC999
CP04OSSM-RI003-05-FLORTD999
CP04OSSM-SB001-02-METBKA999
CP04OSSM-SB001-03-PCO2AA999
CP05MOAS-AV001-01-FLORTN999
CP05MOAS-AV001-02-DOSTAN999
CP05MOAS-AV001-03-CTDAVN999
CP05MOAS-AV001-04-NUTNRN999
CP05MOAS-AV001-05-ADCPAN999
CP05MOAS-AV001-06-PARADN999
CP05MOAS-AV002-01-FLORTN999
CP05MOAS-AV002-02-DOSTAN999
CP05MOAS-AV002-03-CTDAVN999
CP05MOAS-AV002-04-NUTNRN999
CP05MOAS-AV002-05-ADCPAN999
CP05MOAS-AV002-06-PARADN999
CP05MOAS-GL001-01-ADCPAM999
CP05MOAS-GL001-02-FLORTM999
CP05MOAS-GL001-03-CTDGVM999
CP05MOAS-GL001-04-DOSTAM999
CP05MOAS-GL001-05-PARADM999
CP05MOAS-GL002-01-ADCPAM999
CP05MOAS-GL002-02-FLORTM999
CP05MOAS-GL002-03-CTDGVM999
CP05MOAS-GL002-04-DOSTAM999
CP05MOAS-GL002-05-PARADM999
CP05MOAS-GL003-01-ADCPAM999
CP05MOAS-GL003-02-FLORTM999
CP05MOAS-GL003-03-CTDGVM999
CP05MOAS-GL003-04-DOSTAM999
CP05MOAS-GL003-05-PARADM999
CP05MOAS-GL004-01-ADCPAM999
CP05MOAS-GL004-02-FLORTM999
CP05MOAS-GL004-03-CTDGVM999
CP05MOAS-GL004-04-DOSTAM999
CP05MOAS-GL004-05-PARADM999
CP05MOAS-GL005-01-ADCPAM999
CP05MOAS-GL005-02-FLORTM999
CP05MOAS-GL005-03-CTDGVM999
CP05MOAS-GL005-04-DOSTAM999
CP05MOAS-GL005-05-PARADM999
CP05MOAS-GL006-01-ADCPAM999
CP05MOAS-GL006-02-FLORTM999
CP05MOAS-GL006-03-CTDGVM999
CP05MOAS-GL006-04-DOSTAM999
CP05MOAS-GL006-05-PARADM999
GA01SUMO-RI002-02-CTDBPF999
GA01SUMO-RI002-03-ADCPSN999
GA01SUMO-RI002-04-FLORTD999
GA01SUMO-RI002-05-VELPTA999
GA01SUMO-RI003-01-PHSENE999
GA01SUMO-RI003-02-PHSENE999
GA01SUMO-RI003-03-CTDMOQ999
GA01SUMO-RI003-05-CTDMOQ999
GA01SUMO-RI003-06-CTDMOQ999
GA01SUMO-RI003-08-CTDMOQ999
GA01SUMO-RI003-09-CTDMOQ999
GA01SUMO-RI003-10-CTDMOQ999
GA01SUMO-RI003-11-CTDMOQ999
GA01SUMO-RI003-12-CTDMOR999
GA01SUMO-RI003-13-CTDMOR999
GA01SUMO-RI003-14-CTDMOR999
GA01SUMO-SB001-01-METBKA999
GA01SUMO-SB001-02-METBKA999
GA01SUMO-SB001-03-PCO2AA999
GA01SUMO-SB001-05-WAVSSA999
GA02HYPM-MP003-01-ZPLSGA999
GA02HYPM-WF002-01-FLORDL999
GA02HYPM-WF002-03-DOSTAL999
GA02HYPM-WF002-04-CTDPFL999
GA02HYPM-WF002-05-VEL3DL999
GA02HYPM-WF004-01-FLORDL999
GA02HYPM-WF004-03-DOSTAL999
GA02HYPM-WF004-04-CTDPFL999
GA02HYPM-WF004-05-VEL3DL999
GA03FLMA-RI001-01-FLORTD999
GA03FLMA-RI001-02-PHSENF999
GA03FLMA-RI001-03-DOSTAD999
GA03FLMA-RI001-04-ADCPSL999
GA03FLMA-RI001-06-CTDMOG999
GA03FLMA-RI001-07-CTDMOG999
GA03FLMA-RI001-08-CTDMOG999
GA03FLMA-RI001-09-CTDMOG999
GA03FLMA-RI001-10-CTDMOG999
GA03FLMA-RI001-11-CTDMOG999
GA03FLMA-RI001-12-CTDMOG999
GA03FLMA-RI001-13-CTDMOG999
GA03FLMA-RI001-14-CTDMOG999
GA03FLMA-RI001-15-CTDMOH999
GA03FLMA-RI001-16-CTDMOH999
GA03FLMA-RI001-17-CTDMOH999
GA03FLMB-RI001-01-FLORTD999
GA03FLMB-RI001-02-PHSENF999
GA03FLMB-RI001-03-DOSTAD999
GA03FLMB-RI001-04-ADCPSL999
GA03FLMB-RI001-06-CTDMOG999
GA03FLMB-RI001-07-CTDMOG999
GA03FLMB-RI001-08-CTDMOG999
GA03FLMB-RI001-09-CTDMOG999
GA03FLMB-RI001-10-CTDMOG999
GA03FLMB-RI001-11-CTDMOG999
GA03FLMB-RI001-12-CTDMOG999
GA03FLMB-RI001-13-CTDMOG999
GA03FLMB-RI001-14-CTDMOG999
GA03FLMB-RI001-15-CTDMOH999
GA03FLMB-RI001-16-CTDMOH999
GA03FLMB-RI001-17-CTDMOH999
GA05MOAS-GL001-01-FLORDM999
GA05MOAS-GL001-02-DOSTAM999
GA05MOAS-GL001-04-CTDGVM999
GA05MOAS-GL002-01-FLORDM999
GA05MOAS-GL002-02-DOSTAM999
GA05MOAS-GL002-04-CTDGVM999
GA05MOAS-GL003-01-FLORDM999
GA05MOAS-GL003-02-DOSTAM999
GA05MOAS-GL003-04-CTDGVM999
GI01SUMO-RI002-02-CTDBPF999
GI01SUMO-RI002-03-ADCPSN999
GI01SUMO-RI002-04-FLORTD999
GI01SUMO-RI002-05-VELPTA999
GI01SUMO-RI003-01-PHSENE999
GI01SUMO-RI003-02-PHSENE999
GI01SUMO-RI003-03-CTDMOQ999
GI01SUMO-RI003-05-CTDMOQ999
GI01SUMO-RI003-06-CTDMOQ999
GI01SUMO-RI003-08-CTDMOQ999
GI01SUMO-RI003-09-CTDMOQ999
GI01SUMO-RI003-10-CTDMOQ999
GI01SUMO-RI003-11-CTDMOQ999
GI01SUMO-RI003-12-CTDMOR999
GI01SUMO-RI003-13-CTDMOR999
GI01SUMO-RI003-14-CTDMOR999
GI01SUMO-SB001-01-METBKA999
GI01SUMO-SB001-02-METBKA999
GI01SUMO-SB001-03-PCO2AA999
GI01SUMO-SB001-04-FDCHPA999
GI01SUMO-SB001-05-WAVSSA999
GI02HYPM-MP003-01-ZPLSGA999
GI02HYPM-WF002-01-FLORDL999
GI02HYPM-WF002-03-DOSTAL999
GI02HYPM-WF002-04-CTDPFL999
GI02HYPM-WF002-05-VEL3DL999
GI03FLMA-RI001-01-FLORTD999
GI03FLMA-RI001-02-PHSENF999
GI03FLMA-RI001-03-DOSTAD999
GI03FLMA-RI001-04-ADCPSL999
GI03FLMA-RI001-06-CTDMOG999
GI03FLMA-RI001-07-CTDMOG999
GI03FLMA-RI001-08-CTDMOG999
GI03FLMA-RI001-09-CTDMOG999
GI03FLMA-RI001-10-CTDMOG999
GI03FLMA-RI001-11-CTDMOG999
GI03FLMA-RI001-12-CTDMOG999
GI03FLMA-RI001-13-CTDMOG999
GI03FLMA-RI001-14-CTDMOG999
GI03FLMA-RI001-15-CTDMOH999
GI03FLMA-RI001-16-CTDMOH999
GI03FLMA-RI001-17-CTDMOH999
GI03FLMB-RI001-01-FLORTD999
GI03FLMB-RI001-02-PHSENF999
GI03FLMB-RI001-03-DOSTAD999
GI03FLMB-RI001-04-ADCPSL999
GI03FLMB-RI001-06-CTDMOG999
GI03FLMB-RI001-07-CTDMOG999
GI03FLMB-RI001-08-CTDMOG999
GI03FLMB-RI001-09-CTDMOG999
GI03FLMB-RI001-10-CTDMOG999
GI03FLMB-RI001-11-CTDMOG999
GI03FLMB-RI001-12-CTDMOG999
GI03FLMB-RI001-13-CTDMOG999
GI03FLMB-RI001-14-CTDMOG999
GI03FLMB-RI001-15-CTDMOH999
GI03FLMB-RI001-16-CTDMOH999
GI03FLMB-RI001-17-CTDMOH999
GI05MOAS-GL001-01-FLORDM999
GI05MOAS-GL001-02-DOSTAM999
GI05MOAS-GL001-04-CTDGVM999
GI05MOAS-GL002-01-FLORDM999
GI05MOAS-GL002-02-DOSTAM999
GI05MOAS-GL002-04-CTDGVM999
GI05MOAS-GL003-01-FLORDM999
GI05MOAS-GL003-02-DOSTAM999
GI05MOAS-GL003-04-CTDGVM999
GP02HYPM-MP003-01-ZPLSGA999
GP02HYPM-WF002-01-FLORDL999
GP02HYPM-WF002-03-DOSTAL999
GP02HYPM-WF002-04-CTDPFL999
GP02HYPM-WF002-05-VEL3DL999
GP02HYPM-WF004-01-FLORDL999
GP02HYPM-WF004-03-DOSTAL999
GP02HYPM-WF004-04-CTDPFL999
GP02HYPM-WF004-05-VEL3DL999
GP03FLMA-RI001-01-FLORTD999
GP03FLMA-RI001-02-PHSENF999
GP03FLMA-RI001-03-DOSTAD999
GP03FLMA-RI001-04-ADCPSL999
GP03FLMA-RI001-06-CTDMOG999
GP03FLMA-RI001-07-CTDMOG999
GP03FLMA-RI001-08-CTDMOG999
GP03FLMA-RI001-09-CTDMOG999
GP03FLMA-RI001-10-CTDMOG999
GP03FLMA-RI001-11-CTDMOG999
GP03FLMA-RI001-12-CTDMOG999
GP03FLMA-RI001-13-CTDMOG999
GP03FLMA-RI001-14-CTDMOG999
GP03FLMA-RI001-15-CTDMOH999
GP03FLMA-RI001-16-CTDMOH999
GP03FLMA-RI001-17-CTDMOH999
GP03FLMB-RI001-01-FLORTD999
GP03FLMB-RI001-02-PHSENF999
GP03FLMB-RI001-03-DOSTAD999
GP03FLMB-RI001-04-ADCPSL999
GP03FLMB-RI001-06-CTDMOG999
GP03FLMB-RI001-07-CTDMOG999
GP03FLMB-RI001-08-CTDMOG999
GP03FLMB-RI001-09-CTDMOG999
GP03FLMB-RI001-10-CTDMOG999
GP03FLMB-RI001-11-CTDMOG999
GP03FLMB-RI001-12-CTDMOG999
GP03FLMB-RI001-13-CTDMOG999
GP03FLMB-RI001-14-CTDMOG999
GP03FLMB-RI001-15-CTDMOH999
GP03FLMB-RI001-16-CTDMOH999
GP03FLMB-RI001-17-CTDMOH999
GP05MOAS-GL001-01-FLORDM999
GP05MOAS-GL001-02-DOSTAM999
GP05MOAS-GL001-04-CTDGVM999
GP05MOAS-GL002-01-FLORDM999
GP05MOAS-GL002-02-DOSTAM999
GP05MOAS-GL002-04-CTDGVM999
GP05MOAS-GL003-01-FLORDM999
GP05MOAS-GL003-02-DOSTAM999
GP05MOAS-GL003-04-CTDGVM999
GS01SUMO-RI002-02-CTDBPF999
GS01SUMO-RI002-03-ADCPSN999
GS01SUMO-RI002-04-FLORTD999
GS01SUMO-RI002-05-VELPTA999
GS01SUMO-RI003-01-PHSENE999
GS01SUMO-RI003-02-PHSENE999
GS01SUMO-RI003-03-CTDMOQ999
GS01SUMO-RI003-05-CTDMOQ999
GS01SUMO-RI003-06-CTDMOQ999
GS01SUMO-RI003-08-CTDMOQ999
GS01SUMO-RI003-09-CTDMOQ999
GS01SUMO-RI003-10-CTDMOQ999
GS01SUMO-RI003-11-CTDMOQ999
GS01SUMO-RI003-12-CTDMOR999
GS01SUMO-RI003-13-CTDMOR999
GS01SUMO-RI003-14-CTDMOR999
GS01SUMO-RII11-02-ADCPAN011
GS01SUMO-RII11-02-CTDMOQ001
GS01SUMO-RII11-02-CTDMOQ010
GS01SUMO-RII11-02-CTDMOQ012
GS01SUMO-RII11-02-CTDMOQ030
GS01SUMO-RII11-02-CTDMOQ040
GS01SUMO-RII11-02-CTDMOQ050
GS01SUMO-RII11-02-CTDMOQ070
GS01SUMO-RII11-02-CTDMOQ080
GS01SUMO-RII11-02-CTDMOQ090
GS01SUMO-RII11-02-CTDMOR013
GS01SUMO-RII11-02-CTDMOR014
GS01SUMO-RII11-02-CTDMOR015
GS01SUMO-RII11-02-PHSENE020
GS01SUMO-RII11-02-PHSENE060
GS01SUMO-SB001-01-METBKA999
GS01SUMO-SB001-02-METBKA999
GS01SUMO-SB001-03-PCO2AA999
GS01SUMO-SB001-04-FDCHPA999
GS01SUMO-SB001-05-WAVSSA999
GS02HYPM-MP003-01-ZPLSGA999
GS02HYPM-WF002-01-FLORDL999
GS02HYPM-WF002-03-DOSTAL999
GS02HYPM-WF002-04-CTDPFL999
GS02HYPM-WF002-05-VEL3DL999
GS02HYPM-WF004-01-FLORDL999
GS02HYPM-WF004-03-DOSTAL999
GS02HYPM-WF004-04-CTDPFL999
GS02HYPM-WF004-05-VEL3DL999
GS03FLMA-RI001-01-FLORTD999
GS03FLMA-RI001-02-PHSENF999
GS03FLMA-RI001-03-DOSTAD999
GS03FLMA-RI001-04-ADCPSL999
GS03FLMA-RI001-06-CTDMOG999
GS03FLMA-RI001-07-CTDMOG999
GS03FLMA-RI001-08-CTDMOG999
GS03FLMA-RI001-09-CTDMOG999
GS03FLMA-RI001-10-CTDMOG999
GS03FLMA-RI001-11-CTDMOG999
GS03FLMA-RI001-12-CTDMOG999
GS03FLMA-RI001-13-CTDMOG999
GS03FLMA-RI001-14-CTDMOG999
GS03FLMA-RI001-15-CTDMOH999
GS03FLMA-RI001-16-CTDMOH999
GS03FLMA-RI001-17-CTDMOH999
GS03FLMB-RI001-01-FLORTD999
GS03FLMB-RI001-02-PHSENF999
GS03FLMB-RI001-03-DOSTAD999
GS03FLMB-RI001-04-ADCPSL999
GS03FLMB-RI001-06-CTDMOG999
GS03FLMB-RI001-07-CTDMOG999
GS03FLMB-RI001-08-CTDMOG999
GS03FLMB-RI001-09-CTDMOG999
GS03FLMB-RI001-10-CTDMOG999
GS03FLMB-RI001-11-CTDMOG999
GS03FLMB-RI001-12-CTDMOG999
GS03FLMB-RI001-13-CTDMOG999
GS03FLMB-RI001-14-CTDMOG999
GS03FLMB-RI001-15-CTDMOH999
GS03FLMB-RI001-16-CTDMOH999
GS03FLMB-RI001-17-CTDMOH999
GS05MOAS-GL001-01-FLORDM999
GS05MOAS-GL001-02-DOSTAM999
GS05MOAS-GL001-04-CTDGVM999
GS05MOAS-GL002-01-FLORDM999
GS05MOAS-GL002-02-DOSTAM999
GS05MOAS-GL002-04-CTDGVM999
GS05MOAS-GL003-01-FLORDM999
GS05MOAS-GL003-02-DOSTAM999
GS05MOAS-GL003-04-CTDGVM999
RS01SBVM-DP01A-01-CTDPFL104
RS01SBVM-DP01A-02-VEL3DA103
RS01SBVM-DP01A-04-FLORTA102
RS01SBVM-DP01A-05-OPTAAC102
RS01SBVM-DP01A-06-DOSTAD104
RS01SBVM-LJ01A-05-HPIESA101
RS01SBVM-LJ01A-06-CTDPFB101
RS01SBVM-LJ01A-06-DOSTAD101
RS01SBVM-LJ01A-07-OPTAAC103
RS01SBVM-LJ01A-09-HYDBBA102
RS01SBVM-LJ01A-10-ADCPTE101
RS01SBVM-PC01A-05-ADCPTD102
RS01SBVM-PC01A-06-VADCPA101
RS01SBVM-PC01A-07-CAMDSC102
RS01SBVM-PC01A-08-HYDBBA103
RS01SBVM-PC01A-4A-CTDPFA103
RS01SBVM-PC01A-4A-DOSTAD103
RS01SBVM-PC01A-4B-PHSENA102
RS01SBVM-PC01A-4C-FLORDD103
RS01SBVM-SF01A-2A-CTDPFA102
RS01SBVM-SF01A-2A-DOFSTA102
RS01SBVM-SF01A-2D-PHSENA101
RS01SBVM-SF01A-3A-FLORTD101
RS01SBVM-SF01A-3B-OPTAAD101
RS01SBVM-SF01A-3C-PARADA101
RS01SBVM-SF01A-3D-SPKIRA101
RS01SBVM-SF01A-4A-NUTNRA101
RS01SBVM-SF01A-4B-VELPTD102
RS01SBVM-SF01A-4F-PCO2WA101
RS01SLBS-MJ01A-05-HYDLFA101
RS01SLBS-MJ01A-05-OBSBKA101
RS01SLBS-MJ01A-06-PRESTA101
RS01SLBS-MJ01A-12-VEL3DB101
RS01SUM1-LJ01B-05-HYDLFA104
RS01SUM1-LJ01B-05-OBSBBA101
RS01SUM1-LJ01B-06-OBSSPA103
RS01SUM1-LJ01B-07-OBSSPA102
RS01SUM1-LJ01B-08-OBSSPA101
RS01SUM1-LJ01B-09-PRESTB102
RS01SUM1-LJ01B-12-VEL3DB104
RS01SUM2-MJ01B-00-FLOBNA101
RS01SUM2-MJ01B-00-OSMOIA101
RS01SUM2-MJ01B-05-CAMDSB103
RS01SUM2-MJ01B-06-MASSPA101
RS01SUM2-MJ01B-12-ADCPSK101
RS03ASHS-ID03A-06-CAMHDA301
RS03ASHS-MJ03B-00-OSMOIA301
RS03ASHS-MJ03B-05-OBSSPA302
RS03ASHS-MJ03B-06-OBSSPA301
RS03ASHS-MJ03B-07-TMPSFA301
RS03AXBS-MJ03A-05-HYDLFA301
RS03AXBS-MJ03A-05-OBSBKA301
RS03AXBS-MJ03A-06-PRESTA301
RS03AXBS-MJ03A-12-VEL3DB301
RS03AXVM-DP03A-01-CTDPFL304
RS03AXVM-DP03A-02-VEL3DA303
RS03AXVM-DP03A-04-FLORTA302
RS03AXVM-DP03A-05-OPTAAC302
RS03AXVM-DP03A-06-DOSTAD304
RS03AXVM-LJ03A-05-HPIESA301
RS03AXVM-LJ03A-06-CTDPFB301
RS03AXVM-LJ03A-06-DOSTAD301
RS03AXVM-LJ03A-07-OPTAAC303
RS03AXVM-LJ03A-09-HYDBBA302
RS03AXVM-LJ03A-10-ADCPTE301
RS03AXVM-PC03A-05-ADCPTD302
RS03AXVM-PC03A-06-VADCPA301
RS03AXVM-PC03A-07-CAMDSC302
RS03AXVM-PC03A-08-HYDBBA303
RS03AXVM-PC03A-4A-CTDPFA303
RS03AXVM-PC03A-4A-DOSTAD303
RS03AXVM-PC03A-4B-PHSENA302
RS03AXVM-PC03A-4C-FLORDD303
RS03AXVM-SF03A-2A-CTDPFA302
RS03AXVM-SF03A-2A-DOFSTA302
RS03AXVM-SF03A-2D-PHSENA301
RS03AXVM-SF03A-3A-FLORTD301
RS03AXVM-SF03A-3B-OPTAAD301
RS03AXVM-SF03A-3C-PARADA301
RS03AXVM-SF03A-3D-SPKIRA301
RS03AXVM-SF03A-4A-NUTNRA301
RS03AXVM-SF03A-4B-VELPTD302
RS03AXVM-SF03A-4F-PCO2WA301
RS03CCAL-MJ03F-05-BOTPTA301
RS03CCAL-MJ03F-06-HYDLFA305
RS03CCAL-MJ03F-06-OBSBBA301
RS03ECAL-MJ03E-05-OBSSPA303
RS03ECAL-MJ03E-06-BOTPTA302
RS03ECAL-MJ03E-08-OBSSPA304
RS03ECAL-MJ03E-09-HYDLFA304
RS03ECAL-MJ03E-09-OBSBBA302
RS03INT1-MJ03C-05-CAMDSB303
RS03INT1-MJ03C-06-MASSPA301
RS03INT1-MJ03C-07-PPSDNA301
RS03INT1-MJ03C-07-RASFLA301
RS03INT1-MJ03C-09-THSPHA301
RS03INT1-MJ03C-10-TRHPHA301
RS03INT2-MJ03D-05-OBSSPA305
RS03INT2-MJ03D-06-BOTPTA303
RS03INT2-MJ03D-12-VEL3DB304

getlist of available stations


In [17]:
avail_plats = []
try:
    req = requests.get("http://ray-srv.ooi.rutgers.edu:12570/sensor/user/inv/null")
    soup = BeautifulSoup(req.content)
    aa = soup.find_all('a')
    for a in aa:
        if not a.text == "All Sensors":
            avail_plats.append(str(a.text))
except:
    pass
            
            
if len(avail_plats) < 1:
    avail_plats = ['CP05MOAS-GL001-00-ENG000000', 'CP05MOAS-GL002-00-CTDGV0000', 'CP05MOAS-GL002-00-DOSTA0000', 'CP05MOAS-GL002-00-ENG000000', 'CP05MOAS-GL001-00-DOSTA0000', 'CP05MOAS-GL001-00-PARAD0000', 'CP05MOAS-GL002-00-PARAD0000', 'CP05MOAS-GL001-00-FLORT0000', 'CP05MOAS-GL001-00-CTDGV0000']
print avail_plats


['CP05MOAS-GL001-00-ENG000000', 'CP05MOAS-GL002-00-CTDGV0000', 'CP05MOAS-GL002-00-DOSTA0000', 'CP05MOAS-GL002-00-ENG000000', 'CP05MOAS-GL001-00-DOSTA0000', 'CP05MOAS-GL001-00-PARAD0000', 'CP05MOAS-GL002-00-PARAD0000', 'CP05MOAS-GL001-00-FLORT0000', 'CP05MOAS-GL001-00-CTDGV0000']

write to json file


In [18]:
c.execute("SELECT * FROM ooi_instruments")
rows = c.fetchall()
data_dict = {}
print "rows",len(rows)
st_count = 0
for row in rows:
    ref = row[0]
    array = row[1]
    site_id = row[2] #site prefix
    site = row[3]    #site suffix

    node = row[4]    #note type
    port = row[4]        
    lat = row[-2]    
    lon = row[-1]
    node_seq = row[-1] #node seq?
    if array not in data_dict:
       data_dict[array] = {}

    if site not in data_dict[array]:
        if ref in avail_plats:
            status = "on"
        else:
            status = "na"
        data_dict[array][site] = {"status":status,"instruments":[],"lat":lat,"lon":lon,"site_id":site_id}
        st_count +=1 

    if ref not in data_dict[array][site]["instruments"]:
        data_dict[array][site]["instruments"].append(ref)
        
with open("stations.json", "w") as outfile:
    json.dump(data_dict, outfile, indent=4)
    
print "platforms",st_count


rows 738
platforms 51

In [19]:
conn.close()

In [19]:


In [19]: