Skip to content

Instantly share code, notes, and snippets.

@citizenrich
Created February 7, 2017 03:32
Show Gist options
  • Select an option

  • Save citizenrich/47e5d0309c04a342506debe2c55c0f2a to your computer and use it in GitHub Desktop.

Select an option

Save citizenrich/47e5d0309c04a342506debe2c55c0f2a to your computer and use it in GitHub Desktop.
#!/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