Select data from openweathermaps with python

Need help with C, C++, perl, python, etc?

Select data from openweathermaps with python

Postby Stian1979 » 2020-03-07 20:01

Been reading this from openweathermaps and I wish to select the data from thats valid for tomorrow only.
How would I go about to do that in python?


Code: Select all
{'message': 0, 'cod': '200', 'city': {'country': 'NO', 'sunset': 1583600359, 'population': 580000, 'sunrise': 1583560613, 'timezone': 3600, 'id': 3143244, 'name': 'Oslo', 'coord': {'lon': 10.7461, 'lat': 59.9127}}, 'cnt': 40, 'list': [{'main': {'humidity': 90, 'sea_level': 1010, 'grnd_level': 983, 'pressure': 1010, 'temp_min': 269.84, 'temp_max': 271.86, 'feels_like': 264.93, 'temp_kf': -2.02, 'temp': 269.84}, 'dt': 1583604000, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 803, 'description': 'broken clouds'}], 'wind': {'speed': 3.33, 'deg': 194}, 'clouds': {'all': 61}, 'dt_txt': '2020-03-07 18:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 92, 'sea_level': 1009, 'grnd_level': 983, 'pressure': 1009, 'temp_min': 271.36, 'temp_max': 272.88, 'feels_like': 266.33, 'temp_kf': -1.52, 'temp': 271.36}, 'dt': 1583614800, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 3.79, 'deg': 194}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-07 21:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 96, 'sea_level': 1007, 'grnd_level': 981, 'pressure': 1007, 'temp_min': 273.35, 'temp_max': 274.36, 'feels_like': 267.27, 'temp_kf': -1.01, 'temp': 273.35}, 'dt': 1583625600, 'dt_txt': '2020-03-08 00:00:00', 'weather': [{'icon': '13n', 'main': 'Snow', 'id': 600, 'description': 'light snow'}], 'wind': {'speed': 5.77, 'deg': 191}, 'clouds': {'all': 100}, 'snow': {'3h': 0.88}, 'sys': {'pod': 'n'}}, {'main': {'humidity': 94, 'sea_level': 1003, 'grnd_level': 977, 'pressure': 1003, 'temp_min': 274.95, 'temp_max': 275.46, 'feels_like': 269.33, 'temp_kf': -0.51, 'temp': 274.95}, 'rain': {'3h': 0.31}, 'dt': 1583636400, 'weather': [{'icon': '10n', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 5.4, 'deg': 182}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-08 03:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 95, 'sea_level': 1000, 'grnd_level': 975, 'pressure': 1000, 'temp_min': 276.41, 'temp_max': 276.41, 'feels_like': 271.15, 'temp_kf': 0, 'temp': 276.41}, 'rain': {'3h': 1.06}, 'dt': 1583647200, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 5.26, 'deg': 180}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-08 06:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 94, 'sea_level': 998, 'grnd_level': 973, 'pressure': 998, 'temp_min': 277.6, 'temp_max': 277.6, 'feels_like': 271.69, 'temp_kf': 0, 'temp': 277.6}, 'rain': {'3h': 2.25}, 'dt': 1583658000, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 6.44, 'deg': 189}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-08 09:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 94, 'sea_level': 997, 'grnd_level': 971, 'pressure': 997, 'temp_min': 277.88, 'temp_max': 277.88, 'feels_like': 271.9, 'temp_kf': 0, 'temp': 277.88}, 'rain': {'3h': 1.75}, 'dt': 1583668800, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 6.62, 'deg': 184}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-08 12:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 92, 'sea_level': 994, 'grnd_level': 970, 'pressure': 994, 'temp_min': 278.32, 'temp_max': 278.32, 'feels_like': 271.97, 'temp_kf': 0, 'temp': 278.32}, 'rain': {'3h': 3}, 'dt': 1583679600, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 7.18, 'deg': 201}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-08 15:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 88, 'sea_level': 996, 'grnd_level': 971, 'pressure': 996, 'temp_min': 277.07, 'temp_max': 277.07, 'feels_like': 270.9, 'temp_kf': 0, 'temp': 277.07}, 'rain': {'3h': 0.13}, 'dt': 1583690400, 'weather': [{'icon': '10n', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 6.45, 'deg': 200}, 'clouds': {'all': 85}, 'dt_txt': '2020-03-08 18:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 89, 'sea_level': 998, 'grnd_level': 972, 'pressure': 998, 'temp_min': 276.25, 'temp_max': 276.25, 'feels_like': 270.57, 'temp_kf': 0, 'temp': 276.25}, 'dt': 1583701200, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 803, 'description': 'broken clouds'}], 'wind': {'speed': 5.6, 'deg': 199}, 'clouds': {'all': 67}, 'dt_txt': '2020-03-08 21:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 91, 'sea_level': 1000, 'grnd_level': 974, 'pressure': 1000, 'temp_min': 275.14, 'temp_max': 275.14, 'feels_like': 270.13, 'temp_kf': 0, 'temp': 275.14}, 'dt': 1583712000, 'weather': [{'icon': '03n', 'main': 'Clouds', 'id': 802, 'description': 'scattered clouds'}], 'wind': {'speed': 4.47, 'deg': 202}, 'clouds': {'all': 41}, 'dt_txt': '2020-03-09 00:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 90, 'sea_level': 1001, 'grnd_level': 975, 'pressure': 1001, 'temp_min': 274.91, 'temp_max': 274.91, 'feels_like': 270.34, 'temp_kf': 0, 'temp': 274.91}, 'dt': 1583722800, 'weather': [{'icon': '02n', 'main': 'Clouds', 'id': 801, 'description': 'few clouds'}], 'wind': {'speed': 3.75, 'deg': 200}, 'clouds': {'all': 23}, 'dt_txt': '2020-03-09 03:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 96, 'sea_level': 1002, 'grnd_level': 976, 'pressure': 1002, 'temp_min': 275.47, 'temp_max': 275.47, 'feels_like': 271.2, 'temp_kf': 0, 'temp': 275.47}, 'dt': 1583733600, 'weather': [{'icon': '03d', 'main': 'Clouds', 'id': 802, 'description': 'scattered clouds'}], 'wind': {'speed': 3.65, 'deg': 198}, 'clouds': {'all': 29}, 'dt_txt': '2020-03-09 06:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 94, 'sea_level': 1004, 'grnd_level': 978, 'pressure': 1004, 'temp_min': 276.62, 'temp_max': 276.62, 'feels_like': 272.5, 'temp_kf': 0, 'temp': 276.62}, 'dt': 1583744400, 'weather': [{'icon': '04d', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 3.64, 'deg': 206}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-09 09:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 85, 'sea_level': 1004, 'grnd_level': 979, 'pressure': 1004, 'temp_min': 278.52, 'temp_max': 278.52, 'feels_like': 274.57, 'temp_kf': 0, 'temp': 278.52}, 'dt': 1583755200, 'weather': [{'icon': '04d', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 3.51, 'deg': 204}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-09 12:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 94, 'sea_level': 1004, 'grnd_level': 979, 'pressure': 1004, 'temp_min': 277, 'temp_max': 277, 'feels_like': 273.31, 'temp_kf': 0, 'temp': 277}, 'rain': {'3h': 0.81}, 'dt': 1583766000, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 3.12, 'deg': 201}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-09 15:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 98, 'sea_level': 1004, 'grnd_level': 978, 'pressure': 1004, 'temp_min': 275.9, 'temp_max': 275.9, 'feels_like': 272.29, 'temp_kf': 0, 'temp': 275.9}, 'dt': 1583776800, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 2.88, 'deg': 190}, 'clouds': {'all': 98}, 'dt_txt': '2020-03-09 18:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 95, 'sea_level': 1004, 'grnd_level': 978, 'pressure': 1004, 'temp_min': 276.2, 'temp_max': 276.2, 'feels_like': 272.37, 'temp_kf': 0, 'temp': 276.2}, 'dt': 1583787600, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 3.16, 'deg': 200}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-09 21:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 95, 'sea_level': 1003, 'grnd_level': 977, 'pressure': 1003, 'temp_min': 273.91, 'temp_max': 273.91, 'feels_like': 270.18, 'temp_kf': 0, 'temp': 273.91}, 'dt': 1583798400, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 2.51, 'deg': 213}, 'clouds': {'all': 85}, 'dt_txt': '2020-03-10 00:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 94, 'sea_level': 1002, 'grnd_level': 976, 'pressure': 1002, 'temp_min': 272.83, 'temp_max': 272.83, 'feels_like': 268.5, 'temp_kf': 0, 'temp': 272.83}, 'dt': 1583809200, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 803, 'description': 'broken clouds'}], 'wind': {'speed': 3.12, 'deg': 207}, 'clouds': {'all': 80}, 'dt_txt': '2020-03-10 03:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 97, 'sea_level': 1000, 'grnd_level': 974, 'pressure': 1000, 'temp_min': 275.5, 'temp_max': 275.5, 'feels_like': 271.39, 'temp_kf': 0, 'temp': 275.5}, 'rain': {'3h': 0.19}, 'dt': 1583820000, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 3.47, 'deg': 197}, 'clouds': {'all': 87}, 'dt_txt': '2020-03-10 06:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 96, 'sea_level': 995, 'grnd_level': 970, 'pressure': 995, 'temp_min': 276, 'temp_max': 276, 'feels_like': 270.05, 'temp_kf': 0, 'temp': 276}, 'rain': {'3h': 1.75}, 'dt': 1583830800, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed': 6.18, 'deg': 187}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-10 09:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 92, 'sea_level': 988, 'grnd_level': 963, 'pressure': 988, 'temp_min': 277.3, 'temp_max': 277.3, 'feels_like': 270.65, 'temp_kf': 0, 'temp': 277.3}, 'rain': {'3h': 3.94}, 'dt': 1583841600, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 501, 'description': 'moderate rain'}], 'wind': {'speed': 7.34, 'deg': 183}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-10 12:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 82, 'sea_level': 983, 'grnd_level': 958, 'pressure': 983, 'temp_min': 280.36, 'temp_max': 280.36, 'feels_like': 274.4, 'temp_kf': 0, 'temp': 280.36}, 'rain': {'3h': 2.13}, 'dt': 1583852400, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 500, 'description': 'light rain'}], 'wind': {'speed':
 6.73, 'deg': 209}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-10 15:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 78, 'sea_level': 983, 'grnd_level': 959, 'pressure': 983, 'temp_min': 277.82, 'temp_max': 277.82, 'feels_like': 271.99, 'temp_kf': 0, 'temp': 277.82}, 'dt': 1583863200, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 803, 'description': 'broken clouds'}], 'wind': {'speed': 5.75, 'deg': 219}, 'clouds': {'all': 83}, 'dt_txt': '2020-03-10 18:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 77, 'sea_level': 985, 'grnd_level': 960, 'pressure': 985, 'temp_min': 277.62, 'temp_max': 277.62, 'feels_like': 271.59, 'temp_kf': 0, 'temp': 277.62}, 'dt': 1583874000, 'weather': [{'icon': '03n', 'main': 'Clouds', 'id': 802, 'description': 'scattered clouds'}], 'wind': {'speed': 5.95, 'deg': 233}, 'clouds': {'all': 25}, 'dt_txt': '2020-03-10 21:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 70, 'sea_level': 987, 'grnd_level': 962, 'pressure': 987, 'temp_min': 276.56, 'temp_max': 276.56, 'feels_like': 270.33, 'temp_kf': 0, 'temp': 276.56}, 'dt': 1583884800, 'weather': [{'icon': '02n', 'main': 'Clouds', 'id': 801, 'description': 'few clouds'}], 'wind': {'speed': 5.76, 'deg': 237}, 'clouds': {'all': 13}, 'dt_txt': '2020-03-11 00:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 66, 'sea_level': 989, 'grnd_level': 964, 'pressure': 989, 'temp_min': 276.25, 'temp_max': 276.25, 'feels_like': 269.71, 'temp_kf': 0, 'temp': 276.25}, 'dt': 1583895600, 'weather': [{'icon': '01n', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 6, 'deg': 239}, 'clouds': {'all': 0}, 'dt_txt': '2020-03-11 03:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 70, 'sea_level': 991, 'grnd_level': 966, 'pressure': 991, 'temp_min': 275.39, 'temp_max': 275.39, 'feels_like': 269.01, 'temp_kf': 0, 'temp': 275.39}, 'dt': 1583906400, 'weather': [{'icon': '01d', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 5.77, 'deg': 226}, 'clouds': {'all': 0}, 'dt_txt': '2020-03-11 06:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 56, 'sea_level': 994, 'grnd_level': 969, 'pressure': 994, 'temp_min': 278.28, 'temp_max': 278.28, 'feels_like': 271.59, 'temp_kf': 0, 'temp': 278.28}, 'dt': 1583917200, 'weather': [{'icon': '01d', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 6.17, 'deg': 243}, 'clouds': {'all': 0}, 'dt_txt': '2020-03-11 09:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 50, 'sea_level': 996, 'grnd_level': 971, 'pressure': 996, 'temp_min': 280.29, 'temp_max': 280.29, 'feels_like': 273.35, 'temp_kf': 0, 'temp': 280.29}, 'dt': 1583928000, 'weather': [{'icon': '01d', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 6.58, 'deg': 240}, 'clouds': {'all': 0}, 'dt_txt': '2020-03-11 12:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 63, 'sea_level': 994, 'grnd_level': 969, 'pressure': 994, 'temp_min': 279.8, 'temp_max': 279.8, 'feels_like': 273.13, 'temp_kf': 0, 'temp': 279.8}, 'dt': 1583938800, 'weather': [{'icon': '01d', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 6.71, 'deg': 217}, 'clouds': {'all': 0}, 'dt_txt': '2020-03-11 15:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 66, 'sea_level': 994, 'grnd_level': 969, 'pressure': 994, 'temp_min': 277.9, 'temp_max': 277.9, 'feels_like': 271.29, 'temp_kf': 0, 'temp': 277.9}, 'dt': 1583949600, 'weather': [{'icon': '01n', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 6.4, 'deg': 228}, 'clouds': {'all': 6}, 'dt_txt': '2020-03-11 18:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 79, 'sea_level': 994, 'grnd_level': 969, 'pressure': 994, 'temp_min': 276.1, 'temp_max': 276.1, 'feels_like': 270.66, 'temp_kf': 0, 'temp': 276.1}, 'dt': 1583960400, 'weather': [{'icon': '01n', 'main': 'Clear', 'id': 800, 'description': 'clear sky'}], 'wind': {'speed': 4.86, 'deg': 207}, 'clouds': {'all': 0}, 'dt_txt': '2020-03-11 21:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 85, 'sea_level': 993, 'grnd_level': 968, 'pressure': 993, 'temp_min': 275.59, 'temp_max': 275.59, 'feels_like': 270.29, 'temp_kf': 0, 'temp': 275.59}, 'dt': 1583971200, 'weather': [{'icon': '03n', 'main': 'Clouds', 'id': 802, 'description': 'scattered clouds'}], 'wind': {'speed': 4.77, 'deg': 200}, 'clouds': {'all': 50}, 'dt_txt': '2020-03-12 00:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 88, 'sea_level': 989, 'grnd_level': 964, 'pressure': 989, 'temp_min': 274.97, 'temp_max': 274.97, 'feels_like': 271.07, 'temp_kf': 0, 'temp': 274.97}, 'dt': 1583982000, 'weather': [{'icon': '04n', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 2.74, 'deg': 184}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-12 03:00:00', 'sys': {'pod': 'n'}}, {'main': {'humidity': 98, 'sea_level': 981, 'grnd_level': 955, 'pressure': 981, 'temp_min': 274.87, 'temp_max': 274.87, 'feels_like': 272.06, 'temp_kf': 0, 'temp': 274.87}, 'rain': {'3h': 5.81}, 'dt': 1583992800, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 501, 'description': 'moderate rain'}], 'wind': {'speed': 1.49, 'deg': 117}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-12 06:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 96, 'sea_level': 976, 'grnd_level': 951, 'pressure': 976, 'temp_min': 275.5, 'temp_max': 275.5, 'feels_like': 270.83, 'temp_kf': 0, 'temp': 275.5}, 'rain': {'3h': 5.19}, 'dt': 1584003600, 'weather': [{'icon': '10d', 'main': 'Rain', 'id': 501, 'description': 'moderate rain'}], 'wind': {'speed': 4.23, 'deg': 239}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-12 09:00:00', 'sys': {'pod': 'd'}}, {'main': {'humidity': 65, 'sea_level': 981, 'grnd_level': 957, 'pressure': 981, 'temp_min': 278.04, 'temp_max': 278.04, 'feels_like': 271.66, 'temp_kf': 0, 'temp': 278.04}, 'dt': 1584014400, 'dt_txt': '2020-03-12 12:00:00', 'weather': [{'icon': '13d', 'main': 'Snow', 'id': 600, 'description': 'light snow'}], 'wind': {'speed': 6.05, 'deg': 279}, 'clouds': {'all': 100}, 'snow': {'3h': 0.5}, 'sys': {'pod': 'd'}}, {'main': {'humidity': 61, 'sea_level': 986, 'grnd_level': 962, 'pressure': 986, 'temp_min': 277.52, 'temp_max': 277.52, 'feels_like': 271.59, 'temp_kf': 0, 'temp': 277.52}, 'dt': 1584025200, 'weather': [{'icon': '04d', 'main': 'Clouds', 'id': 804, 'description': 'overcast clouds'}], 'wind': {'speed': 5.16, 'deg': 231}, 'clouds': {'all': 100}, 'dt_txt': '2020-03-12 15:00:00', 'sys': {'pod': 'd'}}]}
