-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusgs_crc.py
50 lines (44 loc) · 1.31 KB
/
usgs_crc.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
import urllib2
import urllib
import time
import datetime
import csv
data = {}
data['format'] = 'csv'
data['extension'] = 'csv'
data['analysis'] = 'yes'
data['search'] = 'Search'
data['offset'] = '0'
data['formation'] = 'NIOBRARA'
url_values = urllib.urlencode(data)
base = 'http://my.usgs.gov/crcwc/search/cores'
full_url = base + '?' + url_values
print full_url
response = urllib2.urlopen(full_url)
timestr = time.strftime("%Y%m%d")
csv_name = timestr + '_usgscrc.csv'
yest = str(int(timestr) - 1)
csv_yest = yest + '_usgscrc.csv'
data_file = open(csv_name, 'w')
print>>data_file, response.read()
with open(csv_yest, 'rb') as csvfile:
core_list_yest = []
core_strings_yest = []
row_string_yest = ''
corereader = csv.reader(csvfile, delimiter=' ', quotechar ='|')
for row in corereader:
core_list_yest.append(row)
for item in core_list_yest:
row_string_yest = ''.join(item)
core_strings_yest.append(row_string_yest)
with open(csv_name, 'rb') as csvfile:
core_list = []
core_strings = []
row_string = ''
corereader = csv.reader(csvfile, delimiter=' ', quotechar ='|')
for row in corereader:
core_list.append(row)
for item in core_list:
row_string = ''.join(item)
core_strings.append(row_string)
print set(core_strings).difference(core_strings_yest)