def weather_string(): city = request.args.get('city') state = request.args.get('state') if city is None or state is None: # abort(400, description='City and state must be provided') return 'City and state must be provided', 400 conditions = get_conditions(city, state) if conditions is None: return 'Place not found', 404 return f'{city.title()}, {state.upper()}. {conditions}'
def weather_photo(): city = request.args.get('city') state = request.args.get('state') if city is None or state is None: # abort(400, description='City and state must be provided') return 'City and state must be provided', 400 conditions = get_conditions(city, state) if conditions is None: return 'Place not found', 404 photo = photo_path(conditions) if photo: return send_file(photo) else: print('conditions', conditions) return 'No photo!'
def update_row(index, input_row, column_settings, output_worksheet, styles): row_values = list(input_cell.value for input_cell in input_row) if index > 0: formatting.standardize(index, row_values, column_settings) date, lat, lon = ( row_values[column_settings['date']['index']], row_values[column_settings['lkp_ns']['index']], row_values[column_settings['lkp_ew']['index']] ) snow = row_values[column_settings['snow']['index']] if type(snow) is str and 'NO' in snow.upper(): row_values[column_settings['snow']['index']] = 0.0 rain = row_values[column_settings['rain']['index']] if type(rain) is str and 'NO' in rain.upper(): row_values[column_settings['rain']['index']] = 0.0 if type(date) is datetime.datetime and \ type(lat) is float and type(lon): coordinates = geopy.Point(lat, lon) conditions = weather.get_conditions(date, coordinates) if type(conditions['TMAX']) is float: temp_max = round(conditions['TMAX']/10, 3) row_values[column_settings['temp_max']['index']] = temp_max util.log('Case {}: Temp/H -> {} deg. C'.format(index, temp_max)) if type(conditions['TMIN']) is float: temp_min = round(conditions['TMIN']/10, 3) row_values[column_settings['temp_min']['index']] = temp_min util.log('Case {}: Temp/L -> {} deg C'.format(index, temp_min)) if type(conditions['AWND']) is float: # 1 m/s = 3.6 km/h wind_speed = round(conditions['AWND']/1000*60*60, 3) row_values[column_settings['wind_speed']['index']] = wind_speed util.log('Case {}: Wind Speed -> {} km/h'.format( index, wind_speed)) if type(conditions['SNOW']) is float: snow = round(conditions['SNOW'], 3) row_values[column_settings['snow']['index']] = snow util.log('Case {}: Snowfall -> {} mm'.format(index, snow)) if type(conditions['PRCP']) is float: prcp = round(conditions['PRCP'], 3) snow = row_values[column_settings['snow']['index']] if type(snow) is float: rain = round(max(prcp - snow, 0.0), 3) elif type(snow) is float and 'YES' in snow.upper(): rain = 0.0 else: rain = round(prcp, 3) row_values[column_settings['rain']['index']] = rain util.log('Case {}: Rainfall -> {} mm'.format(index, rain)) for value in row_values: output_cell = openpyxl.writer.dump_worksheet.WriteOnlyCell( output_worksheet, value) for attribute, style in styles.items(): setattr(output_cell, attribute, style) else: yield output_cell
worksheet_out.append([openpyxl.writer.dump_worksheet.WriteOnlyCell(worksheet_out, value) for value in values]) continue date, ipp = values[4], values[113] if type(date) is str: try: date = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S') except ValueError: date = datetime.datetime.strptime(date, '%Y-%m-%d') values[4] = date if ipp: lat, lon = ipp.split(', ') lat, lon = float(lat), float(lon) point = geopy.Point(lat, lon) conditions = weather.get_conditions(date, point) values[122] = round(conditions['TMAX']/10, 3) if conditions['TMAX'] is not None else None values[123] = round(conditions['TMIN']/10, 3) if conditions['TMIN'] is not None else None values[124] = round(conditions['AWND']*3.6, 3) if conditions['AWND'] is not None else None values[126] = round(conditions['SNOW'], 3) if conditions['SNOW'] is not None else None if conditions['PRCP'] is not None: if conditions['SNOW'] is not None: values[127] = round(max(conditions['PRCP'] - conditions['SNOW'], 0.0), 3) else: values[127] = round(conditions['PRCP'], 3) print(values[122:128], conditions, index) worksheet_out.append([openpyxl.writer.dump_worksheet.WriteOnlyCell(worksheet_out, value) for value in values]) workbook_out.save('ISRID-2015-NY-updated.xlsx')
if type(ipp) is str: lat, lon = ipp.split(', ') lat, lon = float(lat), float(lon) if type(incident_datetime) is not datetime.datetime: if ':' not in incident_datetime: incident_datetime += ' 00:00:00' incident_datetime = datetime.datetime.strptime( incident_datetime, datefmt) assert type(incident_datetime) is datetime.datetime conditions = None if lat and lon and incident_datetime: point = geopy.Point(lat, lon) conditions = weather.get_conditions(incident_datetime, point) print('({}, {}) @ "{}" -> {}'.format(lat, lon, incident_datetime.isoformat(), conditions)) key = str(key) if not status or 'N/A' in status.upper().strip(): continue elif status.upper().strip() in ('SUSPENDED', 'DOA'): status = 'DEAD' elif 'N/A' not in status.upper().strip(): status = 'ALIVE' age = str(age) if age else '' if sex is None: sex = '' else: