Beispiel #1
0
def test():
	config = configure('../ual.config')
	S = ual_session(config['ual_user'],config['ual_pwd'],useragent=config['spoofUA'],logging=True)
	P = alert_params('2/22/16','OGG','SFO',nonstop=True)
	results = S.search(P,logging=True)
	#return(S)
	#data = extract_data(results)
	X = S.basic_search(P)
	return S,list(chain.from_iterable(X))
Beispiel #2
0
def ual(logging=False):
	"""quickly load a session for debugging purposes"""
	config = configure('../ual.config')
	S = ual_session(config['ual_user'],config['ual_pwd'],useragent=config['spoofUA'],logging=logging)
	return S
Beispiel #3
0
def run_alerts(config, ses=None, filename='alerts/alert_defs.txt', aggregate=False, site_version=None, max_retries=100):
	"""If no output file is specified then send email to address specified in config.
	   If site_version is specified then the script will repeatedly log in until the specified site version is obtained
	   (up to max_retries times).
	"""
	# open Session
	if not ses:
		try:
			for i in range(max_retries):
				ses = ual_session(config['ual_user'],config['ual_pwd'],useragent=config['spoofUA'])
				if not site_version or ses.site_version == site_version:
					break
		except Exception as e:
			subject = e.args[0]
			message = 'User: '******'ual_user']
			send_email(subject,message,config)
			raise
	# read alert defs
	F = open(filename,'r')
	alert_defs = []
	for line in F:
		try:
			data = line.strip().split('\t')
			if len(data) < 3 or data[0][0]=='#': continue
			if aggregate:
				end_date = data.pop(1)
			else:
				end_date = data[0]
			a = alert_params(*data)
			a.nonstop=True
			cur_datetime = parser.parse(data[0])
			while cur_datetime <= parser.parse(end_date):
				b = a.copy()
				b.depart_date = cur_datetime.strftime('%m/%d/%y')
				b.depart_datetime = cur_datetime
				alert_defs.append(b)
				cur_datetime += timedelta(1)
		except:
			stderr.write('Error parsing alert definition: '+line)
			continue
	F.close()

	print datetime.today().strftime('%c')
	results = []
	errors = []
	for a in alert_defs:
		# search for alerts
		try:
			segs = ses.alert_search(a)
		except Exception as e:
			if aggregate:
				errors.append((a,e.args[0]))
			else:
				subject = e.args[0]
				message = 'Query: '+str(a)
				stderr.write(subject+'\n'+message+'\n')
				if config['alert_recipient'] != config['sms_alerts']:
					# don't send error messates via sms
					send_email(subject,message,config)
			continue
		for seg in segs:
			try:
				print(seg.condensed_repr())
			except:
				stderr.write('Error getting string representation of segment.\n')
				continue
			if sum(seg.search_results.values()) > 0:
				results.append(seg)
				if not aggregate:
					subject = config['email_subject'] if config['email_subject'] else 'Results for '+str(a)
					message = 'Query: '+str(a)+'\nResults: '+seg.condensed_repr()
					send_email(subject,message,config)

	if aggregate:
		if results:
			subject = config['email_subject'] if config['email_subject'] else 'SuperFlyer search results found'
			message = '\n'.join([seg.condensed_repr() for seg in sorted(results, key=lambda x: x.depart_datetime)])
			e = send_email(subject,message,config)
		if errors:
			subject_err = 'Errors in SuperFlyer search'
			message_err = '\n'.join([str(a)+': '+str(e) for a,e in errors])
			e1 = send_email(subject_err,message_err,config)

	return(ses)
Beispiel #4
0
def ual(logging=False):
	"""quickly load a session for debugging purposes"""
	config = configure('../ual.config')
	S = ual_session(config['ual_user'],config['ual_pwd'],useragent=config['spoofUA'],logging=logging)
	return S