Reputation: 89
currently I'm using MATLAB to scrape openweathermap.org data on max temp, min temp, pressure, and humidity from an API. My problem is that no matter what lat and lon I specify in the url, the url is staying the exact same. Here is a link to the API site I'm using for current data: https://openweathermap.org/current
Currently I'm trying a method where I change the latitude and longitude to match the latitude and longitude of a point in a for loop. I'm trying to write these data to a csv file. The writing is going fine, my only problem is that no matter how I change the URL the data on the sheet stay the same.
clear all
close all
% Using data from https://openweathermap.org/history
% Inputs are the latitude and longitude.
%% Add the EPA Code
match_file = 'C:\Users\tadams15\Desktop\Matching_Sites.csv';
data = xlsread(match_file);
lat = data(:,1);
lon = data(:,2);
for i = 1:length(lat)
latv = lat(i);
lonv = lon(i);
url = ['https://samples.openweathermap.org/data/2.5/weather?lat=',num2str(latv),'&lon=',num2str(lonv),'&appid=b6907d289e10d714a6e88b30761fae22'];
tempmaxtarget = 'temp_max';
tempmintarget = 'temp_min';
prestarget = 'pressure';
humtarget = 'humidity';
tempmax = urlfilter(url,tempmaxtarget);
tempmin = urlfilter(url,tempmintarget);
pressure = urlfilter(url,prestarget);
humidity = urlfilter(url,humtarget);
input = [tempmin tempmax pressure humidity];
dlmwrite('Site_Info.csv',input,'delimiter',',','-append');
end
Upvotes: 0
Views: 350
Reputation: 28595
I don't use MATLAB, I use Python so I can;t test, but it looks like you need to fix your url.
It looks like you're just calling up the sample return everytime:
https://samples.openweathermap.org/data/2.5/weather
Maybe you want instead?:
api.openweathermap.org/data/2.5/weather
Upvotes: 1