Esempio n. 1
0
#import cookielib
from cookiejar import CookieJar
#
if (len(sys.argv) != 2):
  print("usage: "+sys.argv[0]+" [-q] password_on_RDA_webserver")
  print("-q suppresses the progress message for each file that is downloaded")
  sys.exit(1)
#
passwd_idx=1
verbose=True
if (len(sys.argv) == 3 and sys.argv[1] == "-q"):
  passwd_idx=2
  verbose=False
#
#cj=cookielib.MozillaCookieJar()
cj=CookieJar.MozillaCookieJar()
#opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))

#
# check for existing cookies file and authenticate if necessary
do_authentication=False
if (os.path.isfile("auth.rda.ucar.edu")):
  cj.load("auth.rda.ucar.edu",False,True)
  for cookie in cj:
    if (cookie.name == "sess" and cookie.is_expired()):
      do_authentication=True
else:
  do_authentication=True
if (do_authentication):
  #login=opener.open("https://rda.ucar.edu/cgi-bin/login","[email protected]&password="******"&action=login")