Image
Stian1979
 
Posts: 313
Joined: 2007-07-29 14:57

Re: Select data from openweathermaps with python

Postby Stian1979 » 2020-03-07 20:59

I think part of this is finding tomorrows date.
Code: Select all
import datetime
tomorrow = datetime.date.today() + datetime.timedelta(days=1)

Then use this to find where in the data I wish to start read.
Code: Select all
y = x[tomorrow_12:00:00]

put a limit on how many caracters it should read in.
Image
Stian1979
 
Posts: 313
Joined: 2007-07-29 14:57

Re: Select data from openweathermaps with python

Postby Dai_trying » 2020-03-08 06:18

If that is part of a web page then you could easily "scrape" the content you need, I found this YT video by engineer man very interesting when I was doing something similar, other YT authors to look for might be Corey schafer who provides a lot of python content (including web scraping). I found it great for gathering only the information you want from a page into variables/lists/dicts/etc. If on the other hand it is just json data then it could also easily be parsed that way.
Dai_trying
 
Posts: 936
Joined: 2016-01-07 12:25

Re: Select data from openweathermaps with python

Postby Stian1979 » 2020-03-08 06:29

Dai_trying wrote:If that is part of a web page then you could easily "scrape" the content you need, I found this YT video by engineer man very interesting when I was doing something similar, other YT authors to look for might be Corey schafer who provides a lot of python content (including web scraping). I found it great for gathering only the information you want from a page into variables/lists/dicts/etc. If on the other hand it is just json data then it could also easily be parsed that way.


