-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathausgsMultiTS.py
77 lines (62 loc) · 2.95 KB
/
ausgsMultiTS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 08 14:13:23 2016
@author: bbwarne
"""
from azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettings
import requests
import datetime
today = datetime.date.today()
lastmonth = today.month-1
rTS = requests.get('http://waterservices.usgs.gov/nwis/iv/?format=json,1.1&indent=on&stateCd=sc&startDT={0}-{2}-{1}&endDT={0}-{3}-{1}¶meterCd=00060,00065'.format(today.year,today.day,lastmonth,today.month))
tsdata = rTS.json()['value']['timeSeries']
import json
with open('usgsDatTS.json', 'w') as outfile:
json.dump(tsdata, outfile, sort_keys=True, indent=2, separators=(',',': '))
block_blob_service = BlockBlobService(account_name='usgsstorage', account_key='KASxRSxKQscbwVvd/zFtln+9wspqq/gae4+8V57xPLodmZvg9Wx29rAOa8a2a/TBgNy2/69MiWoaGpzaCH+MWQ==')
block_blob_service.create_blob_from_path(
'usgspulled',
'blockblobJSONts',
'usgsDatTS.json',
content_settings=ContentSettings(content_type='text/json')
)
testTS = tsdata
tsFlowValList = []
tsHeightValList = []
for i in range(0,len(testTS)):
for j in range(0,len(testTS[i]['values'][0]['value'])):
if(testTS[i]['variable']['unit']['unitCode']== u'ft'):
tsHeightValList.append({u'sitename': testTS[i]['sourceInfo']['siteName'],
u'value': float(testTS[i]['values'][0]['value'][j]['value']),
u'units': testTS[i]['variable']['unit']['unitCode'],
u'description': testTS[i]['variable']['variableDescription'],
u'dateTime':testTS[i]['values'][0]['value'][j]['dateTime']
})
if(testTS[i]['variable']['unit']['unitCode']== u'ft3/s'):
tsFlowValList.append({u'sitename': testTS[i]['sourceInfo']['siteName'],
u'value': float(testTS[i]['values'][0]['value'][j]['value']),
u'units': testTS[i]['variable']['unit']['unitCode'],
u'description': testTS[i]['variable']['variableDescription'],
u'dateTime':testTS[i]['values'][0]['value'][j]['dateTime']
})
import csv
fieldNamTS = [u'sitename',u'value',u'units',u'description',u'dateTime']
with open('usgsTSFvalues.csv', 'w') as tsFfile:
wr = csv.DictWriter(tsFfile,fieldnames=fieldNamTS)
wr.writerows(tsFlowValList)
with open('usgsTSHvalues.csv', 'w') as tsHfile:
wr = csv.DictWriter(tsHfile,fieldnames=fieldNamTS)
wr.writerows(tsHeightValList)
block_blob_service.create_blob_from_path(
'usgspulled',
'tsfblobCSV',
'usgsTSFvalues.csv',
content_settings=ContentSettings(content_type='text/csv')
)
block_blob_service.create_blob_from_path(
'usgspulled',
'tsHblobCSV',
'usgsTSHvalues.csv',
content_settings=ContentSettings(content_type='text/csv')
)