Upload files to "/"

This commit is contained in:
2026-03-23 09:16:04 +00:00
parent 46478e0acf
commit f7811d4781
5 changed files with 1719 additions and 0 deletions

103
meteoutil.pas Normal file
View File

@@ -0,0 +1,103 @@
unit meteoutil;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, fpjson, jsonparser;
function calcolaprecipitazione (oggettoJSON:TJSONObject; ora:integer):string;
function FormattaAstroLinea(linea:string):string;
function MeseToText(mese:integer):string;
function stringarichiesta(https:boolean; lat, long: double):string;
implementation
function calcolaprecipitazione (oggettoJSON:TJSONObject; ora:integer):string;
var
codice:integer;
precipitazione:string;
begin
codice:=oggettoJSON.FindPath('hourly.weather_code['+inttostr(ora)+']').AsInteger;
case codice of
0: precipitazione:= 'Sereno';
1: precipitazione:= 'Prev. Sereno';
2: precipitazione:= 'Parz. Nuvoloso';
3: precipitazione:= 'Nuvoloso';
45..48: precipitazione:= 'Nebbia';
51..57: precipitazione:= 'Pioviggine';
61..65: precipitazione:= 'Pioggia';
66..67:precipitazione:= 'Grandine';
71..77: precipitazione:= 'Neve';
80..82: precipitazione:= 'Rovesci';
85..86:precipitazione:= 'Neve';
95..99:precipitazione:= 'Temporale';
end;
result:=precipitazione;
end;
function FormattaAstroLinea(linea:string):string;
var
mese:string;
begin
mese:=MeseToText(strtoint(copy(linea, 1,2)));
result:=copy(linea, 5, 2)+' '+copy(mese, 1, 3)+' ' +copy(linea, 16);
end;
function MeseToText(mese:integer):string;
begin
case mese of
1: result:='Gennaio';
2: result:='Febbraio';
3: result:='Marzo';
4: result:='Aprile';
5: result:='Maggio';
6: result:='Giugno';
7: result:='Luglio';
8: result:='Agosto';
9: result:='Settembre';
10: result:='Ottobre';
11: result:='Novembre';
12: result:='Dicembre';
end;
end;
function stringarichiesta(https:boolean; lat, long: double):string;
var
segnaposto:string;
defaultseparator:char;
begin
if https then segnaposto:='https://' else segnaposto:='http://';
defaultseparator:=DefaultFormatSettings.DecimalSeparator;
DefaultFormatSettings.DecimalSeparator:='.'; //fa in modo che venga usato il punto nelle conversioni e non la virgola viene usato il punto e la virgola in base alla provenienza dell'utente di solito
//per la richiesta serve che rappresentiamo con i punti
segnaposto:=segnaposto+'api.open-meteo.com/v1/forecast?latitude='+floattostr(lat)+'&longitude='+floattostr(long)+'&hourly=weather_code,temperature_2m,wind_speed_10m,wind_speed_180m,visibility,cloud_cover';
DefaultFormatSettings.DecimalSeparator:=defaultseparator; //rimette il separatore a quello di default
result:=segnaposto;
end;
end.