Exemplo n.º 1
0
def race_search():
	"""Gets information from the goal form, gets it in a form 
	to make an API call, makes the call, gets the JSON back, de-dups
	it, then sends the info to the front end."""

	goal = request.args.get("goal")
	zipcode = request.args.get("zipcode")

	fitness = int(request.args.get("fitness_level"))
	run_length_history = int(request.args.get("run_length_history"))
	# Base date is the date that the goal is being made. The date
	# range for the race search is based on when the goal is created. 
	base_date = date.today()
	# Date range returns a tuple a minimum number of weeks
	# in the future to look for a date and a maximum number of weeks. 
	date_range = goals.determine_date_range(goal, fitness, run_length_history)
	# min_date is the earliest to look for a race. 
	min_date = base_date + timedelta(date_range[0]*7)
	# max date is the latest to look for a race. 
	max_date = base_date + timedelta(date_range[1]*7)

	# Setting up and executing the API call.
	# I decided to go with quality data over quantity.
	# URL will only return results that have a url associated with the organizer.
	activity_request_url = "http://api.amp.active.com/v2/search?attributes=" + model.distance_dictionary[goal] + "&category=event&start_date=" + str(min_date) +".."+str(max_date)+"&near="+str(zipcode)+ "&exists=homePageUrlAdr&api_key="+ACTIVEDOTCOM_KEY
	activity_request = requests.get(activity_request_url)

	content = activity_request.content
	content_dictionary = json.loads(content)

	results = content_dictionary[u'results']
	unique_content = []

	for i in range(len(results)-1):
		do_not_append_content = False
		for j in range(i + 1, len(results)):
			if results[i]['homePageUrlAdr'] == results[j]['homePageUrlAdr']:
				do_not_append_content = True
			else:
				pass

		if do_not_append_content == True:
			pass
		else:
			unique_content.append(results[i])
 	
 	json_content = json.dumps(unique_content)	
	return json_content
Exemplo n.º 2
0
def no_race_search():
	goal = request.args.get("goal")
	fitness = int(request.args.get("fitness_level"))
	run_length_history = int(request.args.get("run_length_history"))
	base_date = date.today()
	date_range = goals.determine_date_range(goal, fitness, run_length_history)
	# min_date is a minimum good date to set.  
	min_date = base_date + timedelta(date_range[0]*7)
	# max date is the later good date to set, so the user doesn't take it too easy.  
	max_date = base_date + timedelta(date_range[1]*7)

	min_date = datetime.strftime(min_date, "%m-%d-%Y")
	max_date = datetime.strftime(max_date, "%m-%d-%Y")

	dates = [min_date, max_date]

	json_output = json.dumps(dates)

	return json_output