#!/usr/bin/env jython from java.lang import System import time, os, sys, re, tempfile from java.net import Authenticator, URL from java.io import BufferedReader, InputStreamReader, InputStream from java.text import SimpleDateFormat from java.util import Date, GregorianCalendar, Calendar import calendar class CallBack: def __init__(self): self.clear() def add_body(self,buf): self.contents = self.contents + buf def check(self,datestr): r=re.compile(r"%s/\"' title=" % datestr) for line in self.contents.split("\n"): if r.search(line): return True return False def clear(self): self.contents = '' def _str_(self): return self.contents TTS_URL="https://somewhere.redhat.com/vogon/tts/action/daily" TIME_IN="9:00" TIME_OUT="17:30" TIME_BREAK="0:30" postString = "time_in=%s&time_out=%s&time_break=%s&btn_save=Save" % \ (TIME_IN,TIME_OUT,TIME_BREAK) # month to fill if len(sys.argv) != 2: sys.exit(1) TTS_MONTH=calendar.SaneCalendar() TTS_MONTH.strptime(sys.argv[1],"y-M") #TTS_MONTH=time.strptime(raw_input("Month to fill YYYY-MM: "),"%Y-%m") # There is no mkstemp in jython 2.2.1 login_conf = tempfile.mktemp() f = file(login_conf,"w") f.write('''com.sun.security.jgss.krb5.initiate { com.sun.security.auth.module.Krb5LoginModule required doNotPrompt=false useTicketCache=true; };''') f.close() System.setProperty('java.security.krb5.realm', 'REDHAT.COM') System.setProperty('java.security.krb5.kdc', 'kerberos.stuttgart.redhat.com') System.setProperty('java.security.auth.login.config', login_conf) System.setProperty('javax.security.auth.useSubjectCredsOnly', 'false') System.setProperty('http.auth.preference', 'SPNEGO') System.setProperty('sun.security.spnego.debug', 'true') cb = CallBack() # number of days in given month LAST_DAY=TTS_MONTH.end_of_month() print >>sys.stderr,str(LAST_DAY) WDAY = calendar.SaneCalendar() for day in range(1,LAST_DAY.get(Calendar.DAY_OF_MONTH)): # skip non-working days WDAY.setDate(LAST_DAY.get(Calendar.YEAR),LAST_DAY.getMonth(),day) if not(WDAY.isWorkday()): continue url = URL('%s/%s' % (TTS_URL,str(WDAY))) print >>sys.stderr,url input = url.openConnection().getInputStream() reader = BufferedReader(InputStreamReader(input)) while True: str = reader.readLine() if str is None: break cb.add_body(str) print cb cb.clear() # if not cb.check("%s-%s-%s" % (TTS_MONTH.year,TTS_MONTH.month,day)): # print "Filling %s-%s-%s..." % (TTS_MONTH.year,TTS_MONTH.month,day) # handle.setopt(handle.POSTFIELDS,postString) # handle.perform() # cb.clear() # handle.setopt(handle.HTTPGET,True) os.unlink(login_conf) print "Done."