Exemple #1
0
def get_me_weather(request, latitude, longitude):
	message = {"weatherHTML": ""}
	if request.is_ajax():
		forecast = oracle.get_forecast(latitude, longitude)
		weatherHTML = render_to_string('./forecast.html', {'weather':forecast})
		message['weatherHTML'] = weatherHTML
		json = simplejson.dumps(message)
		return HttpResponse(json, mimetype='application/json')
Exemple #2
0
def get_me_weather(request, latitude, longitude):
    message = {"weatherHTML": ""}
    if request.is_ajax():

        forecast = oracle.get_forecast(latitude, longitude)
        weatherHTML = render_to_string('./forecast.html',
                                       {'weather': forecast})
        message['weatherHTML'] = weatherHTML
        json = simplejson.dumps(message)
        return HttpResponse(json, mimetype='application/json')
Exemple #3
0
def forecast():
    print("-- Forecast option selected")
    tweet = twitter.Api(
        consumer_key=configuration_manager.AppSettings["twitter"]
        ["consumer key"],
        consumer_secret=configuration_manager.AppSettings["twitter"]
        ["consumer secret"],
        access_token_key=configuration_manager.AppSettings["twitter"]
        ["access token key"],
        access_token_secret=configuration_manager.AppSettings["twitter"]
        ["access token secret"])

    for t in TICKERS:
        print("Running forecast for " + t["ticker"])
        _forecast = oracle.get_forecast(t["ticker"])
        if _forecast is not None:
            if _forecast.get_max_gain() >= 0.1:
                figure = oracle.Plot.from_timeseries(_forecast)
                # input("Press Enter to continue...")
                tweet.PostUpdate(status=_forecast.get_title(), media=figure)
Exemple #4
0
def index(request):
    debug = []
    debug.append('False')
    city_set = []
    if request.method == 'GET':
        form = WeatherForm(request.GET)
        if form.is_valid():
            sample_zip = request.GET['location']
            max_distance = int(request.GET['distance'])
            debug.append('max_distance: ' + str(max_distance))

            # switch here to use either the city or the zipcode
            debug.append('is_this_an_int: ' + str(is_this_an_int(sample_zip)))
            if len(str(sample_zip)) == 5 and is_this_an_int(sample_zip):
                try:
                    center_location = Zips.objects.get(zipcode=sample_zip)
                except ObjectDoesNotExist:
                    notification = 'No zipcode found :('
                    return render_to_response('./index.html', {
                        'form': form,
                        'notification': notification,
                        'debug': debug
                    })
            else:
                # assume we werent given a zipcode, so parse it as a city
                parsed_zip = re.findall(r'\w+', sample_zip)
                city_name = ' '.join(parsed_zip[0:-1])
                state_name = parsed_zip[-1]
                debug.append(parsed_zip)
                debug.append(city_name)
                debug.append(state_name)
                try:
                    center_location = City.objects.get(
                        name__iexact=city_name, state__iexact=state_name)
                except ObjectDoesNotExist:
                    notification = 'No city found :('
                    return render_to_response('./index.html', {
                        'form': form,
                        'notification': notification,
                        'debug': debug
                    })
                # add 3rd except for multiple cites, return links to all of them!
                # then do the search for the one they select!
            max_lat = center_location.latitude + max_distance / 69.09
            min_lat = center_location.latitude - max_distance / 69.09
            max_long = center_location.longitude + max_distance / 69.09
            min_long = center_location.longitude - max_distance / 69.09

            city_set = list(
                City.objects.filter(
                    longitude__range=(min_long, max_long)).filter(
                        latitude__range=(min_lat, max_lat)))

            # trim down the city list to a circle, and build the distance list
            city_distances = []
            approvedcity_set = []
            debug.append('cities before: ' + str(len(city_set)))
            for city in city_set:
                temp_distance = calculate_distance(center_location, city)
                debug.append(city.name + ': ' + str(temp_distance))
                # debug.append(city.name + '- lat:' + str(city.longitude)  + ' long:' + str(city.latitude))
                if temp_distance < float(max_distance):
                    approvedcity_set.append(city)
                    city_distances.append(int(temp_distance))

            debug.append('cities after: ' + str(len(approvedcity_set)))
            debug.append('city distances: ' + str(len(city_distances)))

            all_the_forecasts = []
            for city in city_set:
                tempForecast = oracle.get_forecast(city.latitude,
                                                   city.longitude)
                #getting the day of the week for dates
                for datapoint in tempForecast:
                    datapoint.day = datapoint.date.strftime('%A')
                #add forecast to forecast list
                all_the_forecasts.append(tempForecast)

            zipped = [{
                'city': t[0],
                'weather': t[1],
                'distance': t[2]
            } for t in zip(approvedcity_set, all_the_forecasts, city_distances)
                      ]
            # zipped = [{'city': t[0], 'distance':t[1], 'weather': t[2]} for t in zip(city_set, city_distances, all_the_forecasts)]
            # debug.append(str(len(city_set)) + ' cities')
            return render_to_response(
                './index.html', {
                    'city_list': city_set,
                    "citylist_length": len(city_set),
                    'forecasts': all_the_forecasts,
                    'form': form,
                    'zipped': zipped,
                    'debug': debug
                })
        else:
            debug.append('form data is invalid')
            form = WeatherForm(request.GET)
            return render_to_response('./index.html', {
                'form': form,
                'debug': debug
            })

    else:
        debug.append('no GET request data')
        form = WeatherForm()
        return render_to_response('./index.html', {
            'form': form,
            'debug': debug
        })
Exemple #5
0
def camp(request):
    city_set = []
    if request.method == 'GET':
        form = WeatherForm(request.GET)
        if form.is_valid():
            sample_zip = request.GET['location']
            max_distance = int(request.GET['distance'])
            # debug.append('max_distance: ' + str(max_distance))

            # switch here to use either the city or the zipcode
            if len(str(sample_zip)) == 5 and is_this_an_int(sample_zip):
                try:
                    center_location = Zips.objects.get(zipcode=sample_zip)
                except ObjectDoesNotExist:
                    notification = 'You sure that\'s a real zipcode?'
                    return render_to_response('./camp.html', {
                        'form': form,
                        'notification': notification
                    })
            else:
                # assume we werent given a zipcode, so parse it as a city
                parsed_zip = re.findall(r'\w+', sample_zip)
                city_name = ' '.join(parsed_zip[0:-1])
                state_name = parsed_zip[-1]

                # BUG: searching for a city when there is another in the same state...possible major rewrite required to handle searching with extra data(no more jQuery hack)
                try:
                    center_location = City.objects.get(
                        name__iexact=city_name, state__iexact=state_name)
                #in case we get nothing
                except ObjectDoesNotExist:
                    try:
                        # concatenates the city and state name, if a city is two words, it mixes things up, this fixes that
                        if len(state_name) > 2 and len(city_name) != 0:
                            state_name = city_name + ' ' + state_name
                        possibleCityList = City.objects.filter(
                            name__iexact=state_name)
                        if len(possibleCityList) != 0:
                            notification = 'I didn\'t catch the state. Here\'s a list of cities to start with: '
                            return render_to_response(
                                './camp.html', {
                                    'form': form,
                                    'notification': notification,
                                    'possibleCityList': possibleCityList
                                })
                        else:
                            notification = 'I can\'t find '
                            notification += state_name
                            return render_to_response(
                                './camp.html', {
                                    'form': form,
                                    'notification': notification
                                })
                    except ObjectDoesNotExist:
                        notification = 'I can\'t seem to find that city'
                        return render_to_response('./camp.html', {
                            'form': form,
                            'notification': notification
                        })
                # in case we have two cities with the same name in the same state
                except MultipleObjectsReturned:
                    # we get cities & populations but, cant specify the search based on the cities GEOid or location
                    possibleCityList = City.objects.filter(
                        state__iexact=state_name).filter(
                            name__iexact=city_name)
                    notification = 'I got multiple cities with that name: clicking these will just mess with things...sorry'
                    sameCities = True
                    return render_to_response(
                        './camp.html', {
                            'form': form,
                            'notification': notification,
                            'sameCities': sameCities,
                            'possibleCityList': possibleCityList
                        })
                # Handling Non UTF data that python hates
                except OperationalError:
                    notification = 'I\'ve encountered non-UTF data. And am notifying my superiors\n Sorry about this'
                    return render_to_response('./camp.html', {
                        'form': form,
                        'notification': notification
                    })

            # gives us a minimum and maximum to search in, it would look like a square centered around center_location
            max_lat = center_location.latitude + max_distance / 69.09
            min_lat = center_location.latitude - max_distance / 69.09
            max_long = center_location.longitude + max_distance / 69.09
            min_long = center_location.longitude - max_distance / 69.09

            camp_set = list(
                Campground.objects.filter(
                    longitude__range=(min_long, max_long)).filter(
                        latitude__range=(min_lat, max_lat)))

            # trim down the city list to a circle, and build the distance list
            camp_distances = []
            approvedcamp_set = []
            for campground in camp_set:
                temp_distance = calculate_distance(center_location, campground)

                if temp_distance < float(max_distance):
                    approvedcamp_set.append(campground)
                    camp_distances.append(int(temp_distance))

            #format the campground type to be human friendly
            for campground in approvedcamp_set:
                campground = camp_humanizer(campground)

            all_the_forecasts = []
            for campground in approvedcamp_set:
                tempForecast = oracle.get_forecast(campground.latitude,
                                                   campground.longitude)
                #getting the day of the week for dates
                for datapoint in tempForecast:
                    datapoint.day = datapoint.date.strftime('%A')
                #add forecast to forecast list
                all_the_forecasts.append(tempForecast)

            zipped = [{
                'campground': t[0],
                'weather': t[1],
                'distance': t[2]
            } for t in zip(approvedcamp_set, all_the_forecasts, camp_distances)
                      ]

            # no campgrounds were returned....
            if len(approvedcamp_set) > 0:
                return render_to_response(
                    './camp.html', {
                        "camplist_length": len(approvedcamp_set),
                        'forecasts': all_the_forecasts,
                        'form': form,
                        'zipped': zipped
                    })
            else:
                notification = 'Search farther...'
                return render_to_response('./camp.html', {
                    'form': form,
                    'farther': notification
                })
        else:
            form = WeatherForm(request.GET)
            return render_to_response('./camp.html', {'form': form})

    else:
        form = WeatherForm()
        return render_to_response('./camp.html', {'form': form})
Exemple #6
0
def index(request):
	debug = []
	debug.append('False')
	city_set = []
	if request.method == 'GET':
		form = WeatherForm(request.GET)
		if form.is_valid():
			sample_zip = request.GET['location']
			max_distance = int(request.GET['distance'])
			debug.append('max_distance: ' + str(max_distance))

			# switch here to use either the city or the zipcode
			debug.append('is_this_an_int: ' + str(is_this_an_int(sample_zip)))
			if len(str(sample_zip)) == 5 and is_this_an_int(sample_zip):
				try:
					center_location = Zips.objects.get(zipcode=sample_zip)
				except ObjectDoesNotExist:
					notification = 'No zipcode found :('
					return render_to_response('./index.html', {'form': form,'notification':notification, 'debug':debug})
			else:
				# assume we werent given a zipcode, so parse it as a city
				parsed_zip = re.findall(r'\w+', sample_zip)
				city_name = ' '.join(parsed_zip[0:-1])
				state_name = parsed_zip[-1]
				debug.append(parsed_zip)
				debug.append(city_name)
				debug.append(state_name)
				try:
					center_location = City.objects.get(name__iexact=city_name, state__iexact=state_name)
				except ObjectDoesNotExist:
					notification = 'No city found :('
					return render_to_response('./index.html', {'form': form,'notification':notification, 'debug':debug})
				# add 3rd except for multiple cites, return links to all of them! 
				# then do the search for the one they select!
			max_lat = center_location.latitude + max_distance/69.09
			min_lat = center_location.latitude - max_distance/69.09
			max_long = center_location.longitude + max_distance/69.09
			min_long = center_location.longitude - max_distance/69.09

			city_set = list(City.objects.filter(longitude__range=(min_long,max_long)).filter(latitude__range=(min_lat,max_lat)))

			# trim down the city list to a circle, and build the distance list
			city_distances = []
			approvedcity_set = []
			debug.append('cities before: ' + str(len(city_set)))
			for city in city_set:
				temp_distance = calculate_distance(center_location, city)
				debug.append(city.name + ': ' + str(temp_distance))
				# debug.append(city.name + '- lat:' + str(city.longitude)  + ' long:' + str(city.latitude))
				if temp_distance < float(max_distance):
					approvedcity_set.append(city)
					city_distances.append(int(temp_distance))

			debug.append('cities after: ' + str(len(approvedcity_set)))
			debug.append('city distances: ' + str(len(city_distances)))

			all_the_forecasts = []
			for city in city_set:
				tempForecast = oracle.get_forecast(city.latitude, city.longitude)
				#getting the day of the week for dates
				for datapoint in tempForecast:
					datapoint.day = datapoint.date.strftime('%A')
				#add forecast to forecast list
				all_the_forecasts.append(tempForecast)

			zipped = [{'city': t[0], 'weather': t[1], 'distance': t[2]} for t in zip(approvedcity_set, all_the_forecasts, city_distances)]
			# zipped = [{'city': t[0], 'distance':t[1], 'weather': t[2]} for t in zip(city_set, city_distances, all_the_forecasts)]
			# debug.append(str(len(city_set)) + ' cities')
			return render_to_response('./index.html', {'city_list':city_set,"citylist_length":len(city_set), 'forecasts':all_the_forecasts, 'form': form, 'zipped': zipped, 'debug':debug})
		else:
			debug.append('form data is invalid')
			form = WeatherForm(request.GET)
			return render_to_response('./index.html', {'form': form, 'debug':debug})

	else:
		debug.append('no GET request data')
		form = WeatherForm()
		return render_to_response('./index.html', {'form': form, 'debug':debug})
Exemple #7
0
def camp(request):
	city_set = []
	if request.method == 'GET':
		form = WeatherForm(request.GET)
		if form.is_valid():
			sample_zip = request.GET['location']
			max_distance = int(request.GET['distance'])
			# debug.append('max_distance: ' + str(max_distance))
			
			# switch here to use either the city or the zipcode
			if len(str(sample_zip)) == 5 and is_this_an_int(sample_zip):
				try:
					center_location = Zips.objects.get(zipcode=sample_zip)
				except ObjectDoesNotExist:
					notification = 'You sure that\'s a real zipcode?'
					return render_to_response('./camp.html', {'form': form,'notification':notification})
			else:
				# assume we werent given a zipcode, so parse it as a city
				parsed_zip = re.findall(r'\w+', sample_zip)
				city_name = ' '.join(parsed_zip[0:-1])
				state_name = parsed_zip[-1]

				# BUG: searching for a city when there is another in the same state...possible major rewrite required to handle searching with extra data(no more jQuery hack)
				try:
					center_location = City.objects.get(name__iexact=city_name, state__iexact=state_name)
				#in case we get nothing 
				except ObjectDoesNotExist:
					try:	
						# concatenates the city and state name, if a city is two words, it mixes things up, this fixes that
						if len(state_name) > 2 and len(city_name) != 0:
							state_name = city_name + ' ' +state_name
						possibleCityList = City.objects.filter(name__iexact=state_name)
						if len(possibleCityList) != 0:
							notification = 'I didn\'t catch the state. Here\'s a list of cities to start with: ' 
							return render_to_response('./camp.html', {'form': form, 'notification':notification, 'possibleCityList':possibleCityList})
						else:
							notification = 'I can\'t find '
							notification += state_name
							return render_to_response('./camp.html', {'form': form, 'notification':notification})
					except ObjectDoesNotExist:
						notification = 'I can\'t seem to find that city'
						return render_to_response('./camp.html', {'form': form,'notification':notification})
				# in case we have two cities with the same name in the same state
				except MultipleObjectsReturned:
					# we get cities & populations but, cant specify the search based on the cities GEOid or location
					possibleCityList = City.objects.filter(state__iexact=state_name).filter(name__iexact=city_name)
					notification = 'I got multiple cities with that name: clicking these will just mess with things...sorry'
					sameCities = True
					return render_to_response('./camp.html', {'form': form,'notification':notification, 'sameCities':sameCities, 'possibleCityList':possibleCityList})
				# Handling Non UTF data that python hates
				except OperationalError:
					notification = 'I\'ve encountered non-UTF data. And am notifying my superiors\n Sorry about this'
					return render_to_response('./camp.html', {'form': form,'notification':notification})

			# gives us a minimum and maximum to search in, it would look like a square centered around center_location
			max_lat = center_location.latitude + max_distance/69.09
			min_lat = center_location.latitude - max_distance/69.09
			max_long = center_location.longitude + max_distance/69.09
			min_long = center_location.longitude - max_distance/69.09

			camp_set = list(Campground.objects.filter(longitude__range=(min_long,max_long)).filter(latitude__range=(min_lat,max_lat)))

			# trim down the city list to a circle, and build the distance list
			camp_distances = []
			approvedcamp_set = []
			for campground in camp_set:
				temp_distance = calculate_distance(center_location, campground)

				if temp_distance < float(max_distance):
					approvedcamp_set.append(campground)
					camp_distances.append(int(temp_distance))

			#format the campground type to be human friendly
			for campground in approvedcamp_set:
				campground = camp_humanizer(campground)

			all_the_forecasts = []
			for campground in approvedcamp_set:
				tempForecast = oracle.get_forecast(campground.latitude, campground.longitude)
				#getting the day of the week for dates
				for datapoint in tempForecast:
					datapoint.day = datapoint.date.strftime('%A')
				#add forecast to forecast list
				all_the_forecasts.append(tempForecast)

			zipped = [{'campground': t[0], 'weather': t[1], 'distance': t[2]} for t in zip(approvedcamp_set, all_the_forecasts, camp_distances)]

			# no campgrounds were returned....
			if len(approvedcamp_set) > 0:
				return render_to_response('./camp.html', {"camplist_length":len(approvedcamp_set), 'forecasts':all_the_forecasts, 'form': form, 'zipped': zipped})
			else:
				notification = 'Search farther...'
				return render_to_response('./camp.html', {'form': form,'farther':notification})
		else:
			form = WeatherForm(request.GET)
			return render_to_response('./camp.html', {'form': form})

	else:
		form = WeatherForm()
		return render_to_response('./camp.html', {'form': form})