Json data.
The code I have "stolen" looks for main I think, but that call was for current data and not for forcast.
Therefore I think it fails because its multiple main in this response.
What I am thinking anyways and might be totally wrong..
Image
Stian1979
 
Posts: 313
Joined: 2007-07-29 14:57

Re: Select data from openweathermaps with python

Postby Stian1979 » 2020-03-08 15:49

Dai_trying wrote:If that is part of a web page then you could easily "scrape" the content you need, I found this YT video by engineer man very interesting when I was doing something similar, other YT authors to look for might be Corey schafer who provides a lot of python content (including web scraping). I found it great for gathering only the information you want from a page into variables/lists/dicts/etc. If on the other hand it is just json data then it could also easily be parsed that way.


That youtube video you sugested was interesting..
Just too bad it dont apply to what I am trying to do or I simply did not see how..
Image
Stian1979
 
Posts: 313
Joined: 2007-07-29 14:57

Re: Select data from openweathermaps with python

Postby Dai_trying » 2020-03-08 19:06

You are right it is probably not the way to do it, but I think it would likely be the easiest option to scrape a weather site for the information you want, either that or let us know how (by what method) you are getting your data so we could offer an alternative.
Dai_trying
 
Posts: 936
Joined: 2016-01-07 12:25

Re: Select data from openweathermaps with python

