Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.