Example #1
0
	def __init__(self):
		# get profiling and date information for current request
		self.starttime=time.time()
		today = util.gmtnow()
		self.curday=str(today.day)
		self.curmonth=str(today.month)
		self.curyear=str(today.year)
		self.timestamp = str(today) + " GMT"
		form = cgi.FieldStorage()
		# gather os and form values
		self.script = os.environ.get('SCRIPT_NAME', '') 
		# TODO: use browser cookie for lang
		self.lang  = form.getfirst("lang", 'de')[0:2].lower()
		self.day   = form.getfirst("day", self.curday)[0:2]
		self.month = form.getfirst("month", self.curmonth)[0:2]
		self.year  = form.getfirst("year", self.curyear)[0:4]
		self.edit  = form.getfirst("edit", "0")[0:1]
		self.eventid  = form.getfirst("eventid", "0")[0:1]
		self.debug = form.has_key("debug")
		# some security
		# check for numbers and chars
		if not (self.day.isdigit() and self.month.isdigit() \
			      and self.year.isdigit() and self.lang.isalpha() \
						and self.eventid.isdigit()): 
			raise "invalid input"
		self.form = form
Example #2
0
def fnGlob(fn, langs=[], year=util.gmtnow().year):
  """
  transforms parameters to remote url filename scheme w/ parameters
  """
  remote = []

  # replace lang w/ available langs
  i = fn.find('$lang')
  dot = fn.rfind('.')
  if i>=0:
    (bef, sep, aft) = fn.partition('$lang')
    for lang in langs:
      remote.append(''.join([bef, '?lang=', lang, aft]))

  # replace $date with dates in year
  i = fn.find('$date')
  if i>=0:
    cal = Calendar()
    today =  util.gmtnow()
    for i in range(0, len(remote)):
			# extract part of string before $date
      rbef = remote.pop(0).split('$date')[0]
      for month in range(1, 13):
        for day in cal.itermonthdays(year, month):
          if (0 == day): continue # don't know why, but day is 0 sometimes
          # we are not interested in older events
          if (year < today.year): continue
          if (year == today.year and month < today.month): continue
          # if (year == today.year and month == today.month \
					# 		and day < today.day): continue
          remote.append('%s&year=%i&month=%i&day=%i' % \
            (rbef, year, month, day))

  # when no expansion happened at all, simply add the original string
  if 1 > len(remote):
    remote.append(fn)

  return remote
Example #3
0
		while True:
 			with urlsLock:
				if 1 > len(urls):
					break
				url = urls.pop(0)
			saveToStatic(url, '../../live/', templates)
			self.cnt += 1


if __name__ == '__main__':
	templates=readTemplates()
	languages=readLanguages()
	urlsLock=threading.Lock() # global lock used by worker threads
#	urls = Set()
	urls = []
	year =  util.gmtnow().year
	for template in templates:
		urls.extend(fnGlob(template, languages, year))
		urls.extend(fnGlob(template, languages, year+1))
	threads = []
	for i in range(3):
		thread = worker(i)
		thread.start()
		threads.append(thread)
	for thread in threads:
		thread.join()
		# print 'thread # %i joined after %i pages' % (thread.id, thread.cnt)