Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Last active March 15, 2019 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesBuchner/f57911b815c2a5a8c18cbb4f9a451c54 to your computer and use it in GitHub Desktop.
Save JohannesBuchner/f57911b815c2a5a8c18cbb4f9a451c54 to your computer and use it in GitHub Desktop.
Download Swift spectra
"""
Download custom spectrum from http://www.swift.ac.uk/, programmatically
How to use:
$ python fetchswiftspectrum.py grbid timeslicespec
$ wget -nc --continue $(cat customspec.url)/a.tar.gz
"""
import sys, os
import time
import requests
timeslices = sys.argv[2]
id = sys.argv[1]
mode = os.environ.get('MODE', 'BOTH')
data = dict(
targ=id,
name=id,
pubpriv=1,
public=1,
z=0,
sno=0,
name1='a',
time1=timeslices,
mode1=mode,
name2='',
time2='',
mode2=mode,
name3='',
time3='',
mode3=mode,
name4='',
time4='',
mode4=mode,
grade0='0',
)
print 'requesting build...'
print ' with data:', data
r = requests.post("http://www.swift.ac.uk/xrt_spectra/build_slice_spec.php",
data=data)
print 'response:', r.status_code
url = r.url
open('customspec.url', 'w').write(r.url)
r2 = r
while 'This page will be reloaded in 30 seconds' in r2.content:
print 'sleeping 30 seconds ...'
time.sleep(30)
print 'requesting %s ...' % url
r2 = requests.get(url)
print 'done. Fetch from %s' % url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment