Created
February 7, 2017 03:32
-
-
Save citizenrich/47e5d0309c04a342506debe2c55c0f2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import requests | |
| from datetime import datetime, timedelta | |
| import json | |
| base = 'https://share.osf.io/api/v2/search/creativeworks/_search' | |
| keywords = 'neural networks' | |
| # simple query | |
| simp_query = {"query": {"query_string": {"query": keywords}}} | |
| # complex query | |
| nowiso = datetime.utcnow().isoformat() | |
| minusmonth = datetime.utcnow() - timedelta(weeks=4) | |
| minusiso = datetime.isoformat(minusmonth) | |
| fill = [{"range": {"date": { | |
| "gte": minusiso, #"2017-01-04T00:00:00-05:00" | |
| "lte": nowiso }}}] #"2017-02-04T00:00:00-05:00" | |
| comp_query = {"query": {"bool": {"must": {"query_string": {"query": keywords}}, "filter": fill}}} | |
| r = requests.post(url=base, json=comp_query) | |
| print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment