{*************************************************************** * Project : REST GEO OpenWeather Report * App Name : 640_rest_weather_report.txt, #locs=181 * Purpose : Demonstrates for Tutorial 40 REST Coding * Date : #sign>3:34 Max: MAXBOX10: 15/10/2015 10:24:03 AM * History : convert GEOCode to metrics (celcius) * : add byte code test unit * Tutor : http://www.softwareschule.ch/download/maxbox_starter40.pdf ****************************************************************} //////////////////////////////////////////////////////////////////////////////// // Contains code to process GeoCode in XML data fields // // max@kleiner.ch August 2015 www.openweathermap.com // //////////////////////////////////////////////////////////////////////////////// {@To get access to weather API you need an API key whatever account you chose!!} Program GetGeoCode_API_Weather2; CONST UrlMapQuestAPICode2='http://open.mapquestapi.com/nominatim/v1/search.php?format=%s&json_callback=renderBasicSearchNarrative&q=%s'; UrlMapQuestAPIReverse= 'http://open.mapquestapi.com/nominatim/v1/reverse.php?format=%s&json_callback=renderExampleThreeResults&lat=%s&lon=%s'; UrlGeoLookupInfo2 ='http://ipinfodb.com/ip_query.php?timezone=true&ip=%s'; UrlGeoLookupInfo3 = 'http://api.hostip.info/get_html.php?ip=%s&position=true'; const WeatherREX = //test: '.*Äàòà\s*Êó?ñ\s*Êó?ñ ïîê.\s*Êó?ñ ï?îä.\s*Êóðñ íà?[^<\d]*' '"temp":([\d\.]+).*"pressure":([0-9]+).*"humidity":([0-9]+).*"name":"([\w]+)"'; function GetGeoInfo4(const IpAddress: string; const UrlGeoLookupInfo: string): string; var lHTTP: TIdHTTP; lStream: TStringStream; begin lHTTP:= TIdHTTP.Create(NIL); lStream:= TStringStream.Create(''); try try lHTTP.Get1(Format(UrlGeoLookupInfo,[IpAddress]), lStream); except lHTTP.Get1(Format(UrlGeoLookupInfo2,[IpAddress]), lStream); //if something wrong try using a backup server. end; lStream.Seek(0,0); result:= 'GEO_IP Out: '+lStream.ReadString(lStream.Size); finally lHTTP.Free; lStream.Free; end; end; //test http://api.openweathermap.org/data/2.5/weather?q={klagenfurt} Const //UrlWeatherReport25='http://api.openweathermap.org/data/2.5/weather?q=%s&units=metric'; UrlWeatherReport25= 'http://api.openweathermap.org/data/2.5/weather?q=%s&units=metric&APPID'+ '=55013bf3d09cfb0619989a00ed5bed09'; {@To get access to weather API you need an API key whatever account you chose!!} function GetGeoWeather(const location: string; const UrlRestAPI: string): string; var lHTTP: TIdHTTP; lStream: TStringStream; begin lHTTP:= TIdHTTP.Create(NIL); lStream:= TStringStream.Create(''); try try lHTTP.Get1(Format(UrlRestAPI,[location]),lStream); except lHTTP.Get1(Format(UrlGeoLookupInfo2,[location]),lStream); //if something wrong try using a backup server. end; lStream.Seek(0,0); result:= 'GEO_Weather_Report: '+lStream.ReadString(lStream.Size); finally lHTTP.Free; lStream.Free; end; end; procedure TestMercatorConverters; begin {function GetLongToMercProjection(const long:extended):extended; function GetLatToMercProjection(const Lat:Extended):Extended; function GetMercProjectionToLong(const ProjLong:extended):extended; function GetMercProjectionToLat(const ProjLat:extended):extended;} writeln('GetLongToMercProjection: '+floattostr(GetLongToMercProjection(014.14388))); writeln('GetLatToMercProjection: '+floattostr(GetLatToMercProjection(46.62832))); end; var jsonstr, att: string; Begin {@main} //writeln('Coord is: '+GetGeoCode('xml',ExePath+'outputmap2cologne.xml', 'cathedral cologne', true)); // function CoordinateStr2(Idx: Integer; PosInSec: Double; PosLn: TPos): string; writeln(CoordinateStr(2, 50.56, tlat)); //ShellExecute3('http://maps.google.com/maps?q=+50.94133705,+6.95812076100766','',seCMDOPen) TestMercatorConverters; if isInternet then begin writeln(GetGeoInfo4('178.196.192.131', UrlGeoLookupInfo3)); //writeln(GetGeoInfo4(getIp(gethostname), UrlGeoLookupInfo3)); //writeln(GetGeoWeather('krumpendorf', UrlWeatherReport25)); //writeln(GetGeoWeather('koeln', UrlWeatherReport25)); writeln(GetGeoWeather('bern', UrlWeatherReport25)); writeln('') writeln(GetGeoWeather('klagenfurt', UrlWeatherReport25)); writeln('') sr:= GetGeoWeather('kiruna', UrlWeatherReport25); writeln(sr); writeln(' ') with TRegExpr.Create do try Expression:= weatherREX; if Exec(sr) then PrintF('Weather REXTemp live: %s in %s of %s pressure with %s humidity', [Match[1],Match[4],Match[2],Match[3]+'%']); finally Free; end; { writeln('temp live: '+copy(sr,pos('"temp"',sr)+7,5)) it:= pos('"temp"',sr) writeln(sr[it+7]+sr[it+8]+sr[it+9]+sr[it+10]+sr[it+11]) att:= copy(sr,pos('"temp"',sr)+7,5) writeln(inttostr(strtoint(copy(att,0,2)))); //25; } end; //if isinternet jsonstr:= 'GEO_Weather_Report: {"coord":{"lon":14.16,"lat":46.62},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"base":"cmc stations","main":{"temp":19.93,"pressure":1009,"humidity":64,"temp_min":17,"temp_max":21.67},"wind":{"speed":2.6,"deg":200},"rain":{"1h":1.17},"clouds":{"all":75},"dt":1439818945,"sys":{"type":1,"id":5931,"message":0.0042,"country":"AT","sunrise":1439784246,"sunset":1439834986},"id":2771894,"name":"Maria Worth","cod":200}' //writeln('temp: '+copy(jsonstr,pos('"temp"',jsonstr)+7,5)) writeln(' ') maXcalcF('log(4) / log(2.512)') // 8/20/2015 4:34:32 AM //8/20/2015 6:31:27 PM {writeln(datetimetostr(UnixToDateTime(1440045272))); writeln(datetimetostr(UnixToDateTime(1440095487))); writeln(datetimetostr(UnixToDateTime(1440105134))); writeln(datetimetostr(UnixDateTimeToDelphiDateTime(1440045272))) writeln(datetimetostr(UnixDateTimeToDelphiDateTime(1440095487))) if isinternet then writeln(GetGeoWeather('kiruna', UrlWeatherReport25)); } { with TIDTunnelMaster.create(self) do begin mappedport:= 80; bindings.add; //close free; end; with TIDTunnelSlave.create(self) do begin masterport:= 80; bindings.add; //close socks4:= false; free; end; with TIDmappedportTCP.create(self) do begin mappedhost:= ''; //free active:= false; end; } End. // GeoCode doc: How to use API key in API call Description: To get access to weather API you need an API key whatever account you chose from Free to Enterprise. We keep right to not to process API requests without API key. API call: http://api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID={APIKEY} Parameters: APPID {APIKEY} is your unique API key Example of API call: api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID=1111111111 Invalid API key. Please see http://openweathermap.org/faq#error401 for more info. Q: API calls return an error 401 A: Starting from 9 October 2015 our API requires a valid APPID for access. Note that this does not mean that our API is subscription-only now - please take a minute to register a free account to receive a key. We are sorry for inconvenience but this is a necessary measure that will help us deliver our services to you faster and more reliably. ref: x = log(4) / log(2.512) = 1.505 mag , in other words: Garmin Ref: Krumpendorf 045: N 46.62832 - E 014.14388 GeoCode Coord2 is: latitude: '46.622273' longitude: '14.2222166' - cathedral cologne result Coord is: latitude: '50.94133705' longitude: '6.95812076100766' >>> 50°56'28.8"N 6°57'29.2"E http://maps.google.com/maps?q=+50.94133705,+6.95812076100766 >>> https://www.google.com/maps/place/50%C2%B056%2728.8%22N+6%C2%B057%2729.2%22E/@50.9413371,6.9581208,17z/data=!3m1!4b1!4m2!3m1!1s0x0:0x0 church cologne: result Coord is: latitude: '50.9636172' longitude: '7.0031056' Please help. I only need the coordinates from this string "Latitude: +51.703155 N, Longitude: +5.250327 E http://maps.google.com/maps?q=+51.703155,+5.250327 Sent from my android" result +51.703155, +5.250327 if no internet: Exception: Socket Error # 11004 ref: http://useruploadedfiles.programmersheaven.com/48584/NMEA.pas doc: REST (REpresentational State Transfer) is a simple stateless architecture that generally runs over HTTPS/TLS. The REST style emphasizes that interactions between clients and services are enhanced by having a limited number of operations. Flexibility is provided by assigning resources their own unique universal resource indicators (URIs). A sample query string follows: http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?listLatLon=38.99,-77.02 39.70,-104.80 47.6,-122.30&product=time-series&begin=2004-01-01T00:00:00&end=2013-04-20T00:00:00&Unit=e&maxt=maxt&mint=mint The NDFD data available via the REST service is updated no more than hourly. As a result, we request developers using this REST service only make a request for a specific point no more than once an hour. The database is currently updated by 45 minutes after the hour. You can interact with the REST service by visiting the following URLs: RestFul Web Services Weather Forecast The RestFul Web Services Weather Forecast API provides the weather forecast for a given location, specified by name. This service can be accessed using either REST or SOAP calls in XML format. Both types of calls are aimed at WSDL endpoints. Access current weather data for any location on Earth including over 200,000 cities! Current weather is frequently updated based on global models and data from more than 40,000 weather stations. Data is available in JSON, XML, or HTML format. Call current weather data for one location By city name Description: You can call by city name or city name and country code. API responds with a list of results that match a searching word. API call: api.openweathermap.org/data/2.5/weather?q={city name} api.openweathermap.org/data/2.5/weather?q={city name},{country code} Parameters: q city name and country code divided by comma, use ISO 3166 country codes Examples of API calls: api.openweathermap.org/data/2.5/weather?q=London api.openweathermap.org/data/2.5/weather?q=London,uk Program SpammersAreParasites; var l1,l2: Srting; begin l1:='70'; l2:='0'; Bxo:=l1 + l2; Bxo:=(Bxo) (* l1:=97; l2:=9 Bxo:=(l1 + l2); *) end. ? Value of Bxo: GEO_IP Out: Country: SWITZERLAND (CH) City: Bern Latitude: 46.9167 Longitude: 7.4667 IP: 178.196.192.131 GEO_Weather_Report: {"coord":{"lon":7.45,"lat":46.95},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":19.27,"pressure":1014,"humidity":68,"temp_min":15.56,"temp_max":23.89},"wind":{"speed":1.5,"deg":20.506},"clouds":{"all":75},"dt":1439805254,"sys":{"type":1,"id":6013,"message":0.0048,"country":"CH","sunrise":1439785803,"sunset":1439836653},"id":2661552,"name":"Bern","cod":200}  mX3 executed: 17.08.2015 12:07:08 Runtime: 0:0:11.370 Memload: 78% use https://www.academia.edu/14979785/Tutor_40_REST_API_Coding https://www.scribd.com/doc/274846387/maXbox-Starter-40-REST-API-Coding N 0.0140 GetLongToMercProjection: 14.14388 GetLatToMercProjection: 52.8354560030937 GEO_IP Out: Country: SWITZERLAND (CH) City: Bern Latitude: 46.9167 Longitude: 7.4667 IP: 178.196.192.131 GEO_Weather_Report: {"coord":{"lon":7.45,"lat":46.95},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":20.39,"pressure":1013,"humidity":52,"temp_min":19,"temp_max":23.89},"wind":{"speed":1.5,"deg":40},"clouds":{"all":90},"dt":1439820678,"sys":{"type":1,"id":6013,"message":0.0046,"country":"CH","sunrise":1439785816,"sunset":1439836634},"id":2661552,"name":"Bern","cod":200} GEO_Weather_Report: {"coord":{"lon":14.16,"lat":46.62},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"base":"cmc stations","main":{"temp":19.93,"pressure":1009,"humidity":64,"temp_min":17,"temp_max":21.67},"wind":{"speed":2.6,"deg":200},"rain":{"1h":1.17},"clouds":{"all":75},"dt":1439818945,"sys":{"type":1,"id":5931,"message":0.0042,"country":"AT","sunrise":1439784246,"sunset":1439834986},"id":2771894,"name":"Maria Worth","cod":200} 19.93 https://www.academia.edu/14988582/Tutor_40_REST_API_Coding 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 9783897212466 https://hermes.bfh.ch/owa/?ae=Item&t=IPM.Note&id=RgAAAAAAfzJ37DNuRJflsOsOVoB%2fBwCteBIq18BbS5Nuutf0lzjAAAADHWN%2bAAAK6RssP0AgTajWL4YzGfZsAENMtl0kAAAJ# http://entwickler-konferenz.de/2015/de/speakers/max-kleiner $content = Sys_GetURLContent("http://api.openweathermap.org/data/2.5/forecast/daily?id=2850235&lang=de&mode=json"); $json = json_decode($content); $tag = 1; // Morgen, Übermorgen > 2 usw. if(!isset($json->list[$tag]->rain)){ $wert = 0; }else{ $wert = $json->list[$tag]->rain; } „OpenWeatherMap ist ein Onlineservice, der eine frei nutzbare Programmierschnittstelle (API) für Wetterdaten, Wettervorhersagen, sowie historische Wetterdaten für die Entwickler von Webanwendungen und mobilen Geräten bereitstellt. OpenWeatherMap stellt eine freie API für den Zugriff auf freie Wetterdaten, Wettervorhersagen, sowie Wetterkarten mit Informationen über Wolken, Windgeschwindigkeiten und Luftdruck zur Verfügung. Alle Wetterdaten können im JSON, XML oder HTML Format bezogen werden.“ Quelle: Wikipedia Alle Informationen können im JSON-Format angefordert werden. Dieses Interface ist bereits entwickelt. Wetterstationen mit dem letzten Informationen Städte mit dem aktuellen Wetter Werdegang der Messungen von den einzelnen Stationen Wenn Daten von dieser Website genutzt werden müssen die Bestimmungen der CC-BY-SA Lizenz akzeptiert werden Unix-Timestamp Rechner Mit diesem Zeitrechner können Sie einen Unix-Timestamp in ein normales Datum umrechnen. Und umgekehrt ein normales Datum in einen Unix-Timestamp. Dies gilt für alle Zeiten nach dem 01.01.1970 bis zum 19.01.2038. Was ist ein Unix Timestamp? Der Unix-Timestamp gibt die Anzahl der Sekunden an, die seit dem 01.01.1970 vergangen sind. Zeitangaben in diesem Format werden z.B. bei der Programmierung von PHP und MySQL-Datenbanken benötigt. https://www.aritso.net/mehr-informationen/tools/timestampconverter.htm © von aritso.net echo $wert; Das folgende Beispiel soll als Anregung die eigene Anwendung dienen. In ihm wird die zu erwartende Regenmenge von morgen ermittelt. So kann z.B. entschieden werden, ob es Sinn macht heute den Rasen zu bewässern. Besitzer von Solaranlagen oder Wärmepumpen können mit Hilfe einer Temperaturvorhersage ihr Energiemanagement optimieren. Dabei ist zu beachten, dass die Temperatur in Kelvin angegeben wird – es muss also -273.15 abgezogen werden. Ferner lässt die Beschattung eines Gebäudes optimieren, wenn die zu erwartende Sonnenscheindauer und Höchsttemperatur vorher bekannt sind. In der API muss nur noch lediglich der eigene Standort / ID verändert werden. GEO_Weather_Report: {"coord":{"lon":7.45,"lat":46.95},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"base":"stations","main":{"temp":15.01,"pressure":1025,"humidity":93,"temp_min":13.33,"temp_max":16.11},"visibility":10000,"wind":{"speed":1.5,"deg":100},"clouds":{"all":40},"dt":1440104409,"sys":{"type":1,"id":6013,"message":0.0511,"country":"CH","sunrise":1440045272,"sunset":1440095487},"id":2661552,"name":"Bern","cod":200} get at 2015.08.20 22:58 Wind 1.5 m/s East (100 ) Cloudiness scattered clouds Pressure 1025 hpa Humidity 93 % Sunrise 6:34 Sunset 20:35 Geo coords [ 7.45, 46.95 ] Der Timestamp 1440105134 entspricht dem 20.08.2015 um 23:12:14 Uhr. (gilt für UTC+1