;
; ------------------------------------------------------------
; Парсинг XML кода возвращаемого с ресурса Gismeteo.ru
;
;
; (c) 2009 - kvitaliy
;
; ------------------------------------------------------------
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Text_0
#Image_1
#Text_2
#Text_3
#Text_4
#Text_5
#Text_6
#Text_7
#Text_8
#ComboBox_0
#ButtonImage_1
#ButtonImage_2
#ButtonImage_3
EndEnumeration
;}
UsePNGImageDecoder()
#XML = 0
Global Sity$
Global SityNew$
Global N=0
Global G=1
Global Dim DataDay.s(4)
Global Dim cloudiness.s(4)
Global Dim precipitation.s(4)
Global Dim rpower.s(4)
Global Dim spower.s(4)
Global Dim PRESSUREmin.s(4)
Global Dim PRESSUREmax.s(4)
Global Dim TEMPERATUREmin.s(4)
Global Dim TEMPERATUREmax.s(4)
Global Dim HEATmin.s(4)
Global Dim HEATmax.s(4)
Global Dim WINDmin.s(4)
Global Dim WINDmax.s(4)
Global Dim RELWETmin.s(4)
Global Dim RELWETmax.s(4)
Global Dim direction.s(4)
;{ Fonts
Enumeration
#Font_Text_0
#Font_Text_6
#Font_Text_8
EndEnumeration
;}
;{ Images
Enumeration
#Image_Image_1
#Image_ButtonImage_1
#Image_ButtonImage_2
#Image_ButtonImage_3
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure GisMet_XML_Data(*CurrentNode, CurrentSublevel)
If XMLNodeType(*CurrentNode) = #PB_XML_Normal
If GetXMLNodeName(*CurrentNode) = "FORECAST": N+1:EndIf
If ExamineXMLAttributes(*CurrentNode)
While NextXMLAttribute(*CurrentNode)
Select XMLAttributeName(*CurrentNode)
Case "sname"
Sity$=XMLAttributeValue(*CurrentNode)
Case "day"
day$=XMLAttributeValue(*CurrentNode)
Case "month"
month$=XMLAttributeValue(*CurrentNode)
Case "year"
year$=XMLAttributeValue(*CurrentNode)
Case "hour"
hour$=XMLAttributeValue(*CurrentNode)
Case "weekday"
Select XMLAttributeValue(*CurrentNode)
Case "1"
weekday$= "в воскресенье"
Case "2"
weekday$= "в понедельник"
Case "3"
weekday$= "во вторник"
Case "4"
weekday$= "в среду"
Case "5"
weekday$= "в четверг"
Case "6"
weekday$= "в пятницу"
Case "7"
weekday$= "в субботу"
EndSelect
dataProg$= day$ + "." + month$ +"." + year$+"г., "+weekday$+", на " + hour$
DataDay(N)=dataProg$
Case "cloudiness"; Облачность
Select XMLAttributeValue(*CurrentNode)
Case "0"
cloudiness(N)= "ясно"
Case "1"
cloudiness(N)= "малооблачно"
Case "2"
cloudiness(N)= "облачно"
Case "3"
cloudiness(N)= "пасмурно"
EndSelect
Case "precipitation" ; Осадки
Select XMLAttributeValue(*CurrentNode)
Case "4"
precipitation(N)= "дождь"
Case "5"
precipitation(N)= "ливень"
Case "6","7"
precipitation(N)= "снег"
Case "8"
precipitation(N)= "гроза"
Case "9"
precipitation(N)= "нет данных"
Case "10"
precipitation(N)= "без осадков"
EndSelect
;Debug cloudiness(N) + ", " + precipitation(N)
Case "rpower" ; интенсивность осадков
Select XMLAttributeValue(*CurrentNode)
Case "0"
rpower(N)= "возможен дождь/снег"
Case "1"
rpower(N)= "дождь/снег"
EndSelect
Case "spower" ; вероятность грозы
Select XMLAttributeValue(*CurrentNode)
Case "0"
spower(N)= "возможна гроза"
Case "1"
spower(N)= "гроза"
EndSelect
Case "min"
Select GetXMLNodeName(*CurrentNode)
Case "PRESSURE"
PRESSUREmin(N) = XMLAttributeValue(*CurrentNode)
Case "TEMPERATURE"
TEMPERATUREmin(N) = XMLAttributeValue(*CurrentNode)
Case "HEAT"
HEATmin(N) = XMLAttributeValue(*CurrentNode)
Case "WIND"
WINDmin(N) = XMLAttributeValue(*CurrentNode)
Case "RELWET"
RELWETmin(N) = XMLAttributeValue(*CurrentNode)
EndSelect
Case "max"
Select GetXMLNodeName(*CurrentNode)
Case "PRESSURE"
PRESSUREmax(N) = XMLAttributeValue(*CurrentNode)
Case "TEMPERATURE"
TEMPERATUREmax(N) = XMLAttributeValue(*CurrentNode)
Case "HEAT"
HEATmax(N) = XMLAttributeValue(*CurrentNode)
Case "WIND"
WINDmax(N) = XMLAttributeValue(*CurrentNode)
Case "RELWET"
RELWETmax(N) = XMLAttributeValue(*CurrentNode)
EndSelect
Case "direction"
Select XMLAttributeValue(*CurrentNode)
Case "0"
direction(N) = "северный"
Case "1"
direction(N) = "северо-восточный"
Case "2"
direction(N) = "восточный"
Case "3"
direction(N) = "юго-восточный"
Case "4"
direction(N) = "южный"
Case "5"
direction(N) = "юго-западный"
Case "6"
direction(N) = "западный"
Case "7"
direction(N) = "северо-западный"
EndSelect
EndSelect
Wend
EndIf
;
*ChildNode = ChildXMLNode(*CurrentNode)
While *ChildNode <> 0
GisMet_XML_Data(*ChildNode, CurrentSublevel+1)
*ChildNode = NextXMLNode(*ChildNode)
Wend
EndIf
EndProcedure
;Procedure FileGis(Ind.i)
; If CreateFile(1, "Прогноз.txt") ; we create a new text file...
;
; WriteStringN(1, "В городе " + URLDecoder(Sity$)+" "+ DataDay(Ind)+ "прогнозируется:")
; WriteStringN(1, "давление " + PRESSUREmin(Ind) + "-"+ PRESSUREmax(Ind) +" мм.рт.ст.,")
; WriteStringN(1, "ветер "+direction(Ind)+","+" "+WINDmin(Ind)+"-"+WINDmax(Ind) +"m\c,")
; WriteStringN(1, "относительная влажность воздуха " + RELWETmin(Ind) + "-"+ RELWETmax(Ind) +" %")
; WriteStringN(1, "температура "+TEMPERATUREmin(Ind)+"-"+ TEMPERATUREmax(Ind) +"°C, " + cloudiness(Ind) + ", " + precipitation(Ind))
; WriteStringN(1, "комфортность " + HEATmin(Ind)+"-"+ HEATmax(Ind) +"°C")
;
; CloseFile(1) ; close the previously opened file and store the written data this way
; Else
; MessageRequester("Информация","Невозможно создать файл!", #PB_MessageRequester_Ok)
; EndIf
;EndProcedure
Procedure ShowGis(Ind.i)
;- вывод на печать
; Debug "Комфортность: " + HEATmin(i)+"-"+ HEATmax(i) +"°C"
SetGadgetText(#Text_0,URLDecoder(Sity$))
SetGadgetText(#Text_2,"Давление: " + PRESSUREmin(Ind) + "..."+ PRESSUREmax(Ind) +" мм.рт.ст.")
SetGadgetText(#Text_3,"Ветер "+direction(Ind))
SetGadgetText(#Text_4,WINDmin(Ind)+"..."+WINDmax(Ind) +"m\c")
SetGadgetText(#Text_5,"Влажность: " + RELWETmin(Ind) + "..."+ RELWETmax(Ind) +" %")
SetGadgetText(#Text_6,TEMPERATUREmin(Ind)+"..."+ TEMPERATUREmax(Ind) +"°C")
SetGadgetText(#Text_8,DataDay(Ind))
SetGadgetText(#Text_7,cloudiness(Ind) + ", " + precipitation(Ind))
SetGadgetText(38, "В городе " + URLDecoder(Sity$)+" "+ DataDay(Ind)+ "ч. прогнозируется:" + #CRLF$ + "давление " + PRESSUREmin(Ind) + "-"+ PRESSUREmax(Ind) +" мм.рт.ст.," + #CRLF$ + "ветер "+direction(Ind)+","+" "+WINDmin(Ind)+"-"+WINDmax(Ind) +" m\c,"+ #CRLF$ +"относительная влажность" + #CRLF$ + "воздуха " + RELWETmin(Ind) + "-"+ RELWETmax(Ind) +" %"+ #CRLF$ +"температура "+TEMPERATUREmin(Ind)+"-"+ TEMPERATUREmax(Ind) +"°C, "+ #CRLF$ + cloudiness(Ind) + ", " + precipitation(Ind) )
Select precipitation(Ind)
Case "без осадков"
Select cloudiness(Ind)
Case "ясно":
LoadImage(0, "Pogoda\pogoda20.png")
Case "малооблачно":
LoadImage(0, "Pogoda\pogoda9.png")
Case "облачно":
LoadImage(0, "Pogoda\pogoda2.png")
Case "пасмурно":
LoadImage(0, "Pogoda\pogoda24.png")
EndSelect
Case "дождь"
LoadImage(0, "Pogoda\pogoda14.png")
Case "ливень"
LoadImage(0, "Pogoda\pogoda13.png")
Case "снег"
LoadImage(0, "Pogoda\pogoda19.png")
Case "гроза"
LoadImage(0, "Pogoda\pogoda23.png")
EndSelect
;SetGadgetState(#Image_1, ImageID(0))
EndProcedure
Procedure.l DownloadToMem ( URL.s, *lpRam, ramsize.l )
Protected agent.s, hInet.l, hData.l, Bytes.l
agent.s = "IE 6.0"
hInet.l = InternetOpen_ ( @agent.s,0,0,0,0 )
hData.l = InternetOpenUrl_ ( hInet, @URL.s, "", 0, $8000000, 0 )
If hData > 0 : InternetReadFile_ ( hData, *lpRam, ramsize.l, @Bytes.l ) : Else : Bytes = -1 : EndIf
InternetCloseHandle_ (hInet)
InternetCloseHandle_ (hFile)
InternetCloseHandle_ (hData)
ProcedureReturn Bytes.l
EndProcedure
InitNetwork()
SityNew$="27612"; "29838"; - Барнаул
If OpenWindow(#Window_0, 436, 47, 600, 400, "Прогноз погоды на сутки", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
TextGadget(#Text_0, 40, 5, 250, 30, "", #PB_Text_Center)
ImageGadget(#Image_1, 5, 95, 155, 160, 0)
TextGadget(#Text_2, 190, 210, 200, 25, "Давление", #PB_Text_Center)
TextGadget(#Text_3, 185, 105, 200, 25, "направление ветра", #PB_Text_Center)
TextGadget(#Text_4, 185, 135, 200, 25, "Скорость", #PB_Text_Center)
TextGadget(#Text_5, 185, 165, 200, 25, "Влажность", #PB_Text_Center)
TextGadget(#Text_6, 85, 265, 210, 50, "Температура", #PB_Text_Center)
TextGadget(#Text_7, 85, 315, 210, 50, "атмосфера", #PB_Text_Center)
TextGadget(#Text_8, 5, 40, 250, 30, "число", #PB_Text_Center)
ComboBoxGadget(#ComboBox_0, 85, 370, 210, 20): HideGadget(#ComboBox_0,1)
ButtonImageGadget(#ButtonImage_1, 10, 360, 45, 30, CatchImage(#Image_ButtonImage_1, ?Image_ButtonImage_1))
ButtonImageGadget(#ButtonImage_2, 340, 360, 45, 30, CatchImage(#Image_ButtonImage_2, ?Image_ButtonImage_2))
ButtonImageGadget(#ButtonImage_3, 360, 10, 35, 35, CatchImage(#Image_ButtonImage_3, ?Image_ButtonImage_3))
; Gadget Fonts
SetGadgetFont(#Text_0, LoadFont(#Font_Text_0, "Microsoft Sans Serif", 14, 272))
SetGadgetFont(#Text_6, LoadFont(#Font_Text_6, "Microsoft Sans Serif", 20, 272))
SetGadgetFont(#Text_8, LoadFont(#Font_Text_8, "Microsoft Sans Serif", 12, 784))
SetGadgetFont(#Text_7, LoadFont(#Font_Text_8, "Microsoft Sans Serif", 12, 784))
GadgetToolTip(#ButtonImage_1, "Обновить данные")
GadgetToolTip(#ButtonImage_2, "Дальше...")
GadgetToolTip(#ButtonImage_3, "Найти другой город")
EditorGadget(38,400,7,163,90,#PB_Editor_ReadOnly)
EndIf
If ReadFile(0, "GismeteoCodSity.txt")
While Eof(0) = 0
AddGadgetItem(#ComboBox_0, -1,ReadString(0))
Wend
CloseFile(0)
Else
MessageRequester("Information","Нет файла - справочника")
EndIf
*Mem_XML = AllocateMemory(100000)
newSity:
;Filename$ = "gis.xml";
FillMemory(*Mem_XML, 100000, 0)
Bytes=DownloadToMem ("http://informer.gismeteo.ru/xml/"+SityNew$+"_1.xml", *Mem_XML, 100000)
If Bytes>0 ;ReceiveHTTPFile("http://informer.gismeteo.ru/xml/"+SityNew$+"_1.xml", Filename$)
;Debug "Прогноз загружен"
;If FileSize(FileName$) > 0
If CatchXML(#XML,*Mem_XML,Bytes) ;LoadXML(#XML, FileName$)
If XMLStatus(#XML) <> #PB_XML_Success
Message$ = "Error in the XML file:" + Chr(13)
Message$ + "Message: " + XMLError(#XML) + Chr(13)
Message$ + "Line: " + Str(XMLErrorLine(#XML)) + " Character: " + Str(XMLErrorPosition(#XML))
MessageRequester("Error", Message$)
EndIf
*MainNode = MainXMLNode(#XML)
If *MainNode
GisMet_XML_Data(*MainNode, 0)
EndIf
ShowGis(1)
;FileGis(1)
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Text_0
ElseIf EventGadget = #ButtonImage_3
HideGadget(#ComboBox_0,0)
ElseIf EventGadget = #ComboBox_0
SityNew$= Left(GetGadgetText(#ComboBox_0), 5)
If Len(SityNew$)
HideGadget(#ComboBox_0,1)
N=0
FakeReturn
Goto newSity
EndIf
ElseIf EventGadget = #ButtonImage_1
N=0
FakeReturn
Goto newSity
ElseIf EventGadget = #ButtonImage_2
If G<=3
G+1
ShowGis(G)
;FileGis(G)
Else
G=1
ShowGis(G)
;FileGis(G)
EndIf
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
Else
MessageRequester("Error", "The file cannot be opened.")
EndIf
;EndIf
Else
;Debug "Не загружен"
MessageRequester("Information","Нет возможности загрузить данные из Интернет!")
EndIf
;{ Included Images
DataSection
Image_ButtonImage_1:
IncludeBinary "Pogoda\refresh.ico"
Image_ButtonImage_2:
IncludeBinary "Pogoda\right.ico"
Image_ButtonImage_3:
IncludeBinary "Pogoda\0031 - Start Find.ico"
EndDataSection
;}
;}