Postby Stian1979 » 2020-03-08 19:46

Shamelessly copied someones work and been playing with it.
Added a line that tells me what date it is tomorrow so I can use it to pick data from the response, but got no idea how to do it and youtube and google has not been helpful.
I should also try spesify the time a day.

Code: Select all
# import required modules
import requests, json
import datetime
# What date is it tomorrow?
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
   
# complete_url variable to store
# complete url address
complete_url = "http://api.openweathermap.org/data/2.5/forecast?q=Oslo,NO&appid=xxxxxx"
# get method of requests module
# return response object
response = requests.get(complete_url)
 
# json method of response object 
# convert json format data into
# python format data
x = response.json()
 
# Now x contains list of nested dictionaries
# Check the value of "cod" key is equal to
# "404", means city is found otherwise,
# city is not found
if x["cod"] != "404":
 
    # store the value of "main"
    # key in variable y
    y = x["tomorrow"]
 
    # store the value corresponding
    # to the "temp" key of y
    current_temperature = y["temp"]
 
   
 
    # print following values
    print(" Temperature (in kelvin unit) = " +
                    str(current_temperature))
 
else:
    print(" City Not Found ")
Image
Stian1979
 
Posts: 313
Joined: 2007-07-29 14:57

Re: Select data from openweathermaps with python

Postby Dai_trying » 2020-03-08 20:33

What "data" do you actually need/want?
Dai_trying
 
Posts: 936
Joined: 2016-01-07 12:25

Re: Select data from openweathermaps with python

Postby Stian1979 » 2020-03-09 05:32

Dai_trying wrote:What "data" do you actually need/want?

Tomorrows forcast at 12:00. Temperature, sunrise and clouds for starters.
Image
Stian1979
 
Posts: 313
Joined: 2007-07-29 14:57


Return to Programming

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable