Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrew Buddenberg
gcis-py-client
Commits
86a6230a
Commit
86a6230a
authored
Sep 16, 2013
by
Andrew Buddenberg
Browse files
Update working. Need to refactor hacks out of functions
parent
41eba32a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/.gcis-client.py.swp
View file @
86a6230a
No preview for this file type
src/gcis-client.py
View file @
86a6230a
...
@@ -3,20 +3,72 @@
...
@@ -3,20 +3,72 @@
import
urllib
import
urllib
import
urllib2
import
urllib2
import
json
import
json
from
webform_client
import
get_webforms
url
=
'http://data.gcis-test-front.joss.ucar.edu/report/nca3draft
/figure
'
base_
url
=
'http://data.gcis-test-front.joss.ucar.edu/report/nca3draft'
#user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
#user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values
=
{}
values
=
{}
headers
=
{
'Accept'
:
'application/json'
}
headers
=
{
'Accept'
:
'application/json'
}
params
=
urllib
.
urlencode
({
'all'
:
'1'
})
params
=
urllib
.
urlencode
({
'all'
:
'1'
})
url
+
=
'?'
+
params
url
=
base_url
+
'?'
+
params
data
=
urllib
.
urlencode
(
values
)
data
=
urllib
.
urlencode
(
values
)
req
=
urllib2
.
Request
(
url
,
None
,
headers
)
req
=
urllib2
.
Request
(
url
,
None
,
headers
)
response
=
urllib2
.
urlopen
(
req
)
response
=
urllib2
.
urlopen
(
req
)
figure_listing
=
json
.
load
(
response
)
figure_listing
=
json
.
load
(
response
)
for
entry
in
figure_listing
:
def
main
():
print
entry
[
'identifier'
]
drupal_id
,
create_dt
=
get_webforms
(
'1320'
)
my_thing
,
post_url
=
get_figure
(
drupal_id
)
my_thing
[
'create_dt'
]
=
create_dt
headers
=
{
'Accept'
:
'application/json'
,
'Authorization'
:
'Basic YW5kcmV3LmJ1ZGRlbmJlcmdAbm9hYS5nb3Y6MjFjMjM2Y2YxYmZmMmRjMmMyOTNlZjljMWVjNTY1NWFhZWIyYjQ0ZDUyMzc3OGE1'
}
req
=
urllib2
.
Request
(
post_url
,
json
.
dumps
(
my_thing
),
headers
)
response
=
urllib2
.
urlopen
(
req
)
print
response
.
read
()
# for key in get_full_listing():
# print key
def
do_update
():
print
''
update_url
=
'{base_url}/form/update'
.
format
(
base_url
=
base_url
)
def
get_figure
(
identifier
):
query
=
'{url}{id}.json'
.
format
(
url
=
base_url
,
id
=
identifier
)
resp
=
json
.
load
(
urllib2
.
urlopen
(
query
))
del
(
resp
[
'images'
])
del
(
resp
[
'chapter'
])
del
(
resp
[
'parents'
])
return
resp
,
query
#Full listing
def
get_full_listing
():
full_listing
=
{}
for
entry
in
figure_listing
:
full_listing
[
entry
[
'identifier'
]]
=
entry
return
full_listing
#Numerical identifiers
def
print_chapter_figure_list
():
for
entry
in
figure_listing
:
chapter_num
=
''
if
'chapter'
in
entry
and
'number'
in
entry
[
'chapter'
]
and
entry
[
'ordinal'
]:
chapter_num
=
entry
[
'chapter'
][
'number'
]
ordinal
=
entry
[
'ordinal'
]
print
'{0}.{1} '
.
format
(
chapter_num
,
ordinal
),
entry
[
'identifier'
]
main
()
src/webform_client.py
0 → 100755
View file @
86a6230a
#!/usr/bin/python
import
urllib
import
urllib2
import
json
def
get_webforms
(
nid
):
url
=
'http://dev.nemac.org/asides10/metadata/figures/all?token=A2PNYxRuG9'
figure_listing
=
json
.
load
(
urllib2
.
urlopen
(
url
))
results
=
[]
#for figure_id in figure_listing:
# if 'what_is_the_figure_id' not in figure_listing[figure_id]['figure'][0]:
# continue
# else:
# print figure_id, figure_listing[figure_id]['figure'][0]['what_is_the_figure_id']
return
figure_listing
[
nid
][
'figure'
][
0
][
'what_is_the_figure_id'
],
figure_listing
[
nid
][
'figure'
][
0
][
'when_was_this_figure_created'
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment