def getWeatherLocation(address): 'gets weather based on the address of the location' lat, lng = geocoding(address) lat = float('%.2f' %lat) lng = float('%.2f' %lng) weather, param_list = getWeatherGPS(lat, lng) return weather, param_list
def weatherdata(): # using_current_location = int(bool(request.args.get('CURRENT_LOCATION'))) location = request.args.get('location') original_location = location geocode = geocoding(location) request_url = generate_weather_url(geocode['coords']) print(request_url) forecast_request_tries = 0 max_forecast_request_tries = 10 try: forecast = requests.get(request_url).json() forecast = forecast.get('properties') except json.decoder.JSONDecodeError: return redirect(url_for('weatherdata', **request.args)) if forecast: forecast = forecast.get('periods') while not forecast: forecast = requests.get(request_url).json().get('properties') if forecast: forecast = forecast.get('periods') forecast_request_tries += 1 if forecast_request_tries >= max_forecast_request_tries: flash('Something went wrong.') return redirect(url_for('index', **request.args)) forecast_data = forecast[0:15] return render_template('weatherdata.html', forecast=forecast, address=geocode['string'], data=forecast_data, location=location, link_location=original_location)
def specific_day(date, location): date_arr = date.split('-') months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] day = date_arr[2] month = months[int(date_arr[1]) - 1] year = date_arr[0] date_string = f'{month} {day}, {year}' geocode = geocoding(location) request_url = generate_weather_url(geocode['coords'], hourly=True) try: forecast_request = requests.get(request_url).json() forecast_request = forecast_request.get('properties') except json.decoder.JSONDecodeError: return redirect(url_for('weatherdata', date=date, location=location)) if forecast_request: forecast_request = forecast_request.get('periods') forecast_request_tries = 0 max_forecast_request_tries = 10 while not forecast_request: forecast_request = requests.get(request_url).json().get('properties') if forecast_request: forecast_request = forecast_request.get('periods') forecast_request_tries += 1 if forecast_request_tries >= max_forecast_request_tries: flash('Something went wrong.') print(requests.get(request_url).json()) return redirect(url_for('index')) if session.get('DONT_SHOW_NIGHT'): forecast = [ x for x in forecast_request if x['startTime'].split('T')[0] == date and x['isDaytime'] == True ] else: forecast = [ x for x in forecast_request if x['startTime'].split('T')[0] == date ] return render_template('hourly.html', date=date, location=location, coords=geocode['coords'], forecast=forecast, date_string=date_string, link_location=location, address_string=geocode['string'], dont_show_night=session.get('DONT_SHOW_NIGHT'))
def post(): form = addressform(request.form) latlng = geocoding(form.address.data) if request.method == 'POST' and form.validate() and latlng!=0: food,shop = hotpepper(latlng) address = form.address.data form = addressform() return render_template('index.html',form=form,address=address,food=food,shop=shop) else: form=addressform() return render_template('index.html',form=form,shop=0,address=0)
给每一行的数据都添加一项坐标 ''' import csv # pip install csvfile import geocoding ''' 配置 ''' paths = [] # 文件列表 path_list = 2 # 下标 for path in paths: # path = '钱眼网\钱眼网企业资料_电脑互联网.csv' # 文件名 print('正在操作%s' % path) new_path = '已完成\\' + path key = '40fe8f7ca0626fe71fe12bdc54922ded' gao_api = geocoding.geocoding(key) with open(path, 'r', encoding="utf-8") as csvFile: rows = csv.reader(csvFile) with open(new_path, 'w', encoding="utf-8") as f: writer = csv.writer(f) for row in rows: if row[path_list] == '企业地址': row.append("地址坐标") writer.writerow(row) else: if len(row) >= (path_list + 1): g = gao_api.index(row[path_list], 1) row.append(g) writer.writerow(row)
def main(): geocoding() df = np.array(pd.read_csv('locations_kml.csv', header=None)) baixa_imagem(df[0][2], df[0][3])
def main(address): hotpepper(geocoding(address))
from get_cities import get_cities from geocoding import geocoding get_cities() geocoding()