Skip to content

Commit

Permalink
Adding restapi.
Browse files Browse the repository at this point in the history
  • Loading branch information
knc6 committed Mar 31, 2024
1 parent 7eb8df9 commit a067e33
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion jarvis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ def test(*args):

path = os.path.join(os.path.split(__file__)[0], "tests")
pytest.main(args=[path] + list(args))

20 changes: 20 additions & 0 deletions jarvis/db/restapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module to access or upload data in JARVIS-API."""

import requests
import pprint
import os
Expand All @@ -9,6 +10,25 @@
import json


def jarvisdft_optimade(
prefix="https://jarvis.nist.gov/optimade/jarvisdft/v1/structures/?filter=",
query="elements HAS ALL C,Si",
):
url = prefix + query
vals = []
while True:
if url is not None:
# print('url', url)
response = requests.get(url)
data = response.json()["data"]
for i in data:
vals.append(i)
url = response.json()["links"]["next"]
else:
break
return vals


class Api(object):
"""Class for handling functions for JARVIS-API."""

Expand Down
8 changes: 8 additions & 0 deletions jarvis/tests/testfiles/db/test_restapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from jarvis.db.restapi import jarvisdft_optimade


def test_optimade():
x = jarvisdft_optimade()
print(x)
print(len(x))
assert len(x) > 1

0 comments on commit a067e33

Please sign in to comment.