list2form : gestion des erreurs et des petits fichiers (merci cgi.py…)
[progfou.git] / wcs / sigma-download
CommitLineData
a9de62a1
P
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import urllib2
5
6SIGMA_BASE = 'https://formulaires.auf.org/sigma'
7SIGMA_USER = 'XXX'
8SIGMA_PASS = 'XXX'
9
10passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
11passman.add_password(None, SIGMA_BASE, SIGMA_USER, SIGMA_PASS)
12authhandler = urllib2.HTTPBasicAuthHandler(passman)
13opener = urllib2.build_opener(authhandler)
14urllib2.install_opener(opener)
15
16def retrieve(url, filename):
17 doc = urllib2.urlopen(url)
18 f = file(filename, 'wb')
19 f.write(doc.read())
20 f.close()
21 doc.close()
22
23# on récupère quelques pages…
24
25formname = 'demande-de-bourse-de-doctorat-2010-2011-algerie-maroc-tunisie'
26
27for filename in ['field-names.json', 'last-run.log']:
28 url = '%s/%s/%s' % (SIGMA_BASE, formname, filename)
29 retrieve(url, filename) # sauve le contenu à l'URL donnée dans filename
30