file = os.path.join(os.getcwd(), 'config', 'config') with open(file) as f: for line in f: if '=' in line: line = line.replace('"', '') data[line.rsplit(' = ')[0].strip()] = line.rsplit( ' = ')[1].strip() # I put spaces around the "=" because the url will have an "=" in it, # but the rest of the config data will have spaces around "=". return data def ocean_data(source, my_loc): WeatherInfo = NoaaParser() all_locations = WeatherInfo.parse_results(source) my_sources = WeatherInfo.get_locations(my_loc, all_locations) return WeatherInfo.weather_get(my_sources) if __name__ == '__main__': configs = read_config() username = configs['EMAIL_USERNAME'] password = configs['EMAIL_PASSWORD'] recipient = configs['RECIPIENT'] region = configs['SET_REGION'] location = configs['SET_LOCATION'] message = '\n'.join(ocean_data(region, location)) send_text(username, password, recipient, message)
# Location settings source = configs['noaa.gov settings']['my_source'] location = configs['noaa.gov settings']['location'] time_zone = configs['location settings']['set_time_zone'] all_dat = configs['forecast settings'].getboolean('send_all_data') forecast = configs['forecast settings'].getboolean('send_marine_forecast') hours_ = int(configs['forecast settings']['hours_ahead_to_forecast']) tmpfile = 'tmp-forecast.csv' weather = NoaaParser() weather.get_locations(location, source) if all_dat: message = weather.weather_get_all() # returns a list else: message = weather.weather_info_dict(time_zone) # returns a dict if forecast: with open(tmpfile, 'w') as f: for n in weather.prettify_forecast(hours_ahead=hours_): field, time, data = n f.write(field + ',' + time + ',' + data + '\n') else: pass weather_msg = location + '\n' + make_message(message) send_text(username, password, recipient, weather_msg) # need attachment module
def read_config(): data = {} file = os.path.join(os.getcwd(), "config", "config") with open(file) as f: for line in f: if "=" in line: line = line.replace('"', "") data[line.rsplit(" = ")[0].strip()] = line.rsplit(" = ")[1].strip() # I put spaces around the "=" because the url will have an "=" in it, # but the rest of the config data will have spaces around "=". return data def ocean_data(source, my_loc): WeatherInfo = NoaaParser() all_locations = WeatherInfo.parse_results(source) my_sources = WeatherInfo.get_locations(my_loc, all_locations) return WeatherInfo.weather_get(my_sources) if __name__ == "__main__": configs = read_config() username = configs["EMAIL_USERNAME"] password = configs["EMAIL_PASSWORD"] recipient = configs["RECIPIENT"] region = configs["SET_REGION"] location = configs["SET_LOCATION"] message = "\n".join(ocean_data(region, location)) send_text(username, password, recipient, message)
elif isinstance(input_data, dict): for key, val in input_data.items(): messagestring += key + '\n' if isinstance(val, dict): for newkey, newval in val.items(): messagestring += newkey + ' ' + newval + '\n' else: messagestring += val + '\n' return messagestring if __name__ == '__main__': configs = read_config() username = configs['email']['username'] password = configs['email']['password'] recipient = configs['cell settings']['recipient'] region = configs['noaa.gov settings']['region'] location = configs['noaa.gov settings']['location'] time_zone = configs['location settings']['set_time_zone'] all_dat = configs['data requested'].getboolean('all') if all_dat: message = ocean_data_all(region, location) # returns a list else: message = ocean_data_clean(region, location, time_zone) # returns a dict weather_msg = location + '\n' + make_message(message) send_text(username, password, recipient, weather_msg)
messagestring = "\n".join(input_data) elif isinstance(input_data, dict): for key, val in input_data.items(): messagestring += key + "\n" if isinstance(val, dict): for newkey, newval in val.items(): messagestring += newkey + " " + newval + "\n" else: messagestring += val + "\n" return messagestring if __name__ == "__main__": configs = read_config() username = configs["email"]["username"] password = configs["email"]["password"] recipient = configs["cell settings"]["recipient"] region = configs["noaa.gov settings"]["region"] location = configs["noaa.gov settings"]["location"] time_zone = configs["location settings"]["set_time_zone"] all_dat = configs["data requested"].getboolean("all") if all_dat: message = ocean_data_all(region, location) # returns a list else: message = ocean_data_clean(region, location, time_zone) # returns a dict weather_msg = location + "\n" + make_message(message) send_text(username, password, recipient, weather_msg)