Skip to content

Instantly share code, notes, and snippets.

@keflavich
Created June 7, 2017 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keflavich/b13988322707d7bdda10d3e897ed6678 to your computer and use it in GitHub Desktop.
Save keflavich/b13988322707d7bdda10d3e897ed6678 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import urllib
import requests
S = requests.Session()
r = S.get('http://archive.noao.edu/search/query')
# not 100% sure this is necessary any mroe...
S.headers['X-CSRF-Token'] = BeautifulSoup(r.text, 'html5lib').find('meta',{'name':'csrf-token'}).attrs['content']
# this is the part we had missed: the NOAO server apparently needs to have all
# this stuff done to it before the cookies become valid
header_content = S.get('http://archive.noao.edu/application/header_content')
query_content = S.get('http://archive.noao.edu/search/query_content')
main_notice = S.get('http://archive.noao.edu/application/get_main_notice')
stage_area = S.get('http://archive.noao.edu/application/render_stage_area')
# Create a real query
data = "reset_datagrid=true&conditions=&object=&ra=148.888&dec=69.065&searchbox=30.0&dtpropid=&dtpi=&dtacqnam=&archive_file=&telescope_instrument=&raw_proctype=false&instcal_proctype=false&resampled_proctype=false&stacked_proctype=false&mastercal_proctype=false&tile_proctype=false&skysub_proctype=false"
dd = dict(urllib.parse.parse_qsl(data))
result1b = S.post('http://archive.noao.edu/search/send_simple_query', data=dd)
result1b.raise_for_status()
assert result1b.text == 'OK'
result2b = S.post('http://archive.noao.edu/search/list_resources')
result2b.raise_for_status()
result3b = S.post('http://archive.noao.edu/search/get_selected_rows_length')
result3b.raise_for_status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment