Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91882795
get-json-data.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 15, 10:56
Size
1 KB
Mime Type
text/x-python
Expires
Sun, Nov 17, 10:56 (2 d)
Engine
blob
Format
Raw Data
Handle
22340923
Attached To
R2664 SHRINE MedCo Fork
get-json-data.py
View Options
#!/usr/bin/env python
import
json
import
sys
import
subprocess
def
json_print
(
json_thing
):
print
json
.
dumps
(
json_thing
)
def
curl
(
url_after_steward
,
user
,
password
):
input
=
subprocess
.
check_output
([
"curl"
,
"https://shrine-dev1.catalyst:6443/steward/"
+
url_after_steward
,
"-k"
,
"--user"
,
"
%s
:
%s
"
%
(
user
,
password
)
])
return
json
.
loads
(
input
.
decode
(
"utf-8"
))
def
topic_ids
(
user
,
password
):
json_input
=
curl
(
"researcher/topics/"
,
user
,
password
)
topics
=
json_input
[
"topics"
]
result
=
[]
for
topic
in
topics
:
result
.
append
(
topic
[
"id"
])
result
.
sort
()
return
result
def
query_history_for_topic
(
user
,
password
,
topic
):
return
curl
(
"researcher/queryHistory/topic/
%s
"
%
topic
,
user
,
password
)
def
query_history_for_all_topics
(
user
,
password
):
return
curl
(
"researcher/queryHistory"
,
user
,
password
)
def
write_topic_history_to_file
(
user
,
password
,
topic
):
result
=
query_history_for_topic
(
user
,
password
,
topic
)
if
result
[
"totalCount"
]
>
0
:
json_file
=
open
(
'
%s
_topic_
%d
.json'
%
(
user
,
topic
),
'w'
)
json_file
.
write
(
json
.
dumps
(
result
))
json_file
.
close
()
def
write_histories_to_file
(
user
,
password
):
topics
=
topic_ids
(
user
,
password
)
for
topic
in
topics
:
write_topic_history_to_file
(
user
,
password
,
topic
)
json_file
=
open
(
'
%s
_all_topics.json'
%
user
,
'w'
)
json_file
.
write
(
json
.
dumps
(
query_history_for_all_topics
(
user
,
password
)))
json_file
.
close
()
user
=
sys
.
argv
[
1
]
password
=
sys
.
argv
[
2
]
if
'-topics'
in
sys
.
argv
:
json_print
(
topic_ids
(
user
,
password
))
if
'-t'
in
sys
.
argv
:
topic
=
sys
.
argv
[
1
+
sys
.
argv
.
index
(
'-t'
)]
json_print
(
query_history_for_topic
(
user
,
password
,
topic
))
if
'-h'
in
sys
.
argv
:
json_print
(
query_history_for_all_topics
(
user
,
password
))
if
'-f'
in
sys
.
argv
:
write_histories_to_file
(
user
,
password
)
Event Timeline
Log In to Comment