Hab jetzt mal mein Wetter Script fertiggestellt ( ich weiß, man kann viel verbessern und es hat keine Bilder, aber egal) :
Spoiler anzeigen
; Globale Variablen und Einstellungen
Global $windtype
Global $oGUI
Global $state
Global $city
Global $trans
Global $nwp
Global $wp
If IniRead("data", "Main", "weatherpage", "google")="Google Weather" Then $wp="Google Weather"
If IniRead("data", "Main", "weatherpage", "google")="Accu Weather" Then $wp="Accu Weather"
Opt("GUIOnEventMode", "1")
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)
$opt=TrayCreateItem("Optionen")
TrayItemSetOnEvent(-1, "options")
TrayCreateItem("")
$about=TrayCreateItem("Über")
TrayItemSetOnEvent(-1, "about")
;==> Globale Variablen und Einstellungen
; Haupt GUI
GUICreate("Wetter", 295, 219, 189, 132)
GUISetOnEvent(-3, "_exit")
$type = GUICtrlCreateLabel("", 8, 16, 188, 18)
$Temperatur = GUICtrlCreateLabel("Temperatur:", 8, 80, 115, 17)
$gtemperatur = GUICtrlCreateLabel("Gefühlte Temperatur:", 8, 112, 290, 17)
$luftfeuchtigkeit = GUICtrlCreateLabel("Luftfeuchtigkeit:", 8, 144, 118, 17)
$wind = GUICtrlCreateLabel("Wind:", 8, 176, 160, 17)
$currentcity=GUICtrlCreateLabel("Aktuelle Stadt: "&IniRead("data", "Main", "city", "Berlin"), 8, 48, 103, 17)
$hMenu=GUICtrlCreateMenu("Menü")
GUICtrlCreateMenuItem("Optionen", $hMenu)
GUICtrlSetOnEvent(-1, "options")
GUICtrlCreateMenuItem("Über", $hMenu)
GUICtrlSetOnEvent(-1, "about")
WinSetTrans("Wetter", "", IniRead("data", "Other", "Trans", "255"))
GUISetState(@SW_SHOW)
; ==> Haupt GUI
update()
AdlibRegister('update', '30000')
While sleep(500)
WEnd
; Eigene Funktionen
Func update()
If $wp="Accu Weather" Then
$source=_INetGetSource('http://www.accuweather.com/de/EUR/DE/GM'&IniRead("data", "Main", "state", "003")&'/'&IniRead("data", "Main", "city", "Berlin")&'/quick-look.aspx')
$ntype=_StringBetween($source, '<span id="ctl00_cphContent_lblCurrentText" style="display: block; font-size: 11px;line-height: 17px;">', "</span>")
If not IsArray($ntype) Then
MsgBox(0, "Fehler", "Die angegebene Stadt wurde nicht gefunden")
options()
Return
EndIf
GUICtrlSetData($type, $ntype[0])
$ntemperatur=_StringBetween($source, '<span id="ctl00_cphContent_lblCurrentTemp" style="display: block; font-weight: bold;font-size: 18px; line-height: 24px;">', '°')
$ntemperatur[0]-=32
$ntemperatur[0]/=1.8
GUICtrlSetData($Temperatur, "Temperatur: "&Round($ntemperatur[0])&" °C")
$ngtemperatur=_StringBetween($source, 'display: block;">', '°')
$ngtemperatur[0]=StringRight($ngtemperatur[0], 2)
$ngtemperatur[0]-=32
$ngtemperatur[0]/=1.8
GUICtrlSetData($gtemperatur, "Gefühlte Temperatur: "&Round($ngtemperatur[0])&" °C")
$nluftfeuchtigkeit=_StringBetween($source, 'display: block;"', '%')
$nluftfeuchtigkeit[0]=StringRight($nluftfeuchtigkeit[0], 2)
GUICtrlSetData($luftfeuchtigkeit, "Luftfeuchtigkeit: "&$nluftfeuchtigkeit[0]&" %")
$nwind=_StringBetween($source, '<span id="ctl00_cphContent_lblWindsValue" style="width: 80px; float: right; display: block;">', '</span>')
If StringLen($nwind[0])=7 Then
$windtype=StringLeft($nwind[0], 1)
$nwind[0]=StringTrimLeft($nwind[0], 1)
ElseIf StringLen($nwind[0])=8 Then
$windtype=StringLeft($nwind[0], 2)
$nwind[0]=StringTrimLeft($nwind[0], 2)
ElseIf StringLen($nwind[0])=9 Then
$windtype=StringLeft($nwind[0], 3)
$nwind[0]=StringTrimLeft($nwind[0], 3)
EndIf
$nwind[0]=StringTrimRight($nwind[0], 3)
$nwind[0]*=1.609344
If StringRegExp($windtype, "E")=1 Then $windtype=StringRegExpReplace($windtype, "E", "O")
GUICtrlSetData($wind, "Wind: "&$windtype&" "&Round($nwind[0])&" km/h")
Else
$source=_INetGetSource('http://www.google.com/ig/api?weather='&IniRead("data", "Main", "city", "Berlin")&'&hl=de')
$ntype=_StringBetween($source, '<condition data="', '"')
GUICtrlSetData($type, $ntype[1])
$ntemperatur=_StringBetween($source, '<temp_c data="', '"')
GUICtrlSetData($Temperatur, "Temperatur: "&$ntemperatur[0]&" °C")
GUICtrlSetData($gtemperatur, "Gefühlte Temperatur: Nicht bei Google Weather vorhanden.")
$nluftfeuchtigkeit=_StringBetween($source, '<humidity data="Feuchtigkeit: ', '"')
GUICtrlSetData($luftfeuchtigkeit, "Luftfeuchtigkeit: "&$nluftfeuchtigkeit[0])
$nwind=_StringBetween($source, '<wind_condition data="Wind: ', '"')
$nwind[0]=StringRegExpReplace($nwind[0], "mit", "")
GUICtrlSetData($wind, "Wind: "&$windtype&" "&$nwind[0])
EndIf
EndFunc
Func _exit()
Exit
EndFunc
Func options()
TrayItemSetState($opt, 4)
$oGUI = GUICreate("Optionen", 205, 198, 192, 124)
GUISetOnEvent(-3, "close")
GUICtrlCreateLabel("Bundesland: ", 8, 8, 100, 17)
$state = GUICtrlCreateInput("", 70, 6, 121, 21)
GUICtrlCreateLabel("Stadt: ", 8, 48, 27, 17)
$city = GUICtrlCreateInput("", 70, 46, 121, 21)
GUICtrlCreateLabel("Sichtbarkeit:", 8, 88, 60, 17)
$trans = GUICtrlCreateSlider(72, 80, 126, 45)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetData(-1, IniRead("data", "Other", "trans", "0"))
$nwp = GUICtrlCreateCombo(IniRead("data", "Main", "weatherpage", "Accu Weather"), 112, 136, 89, 25)
GUICtrlSetData(-1, "Accu Weather | Google Weather")
GUICtrlCreateLabel("Wetterinformationen", 8, 136, 99, 17)
GUICtrlCreateButton("Änderungen speichern", 44, 168, 120, 25)
GUICtrlSetOnEvent(-1, "save")
GUISetState(@SW_SHOW)
EndFunc
Func close()
GUIDelete($oGUI)
EndFunc
Func save()
$state=GUICtrlRead($state)
If $state="Baden-Württemberg" Then $nstate="001"
If $state="Baden Württemberg" Then $nstate="001"
If $state="Bayern" Then $nstate="002"
If $state="Berlin" Then $nstate="003"
If $state="Brandenburg" Then $nstate="004"
If $state="Bremen" Then $nstate="005"
If $state="Hamburg" Then $nstate="006"
If $state="Hessen" Then $nstate="007"
If $state="Niedersachsen" Then $nstate="009"
If $state="Mecklenburg-Vorpommern" Then $nstate="010"
If $state="Mecklenburg Vorpommern" Then $nstate="010"
If $state="Nordrhein-Westfalen" Then $nstate="011"
If $state="Nordrhein Westfalen" Then $nstate="011"
If $state="Rheinland-Pfalz" Then $nstate="012"
If $state="Rheinland Pfalz" Then $nstate="012"
If $state="Saarland" Then $nstate="013"
If $state="Sachsen" Then $nstate="014"
If $state="Sachsen-Anhalt" Then $nstate="015"
If $state="Sachsen Anhalt" Then $nstate="015"
If $state="Schleswig-Holstein" Then $nstate="016"
If $state="Schleswig Holstein" Then $nstate="016"
If $state="Thüringen" Then $nstate="017"
$city=GUICtrlRead($city)
$trans=GUICtrlRead($trans)
$nwp=GUICtrlRead($nwp)
If $nstate<>IniRead("data", "Main", "state", "")And $nstate<>"" Then IniWrite("data", "Main", "state", $nstate)
If $city<>"" Then IniWrite("data", "Main", "city", $city)
If $trans<>IniRead("data", "Other", "trans", "") Then IniWrite("data", "Other", "trans", $trans)
If $nwp<>"" Then IniWrite("data", "Main", "weatherpage", $nwp)
GUIDelete($oGUI)
WinSetTrans("Wetter", "", IniRead("data", "Other", "trans", "255"))
GUICtrlSetData($currentcity, "Aktuelle Stadt:"&$city)
update()
EndFunc
Func about()
TrayItemSetState($about, 4)
MsgBox(0, "Über", "Code: Jan Timon"&@CRLF&"Wetterdaten: http://www.accuweather.com | http://www.google.com/ig/api?weather")
EndFunc ;==>Eigene Funktionen
; Funktionen aus UDF's
Func _INetGetSource($s_URL, $bString = True)
Local $sString = InetRead($s_URL, 1)
Local $nError = @error, $nExtended = @extended
If $bString Then $sString = BinaryToString($sString)
Return SetError($nError, $nExtended, $sString)
EndFunc
Func _StringBetween($s_String, $s_Start, $s_End, $v_If = -1)
; Set If type
Local $s_If = ""
If $v_If = Default Or $v_If = -1 Then $s_If = "(?i)"
; Escape characters
Local $s_pattern_escape = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
$s_Start = StringRegExpReplace($s_Start, $s_pattern_escape, "\\$1")
$s_End = StringRegExpReplace($s_End, $s_pattern_escape, "\\$1")
; If you want data from beginning then replace blank start with beginning of string
If $s_Start = "" Then $s_Start = "\A"
; If you want data from a start to an end then replace blank with end of string
If $s_End = "" Then $s_End = "\z"
Local $a_ret = StringRegExp($s_String, "(?s)" & $s_If & $s_Start & "(.*?)" & $s_End, 3)
[/autoit] [autoit][/autoit] [autoit]If @error Then Return SetError(1, 0, 0)
Return $a_ret
EndFunc ;==>Funktionen aus UDF's
Man kann zwischen zwei Wetterseiten wählen; mit Accu Weather gehen bisher nur Städte aus Deutschland, mit Google Weather sollten alle gehen.
Sollte die Stadt nicht vorhanden sein, wird man in die Optionen GUI weitergeleitet, um eine neue anzugeben.