ErrorLevel("syntax") # 2010/05/17 (Mon) ネット接続部分修正 # 地域設定ページ変更に伴なうソース修正 SleepTime = 3 selindex[1] = "しない" selindex[2] = "する" Mortexe = systempath("ScriptExe") \ "MortScript.exe" Pollenmscr = systempath("ScriptPath") \ systempath( "ScriptName" ) & systempath( "ScriptExt" ) PollenRunAtT = """" & Pollenmscr & """ RunAtTimer=ON" PollenRunAtA = """" & Pollenmscr & """ RunAtAutoexec=ON" gozen = "Software\5zen\pollen" NotifyApp = "\Program Files\cmdRegistryNotifyApp\cmdRegistryNotifyApp.exe" NotifyAppStop = "\Program Files\cmdRegistryNotifyApp\cmdRegistryStopNotification.exe" ConnectName = split("接続しない,その他,インターネット設定",",") ### URL設定 URL_root = "http://tenki.jp/" URL_pollen = URL_root & "pollen/" ### データフォルダのパス DATA_path = systempath("ScriptPath") \ "Kafun" if(direxists(DATA_path) = 0) mkdir(DATA_path) endif ### テンポラリファイル名 DL_temp = DATA_path \ "Kafun.txt" ### テキスト出力名 Kafunout = DATA_path \ "KafunText.txt" ### レジストリ読み込み # 終了時にToday画面を再描画させるか call("RegstorySet","RDToday",1) # 接続方法 call("RegstorySet","InternetConnect",3) # タイマー call("RegstorySet","Timelag",10) call("RegstorySet","Interval",15) ### タイマー起動 ### if(RunAtTimer eq "ON") # Desktopが表示されている場合、五分後に再実行 if (ActiveWindow() ne "Desktop") call("TimerSet",timestamp() + 5 * 60) exit endif # ネット接続 i = 0 callfunction("NetConnect",i) if(i) # 回線接続できなかった call("TimerSet",timestamp() + Interval * 60) exit else # お天気データダウンロード callfunction("PollenDownload",i) if(i) call("TimerSet",timestamp() + Interval * 60) else call("TimerRoundSet") endif endif # ネット切断 call("NetDisconnect") exit endif ### マニュアル起動 ### if(RunAtManual eq "ON") # 実行問い合わせ if (Question("花粉情報を取得します。",""."YesNo")) # ネット接続 i = 0 callfunction("NetConnect",i) if(i) message("ネット接続できませんでした") else call("PollenDownload") call("NetDisconnect") endif endif exit endif ### 回線接続時の自動起動によるダウンロード ### if(RunAtAutoexec eq "ON") NowTime = (((timestamp() - TimeLag * 60) / 3600) + 1) / 6 NowTime = ((NowTime - ((NowTime mod 4) = 0)) * 6 - 1) * 3600 T_Year = formattime("Y",NowTime) T_Month = formattime("m",NowTime) T_Day = formattime("d",NowTime) T_Hour = formattime("H",NowTime) # 更新確認 if(((regread("HKCU",gozen,"ReleaseYear") = T_Year) and \ (regread("HKCU",gozen,"ReleaseMonth") = T_Month) and \ (regread("HKCU",gozen,"ReleaseDay") = T_Day) and \ (regread("HKCU",gozen,"ReleaseHour") = T_Hour)) = 0) NowTime = timestamp() + 60 while((regread("HKLM","System\State\Connections","Count") = 0) and (NowTime > timestamp())) sleep(1000) endwhile if(regread("HKLM","System\State\Connections","Count") = 0) exit endif for i = 1 to 3 callfunction("PollenDownload",j) if(j) sleep(10000) else i = 3 endif next endif exit endif while(1) ### メニュー選択 ### callfunction("TimerStr",buff) choice("花粉情報","現在の花粉情報は^NL^" & regread("HKCU",gozen,"ReleaseYMDT") & "^NL^のものです", \ "地域選択(" & regread("HKCU",gozen,"SelectArea") & ")" , \ "TodayRedraw      " & selindex[RDToday + 1] , \ "rlTodayを利用" & selindex[rlToday + 1] , \ "各種情報設定" , "" , \ "タイマー設定(" & buff & ")" , \ "その他の設定" , "" , \ "花粉飛沫情報ダウンロード") ## 終了 case(0) exit ## 地域選択 case(1) # ネット接続 i = 0 callfunction("NetConnect",i) if(i) message("ネット接続できませんでした") else for AreaSelect = 1 to 0 switch(AreaSelect) case (1) ### 地域の選択 ### # html読み込み callfunction("DL_html",text,URL_pollen & "index.html",DATA_path \ "kafun_index.txt") save_text = text # 選択した都道府県の選択肢のあるテキストを切り出す callfunction("BetweenStrings",text,text,1,"花粉飛散情報","花粉飛散凡例") callfunction("GetArea",i,text,"abbr=""","""",">","<") if (i) # 選択する i = choice("地方選択","地方を選択してください",1,0,area_dir_name) if(i) DL_Tihou = area_dir_name[i] else # キャンセル AreaSelect = 0 endif else # 切り出し失敗 AreaSelect = 0 endif case ( 0 ) callfunction("BetweenStrings",text,text,1,DL_Tihou,"/ul") # 切り出したテキストから選択肢を作る callfunction("GetArea",i,text,"/pollen/",".html",">","<") area_dir_name[i + 1] = "戻る" # 選択する j = Choice(AreaName ,"花粉飛散状況を知りたい地域を選択してください" ,1 ,0 ,area_dir_name) if((j <= i) && j) # ダウンロードURL設定 regwritestring("HKCU",gozen,"DownloadURL", area_dir[j] & ".html") regwritestring("HKCU",gozen,"SelectArea",area_dir_name[j]) elseif(j) # 戻る AreaSelect = AreaSelect + 2 endif EndSwitch next endif ## Today画面の再描画 case(2) call("RegstoryToggle","RDToday") ## rlTodayの利用 case(3) call("RegstoryToggle","rlToday") ## 各種情報設定 case(4) message("現在未対応です") ## タイマー設定 case(6) i = 1 while(i) callfunction("TimerStr",buff) choice("メニュー選択","メニューを選択してください", \ "タイマーセット(" & buff & ")" , \ "タイマーキャンセル" , \ "タイムラグ(" & Timelag & "分)" , \ "インターバル(" & Interval & "分間隔)") # 終了 case(0) regwritedword("HKCU",gozen,"Timelag",Timelag) regwritedword("HKCU",gozen,"Interval",Interval) i = 0 # タイマーセット case(1) if(question("タイマーをセットしますか?")) call("TimerDelete") callfunction("TimerRoundSet",j) message("初回 " & formattime("y/m/d H:i:s",j) & " にセットしました") endif # タイマーキャンセル case(2) if(question("タイマーをキャンセルしますか?^NL^現在 " & buff)) call("TimerDelete") message("タイマーを削除しました") endif # タイムラグ設定 case(3) j = input("更新時間の何分後にチェックしますか?","タイムラグ",0,0,Timelag) * 1 if(j<0) j = 0 endif if(question(j & "分後でよろしいですか?")) Timelag = j endif # Interval設定 case(4) j = input("更新失敗時何分間隔に再度チェックしますか?","インターバル",0,0,Interval) * 1 if(j<1) j = 1 endif if(question(j & "分間隔でよろしいですか?")) Interval = j endif endchoice endwhile ## その他の設定 case(7) i = 1 while(i) LANautoexec = regkeyexists("HKLM","System\Notifications\Weather.LANautoexec") ASautoexec = regkeyexists("HKLM","System\Notifications\Weather.ASautoexec") choice("お天気情報","各種設定", \ "ネット接続設定(" & ConnectName[InternetConnect] & ")" , \ "LAN接続時に自動更新" & selindex[LANautoexec + 1] , \ "AS開始時に自動更新" & selindex[ASautoexec + 1] ) # "アイコンダウンロード") # キャンセル case(0) i = 0 # 接続設定 case(1) j = choice("花粉情報","インターネット接続名の選択",InternetConnect,0,ConnectName) if(j) InternetConnect = j regwritedword("HKCU",gozen,"InternetConnect",InternetConnect) endif #LAN接続時の自動更新 case(2) if(LANautoexec) runwait(NotifyAppStop,"3;Weather.LANautoexec") else runwait(NotifyApp,"3;Pollen.LANautoexec;HKLM;System\State\Hardware;WiFi;" & Mortexe & ";'" & PollenRunAtA & "';-;-;-1;1;2;16;16;-") endif # AS開始時の自動更新 case(3) if(ASautoexec) runwait(NotifyAppStop,"3;Weather.ASautoexec") else runwait(NotifyApp,"3;Pollen.ASautoexec;HKLM;System\State\Hardware;Cradled;" & Mortexe & ";'" & PollenRunAtA & "';-;-;-1;1;2;-;1;-") endif endchoice endwhile ## 花粉飛散データダウンロード case(9) i = 0 showwaitcursor call("NetConnect", i) if(i) hidewaitcursor message("ネット接続できませんでした") else call("PollenDownload") call("NetDisconnect") hidewaitcursor endif endchoice endwhile exit ### アイコンダウンロード ### sub GIFDownload local ( i,j ) callfunction("PrintQuestion",i,"アイコンデータをダウンロードしますか?(約120kb)") if(i) for i = 1 to 5 j = substr("0" & i,-1) call("ImageDL","http://tenki.jp/images/pollen/icon_middle_" & j & ".jpg",DATA_path \ j & "_m.jpg") call("ImageDL","http://tenki.jp/images/pollen/icon_large_" & j & ".jpg",DATA_path \ j & "_l.jpg") next endif endsub ### ネット接続 ### # out...(ret.) 0...接続している/接続した 1...接続失敗 sub NetConnect WifiNow = regread( "HKLM" , "System\State\Hardware" , "Wifi" ) CellularNow = regread( "HKLM" , "System\State\Connections\Cellular", "Count") AsNow = regread( "HKLM" , "Drivers\USB\FunctionDrivers", "ActiveSyncConnected") ipAddr = regread( "HKLM" , "Comm\Tcpip\Hosts\dtpt_peer" , "ipaddr" ) ipAddrFlg = RegValueExists( "HKLM" , "Comm\Tcpip\Hosts\dtpt_peer", "ipaddr" ) if (CellularNow > 0) return(0) else if((WifiNow = 19) or (WifiNow = 23) or (WifiNow = 27)) return(0) else if (AsNow = 1 && ipAddrFlg = TRUE) #ActiveSync接続済みでIPアドレス割り当て済み return(0) else if (AsNow = 1 && ipAddrFlg = FALSE) #ActiveSync接続済みでIPアドレス割り当てなし return (1) else if ((CellularNow = 0) and (InternetConnect <> 1)) # 回線接続する Connect(ConnectName[InternetConnect]) Sleep( 8000 ) NetConnect = regread("HKLM","System\State\Connections","Count") endif return( NetConnect = 0 ) endif endif endif endif endsub ### ネット切断 ### sub NetDisconnect endsub ### ダウンロード(ファイルキャッシュ付) ### # in....[1] ダウンロードするURL # [2] 書き込むファイル名 sub DL_html local(i) showwaitcursor download(argv[1],argv[2]) hidewaitcursor return(readfile(argv[2],0,"utf8-prefix")) endsub ### 配列に読み込む ### # in....[1] html # [2] html切り出し切欠 # [3] html切り出しここまで # [4] 地域名切り出し切欠 # [5] 地域名切り出しここまで # out...area_dir[] html # area_dir_name[] 地域名 sub GetArea local(i,GetStr) i = 1 x = 1 clear(area_dir) clear(area_dir_name) while(x) callfunction("BetweenStrings",GetStr,argv[1],x,argv[2],argv[3]) if(GetStr ne "") area_dir[i] = GetStr callfunction("BetweenStrings",area_dir_name[i],argv[1],x,argv[4],argv[5]) i = i + 1 else x = 0 endif endwhile return(i - 1) endsub ### レジストリ読み込み ### # in....[1] レジストリ名 # [2] 初期値 sub RegstorySet if(regvalueexists("HKCU",gozen,argv[1])) [argv[1]] = regread("HKCU",gozen,argv[1]) else [argv[1]] = argv[2] endif endsub ### レジストリトグル ### # in....[1] レジストリ名 sub RegstoryToggle [argv[1]] = 1 - [argv[1]] regwritedword("HKCU",gozen,argv[1],[argv[1]]) endsub ### タイマーをセットした時間を返す ### sub TimerStr call("RegstorySet","DownloadTime",0) if(DownloadTime) return(formattime("Y/m/d({W}) H:i:s",DownloadTime)) else return("----/--/--(---) --:--:--") endif endsub ### 巡回タイマーセット ### sub TimerRoundSet local(i) now = timestamp() # 時間を23-4:0/5-10:1/11-16:2/17-22:3に四分割する i = ((now mod 86400) / 3600) Switch ( i ) case ( 0, 1, 2, 3, 4, 5, 6, 7 ) # 当日の8時に取得予定 i = now - (now mod 86400) + 8 * 3600 + Timelag * 60 case ( 18, 19, 20, 21, 22, 23 ) # 翌日の8時に取得予定 i = now - (now mod 86400) + 86400 + 8 * 3600 + Timelag * 60 case ( 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) # 当日の18時に取得予定 i = now - (now mod 86400) + 18 * 3600 + Timelag * 60 EndSwitch # message( formattime("Y/m/d({W}) H:i:s",i) ) call("TimerSet",i) return(i) endsub ### タイマーセット ### sub TimerSet runat(argv[1],Mortexe,PollenRunAtT) regwritedword("HKCU",gozen,"DownloadTime",argv[1]) endsub ### タイマー削除 ### sub TimerDelete removenotifications(Mortexe,PollenRunAtT) regwritedword("HKCU",gozen,"DownloadTime",0) endsub ### 画像読み込み ### # in....[1] ダウンロードファイル名 # [2] ダウン先ファイル名 sub ImageDL # DL済みか if(fileexists(argv[2]) = 0) # DLする download(argv[1],argv[2]) if(filesize(argv[2]) = 0) # delete(argv[2]) endif endif endsub ### メッセージ表示 ### # タイマー起動の場合は表示しない sub PrintMessage if((RunAtTimer ne "ON") and (RunAtAutoexec ne "ON")) sleepmessage(SleepTime,argv[1]) endif endsub ### エラーメッセージ表示 ### # メッセージを表示して終了する sub PrintError call("PrintMessage",argv[1]) exit endsub ### Yes/No表示 ### # タイマー起動の場合はそのまま終了 sub PrintQuestion if((RunAtTimer eq "ON") or (RunAtAutoexec eq "ON")) exit endif return(question(argv[1])) endsub ### 花粉飛散状況データダウンロード ### sub PollenDownload # ダウンロードする地域のURL(tenki.jp) PollenURL = URL_pollen & regread("HKCU",gozen,"DownloadURL") if(PollenURL eq URL_pollen) call("PrintError","ダウンロード地域が指定されていません^NL^終了します") endif # データダウンロード download(PollenURL,DL_temp) # 読み込みに成功しているか if(fileexists(DL_temp)) text = readfile(DL_temp,0,"utf8-prefix") # 必要な所だけ切り出す callfunction("BetweenStrings",today,text,1,"","
") callfunction("BetweenStrings",otherday,text,1,"","") ### 地域取得 ### callfunction("BetweenStrings",DT_area,today,1,"summary=""","の花粉飛散情報",16) ### 発表日時 ### # 年 callfunction("BetweenStrings",DT_year,today,1,"icon_mytenki.jpg","") callfunction("BetweenStrings",DT_year,today,x,"dateRight"">","年",4) # 月 callfunction("BeforeStrings",DT_month,today,x,"月",2) # 日 callfunction("BeforeStrings",DT_day,today,x,"日",2) # 時 callfunction("BeforeStrings",DT_hour,today,x + 1,"時",2) # 分 callfunction("BeforeStrings",DT_minute,today,x,"分",2) #発表時間+エリア情報 textout = DT_year & "年 " & DT_month & "月 " & DT_day & "日 " & DT_hour & "時" & DT_minute & "分発表(" & DT_area & ")" regwritestring("HKCU",gozen,"ReleaseArea",DT_area) regwritestring("HKCU",gozen,"ReleaseYear",DT_year) regwritestring("HKCU",gozen,"ReleaseMonth",DT_month) regwritestring("HKCU",gozen,"ReleaseDay",DT_day) regwritestring("HKCU",gozen,"ReleaseHour",DT_hour) regwritestring("HKCU",gozen,"ReleaseMinute",DT_minute) regwritestring("HKCU",gozen,"ReleaseYMDT",textout) textout = DT_area & "の天気^NL^" & textout & "^NL^^NL^" ### 切り分け ### # 今日 callfunction("BetweenStrings",weather[1],today,1,"AreaWeathersToday",">") callfunction("BetweenStrings",DT_days[1],today,x,"月","日",2) callfunction("BetweenStrings",DT_week[1],today,x,"(",")",1) # 明日 callfunction("BetweenStrings",weather[2],today,1,"AreaWeathersTomorrow",">") callfunction("BetweenStrings",DT_days[2],today,x,"月","日",2) callfunction("BetweenStrings",DT_week[2],today,x,"(",")",1) # 2日後 callfunction("BetweenStrings",weather[3],today,1,"AreaWeathersDay",">") callfunction("BetweenStrings",DT_days[3],today,x,"月","日",2) callfunction("BetweenStrings",DT_week[3],today,x,"(",")",1) # 3日後 callfunction("BetweenStrings",DT_days[4],today,x,"月","日",2) callfunction("BetweenStrings",DT_week[4],today,x,"(",")",1) # 4日後 callfunction("BetweenStrings",DT_days[5],today,x,"月","日",2) callfunction("BetweenStrings",DT_week[5],today,x,"(",")",1) # 6日後 callfunction("BetweenStrings",DT_days[6],today,x,"月","日",2) callfunction("BetweenStrings",DT_week[6],today,x,"(",")",1) ### 花粉状況の取得 ### callfunction("BetweenStrings",KafunInfo[1],today,1,"title=""","""") callfunction("BetweenStrings",DT_kafun[1],text,x,"/images/pollen/icon_large_","jpg",5) callfunction("BetweenStrings",DT_kafunstr[1],text,x,"alt=""","""",5) callfunction("BetweenStrings",DT_kafun[2],text,x,"/images/pollen/icon_large_","jpg",5) callfunction("BetweenStrings",DT_kafunstr[2],text,x,"alt=""","""",5) callfunction("BetweenStrings",DT_kafun[3],text,x,"/images/pollen/icon_middle_","jpg",5) callfunction("BetweenStrings",DT_kafunstr[3],text,x,"alt=""","""",5) callfunction("BetweenStrings",DT_kafun[4],text,x,"/images/pollen/icon_middle_","jpg",5) callfunction("BetweenStrings",DT_kafunstr[4],text,x,"alt=""","""",5) callfunction("BetweenStrings",DT_kafun[5],text,x,"/images/pollen/icon_middle_","jpg",5) callfunction("BetweenStrings",DT_kafunstr[5],text,x,"alt=""","""",5) callfunction("BetweenStrings",DT_kafun[6],text,x,"/images/pollen/icon_middle_","jpg",5) callfunction("BetweenStrings",DT_kafunstr[6],text,x,"alt=""","""",5) for i = 1 to 6 # データがない? if(DT_kafun[i] eq "") DT_kafun[i] = "0." DT_kafunstr[i] = "---" endif # 日時@@ textout = textout & DT_days[i] & "(" & DT_week[i] & ")^NL^" & DT_kafunstr[i] & "^NL^" regwritestring("HKCU",gozen \ i,"Day",DT_days[i]) regwritestring("HKCU",gozen \ i,"Week",DT_week[i]) regwritestring("HKCU",gozen \ i,"Dayweek",DT_days[i] & "日(" & DT_week[i] & ")") if (DT_kafunstr[i] eq "飛散開始前") DT_kafunstr[i] = "なし" endif regwritestring("HKCU",gozen \ i,"info",DT_kafunstr[i]) # アイコンの複写 copy(DATA_path \ DT_kafun[i] & "png",systempath("ScriptPath") \ "kafun_" & i & ".png",1) textout = textout & "^NL^" next # 天気をファイルに書き出す writefile(Kafunout,textout) return(0) # today画面の再描画 if(RDToday) redrawtoday endif ### ダウンロードに失敗した else call("PrintMessage","花粉飛散データがダウンロードできませんでした") return(1) endif endsub ### 指定文字列までの文字列を返す ### # in....[1] 対象文字列 # [2] 検索位置 # [3] チェックする文字列 # out...ret() 取得文字列 # x 検索後の位置 sub BeforeStrings local(i) i = find(argv[1],argv[3],argv[2]) switch(1) case(i = 1) return("") x = i + length(argv[3]) case(i > 1) return(substr(argv[1],argv[2],i - argv[2])) x = i + length(argv[3]) case(i = 0) return("") x = argv[2] endswitch endsub ### 指定文字列以降の文字列を返す ### # in....[1] 対象文字列 # [2] 検索位置 # [3] チェックする文字列 # out...ret() 取得文字列 # x 常に1 sub AfterStrings local(i) i = find(argv[1],argv[3],argv[2]) if(i) return(substr(argv[1],i + length(argv[3]))) else return("") endif x = 1 endsub ### 指定文字列間の文字列を返す ### # in....[1] 対象文字列 # [2] 検索位置 # [3] 最初の文字列 # [4] 最後の文字列 # [5] [返り血の文字数制限] # out...ret() 取得文字列 # x 検索後の位置 sub BetweenStrings local(i,text) i = find(argv[1],argv[3],argv[2]) text = "" if(i) i = i + length(argv[3]) x = find(argv[1],argv[4],i) if(x) text = substr(argv[1],i,x-i) x = x + length(argv[4]) endif else x = argv[2] endif # 返り値の制限の有無 if(argc > 4) return(substr(text,1,argv[5])) else return(text) endif endsub