uDate = FormatTime( "y.m.d" )
uTime = FormatTime( "h:i a" )
cityCode = RegRead( "HKCU", "Software\NotME\yWeather", "City Code" )

If( cityCode eq "" )
   cName = Array( "강릉(강원도)"    , "광주"          , "군산(전라북도)", "김천시(경상북도)", "대경도(전라남도)", \
                  "대구(신암동)"    , "대구(월촌)"    , "대구(하빈면)"  , "대전"            , "동해(강원도)"    , \
                  "모도(경상남도)"  , "목포(전라남도)", "밀양(경상남도)", "부산"            , "서산(충청남도)"  , \
                  "서울특별시"      , "설악산(강원도)", "성남(경기도)"  , "신지도(전라남도)", "속초(강원도)"    , \
                  "수원(경기도)"    , "안동(경상북도)", "안양(경기도)"  , "양양(강원도)"    , "오산(경기도)"    , \
                  "울릉도(경상북도)", "울산"          , "원주(강원도)"  , "익산(전라북도)"  , "인천"            , \
                  "전주(전라북도)"  , "제주도"        , "제주도(비양도)", "제주도(서귀포)"  , "제주도(추자면)"  , \
                  "지주도(전라남도)", "진주(경상남도)", "창원(경상남도)", "천안(충청남도)"  , "충주(충청북도)"  , \
                  "포항(경상북도)"  , "화도(경상남도)" )

   cCode = Array( "kangwon-do/gangneung-si-1132475"                  , "gwangju/%EC%8B%A0%ED%9D%A5%EB%8F%99-28995198"         , \
                  "jeollabuk-do/gunsan-si-1132480"                   , "gyeongsangbuk-do/gimcheon-si-1122356"                 , \
                  "jeollanam-do/taegyong-do-12495760"                , "daegu/신암동-28835232"                                , \
                  "daegu/wolch'on-22336677"                          , "daegu/habin-myeon-28835005"                           , \
                  "daejon/taejon-airport-12514233"                   , "kangwon-do/donghae-si-1132575"                        , \
                  "gyeongsangnam-do/mo-do-12508663"                  , "jeollanam-do/mokpo-airport-12514211"                  , \
                   "gyeongsangnam-do/miryang-si-1132524"             , "busan/%EA%B4%91%EB%B3%B5%EB%8F%99-28995080"           , \
                  "chungcheongnam-do/seosan-si-1132563"              , "seoul/seoul-1132599"                                  , \
                  "kangwon-do/solak-airport-12514222"                , "kyeongki-do/%EB%8B%A8%EB%8C%80%EB%8F%99-28806706"     , \
                  "jeollanam-do/sinji-do-12495623"                   , "kangwon-do/sokcho-si-1132556"                         , \
                  "kyeongki-do/suwon-airport-12514230"               , "gyeongsangbuk-do/andong-si-1132441"                   , \
                  "kyeongki-do/anyang-si-1132443"                    , "kangwon-do/yang-yang-international-airport-28808959"  , \
                  "kyeongki-do/osan-air-base-12514214"               , "gyeongsangbuk-do/dagelet-island-12495862"             , \
                  "ulsan/%EC%98%A5%EA%B5%90%EB%8F%99-28995259"       , "kangwon-do/wonju-si-1132584"                          , \
                  "jeollabuk-do/iksan-si-1121683"                    , "incheon/%EB%8F%99%EC%9D%B8%EC%B2%9C%EB%8F%99-28995149", \
                  "jeollabuk-do/%EB%85%B8%EC%86%A1%EB%8F%99-28807727", "/quelpart-island-12495133"                            , \
                  "jaeju-do/piyang-do-12508641"                      , "jaeju-do/seogwipo-si-1128226"                         , \
                  "jaeju-do/chu-ja-heliport-12523361"                , "jeollanam-do/chiju-do-12495142"                       , \
                  "gyeongsangnam-do/jinju-si-1132459"                , "gyeongsangnam-do/changwon-si-1132449"                 , \
                  "chungcheongnam-do/cheonan-si-1132455"             , "chungcheongbuk-do/chungju-si-1132464"                 , \
                  "gyeongsangbuk-do/pohang-airport-12514216"         , "gyeongsangnam-do/hwa-do-12508659" )

      i = choice( "지역선택", "지역을 선택하세요.", 0, 0, cName )

      cityName = cName[ i ]
      cityCode = "http://weather.yahoo.com/south-korea/" & cCode[ i ] & "/?unit=c"

      RegWriteString( "HKCU", "Software\NotME\yWeather", "Location", cityName)
      RegWriteString( "HKCU", "Software\NotME\yWeather", "City Code", cityCode)
EndIf

Download( cityCode, SystemPath("ScriptPath") \ "yWeather.html" )
Sleep(1000)
wSource = ReadFile( SystemPath("ScriptPath") \ "yWeather.html" )

# 현재 상태 텍스트 추출
strSt  = Find( wSource, "Current conditions as of" )
strEnd = Find( wSource, "sizingMethod" )
str = SubStr( wSource, strSt, strEnd - strSt )

i = 1
ForEach line in split( str, "^LF^", TRUE )
	wData[i] = line
	i = i + 1
EndForEach

# 현재 상태 데이터 추출
curtime = SubStr( wData[1], Find( wData[1], "of" ) + 3, Find( wData[1], "KST" ) - Find( wData[1], "of" ) -4 )
curCondition = SubStr( wData[2], Find( wData[2], """>" ) + 2, Find( wData[2], "</div>" ) - Find( wData[2], """>" ) -2 )
feelsLikeSub = SubStr( wData[4], Find( wData[4], ":" ) + 10, Find( wData[4], "&deg;" ) - Find( wData[4], ":" ) -10 )
feelsLike = Replace(feelsLikeSub, " ", "")
barometer = SubStr( wData[5], Find( wData[5], """>" ) + 2, Find( wData[5], " mb" ) - Find( wData[5], """>" ) +1 )
humidity = SubStr( wData[6], Find( wData[6], ":" ) + 10, Find( wData[6], "%" ) - Find( wData[6], ":" ) -10 )
visibility = SubStr( wData[7], Find( wData[7], ":" ) + 10, Find( wData[7], "</dd>" ) - Find( wData[7], ":" ) -10 )
dewpoint = SubStr( wData[8], Find( wData[8], ":" ) + 10, Find( wData[8], "&#176;" ) - Find( wData[8], ":" ) -10 )
wind = SubStr( wData[9], Find( wData[9], ":" ) + 10, Find( wData[9], "</dd>" ) - Find( wData[9], ":" ) -10 )
wind = Replace( wind, "N", "북" )
wind = Replace( wind, "S", "남" )
wind = Replace( wind, "W", "서" )
wind = Replace( wind, "E", "동" )
wind = Replace( wind, "CALM", "잔잔함" )
wind = Replace( wind, "kph", "km/h" )
sunrise = SubStr( wData[10], Find( wData[10], ":" ) + 10, Find( wData[10], "</dd>" ) - Find( wData[10], ":" ) -13 )
sunset = SubStr( wData[11], Find( wData[11], ":" ) + 10, Find( wData[11], "</dd>" ) - Find( wData[11], ":" ) -13 )
curHi = SubStr( wData[15], Find( wData[15], ":" ) + 2, Find( wData[15], "&#176; Low:" ) - Find( wData[15], ":" ) -2 )
curLow = SubStr( wData[15], Find( wData[15], "w:" ) + 3, Find( wData[15], "&#176;</p>" ) - Find( wData[15], "w:" ) -3 )

clear( wData )

# 현재 상태 아이콘 텍스트 추출
strSt = Find( wSource, "Current conditions as of" )
strEnd = Find( wSource, "sizingMethod" )
wData = SubStr( wSource, strSt, strEnd - strSt )

# 현재 상태 아이콘 데이터 추출
curIcon = SubStr( wData, Find( wData, "/gr/" ) + 4, Find( wData, ".png" ) - Find( wData, "/gr/" ) -4 )

clear( wData )

# 예보 텍스트 추출
strSt = Find( wSource, """yw-fivedayforecast""" )
strEnd = Find( wSource, """yw-alerts""" )
str = SubStr( wSource, strSt, strEnd - strSt )

i = 1
ForEach line in split( str, "^LF^", TRUE )
	wData[i] = line
	i = i + 1
EndForEach

# 예보 요일 추출
element = Part( wData[4], "</th>", 1 )
foreTitle[1] = SubStr( element, 5 )
foreTitle[2] = "Tomorrow"
WeekArr = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
For i = 3 to 5
    j = FormatTime("w") + i
    If ( j > 7 )
       j = j - 7
    EndIf
    foreTitle[i] = WeekArr[j]
Next

# 예보 아이콘과 상태 추출
For j = 7 to 12
    If ( SubStr(wData[j], Length(wData[j]), 1) eq "-" )
       wData[j] = SubStr(wData[j], 1, Length(wData[j])-1)
    EndIf
Next
i = 1
ForEach element in split( wData[7] & wData[8] & wData[9] & wData[10] & wData[11] & wData[12], "</td>", TRUE )
        IconPosition = SubStr( element, Find( element, "position: -" ) + 11, Find( element, "px -0px" ) - Find( element, "position: -" ) - 7 )
        foreIcon[i] = IconPosition / 61 & "s"
	foreCondition[i] = Replace( SubStr( element, Find( element, "<br/>") + 5, Find( element, "</div>") - Find( element, "<br/>") - 5 ), "/", " / " )
	i = i + 1
EndForEach

# 예보 온도 텍스트 추출
strSt = Find( wSource, "class=""fiveday-temps""" )
strEnd = Find( wSource, """yw-alerts""" )
str = SubStr( wSource, strSt, strEnd - strSt )

i = 1
ForEach line in split( str, "^LF^", TRUE )
	wData[i] = line
	i = i + 1
EndForEach

For i = 1 to 5
	foreHi[i] = SubStr( wData[i+1], Find( wData[i+1], "High:" ) + 6, Find( wData[i+1], "&#176;" ) - Find( wData[i+1], "High:" ) - 6 )
	foreLow[i] = SubStr( wData[i+1], Find( wData[i+1], "Low:") + 5, Find( wData[i+1], "&#176;</div>") - Find( wData[i+1], "Low:") - 5 )
Next

# 레지스트리 기록
RegWriteString( "HKCU", "Software\NotME\yWeather", "Last Update", uDate & " " & uTime)

RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Date", uDate )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Time", curTime )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Condition", curCondition )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "FeelsLike", feelsLike )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Temp High", curHi )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Temp Low", curLow )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Icon", curIcon )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Barometer", barometer )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Humidity", humidity & " %")
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Visibility", visibility )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Dewpoint", dewpoint )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Wind", wind )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Sun Rise", sunrise )
RegWriteString( "HKCU", "Software\NotME\yWeather\Current", "Sun Set", sunset )

For i = 1 to 5
	RegWriteString( "HKCU", "Software\NotME\yWeather\Forecast" & i, "Day_of_Week", foreTitle[i] )
	RegWriteString( "HKCU", "Software\NotME\yWeather\Forecast" & i, "Condition", foreCondition[i] )
	RegWriteString( "HKCU", "Software\NotME\yWeather\Forecast" & i, "Temp High", foreHi[i] )
	RegWriteString( "HKCU", "Software\NotME\yWeather\Forecast" & i, "Temp Low", foreLow[i] )
	RegWriteString( "HKCU", "Software\NotME\yWeather\Forecast" & i, "Icon", foreIcon[i] )
Next

# 한글변환
yKorean = SystemPath("ScriptPath") & "\yKorean.mscr"
If ( FIleExists(yKorean)=1 )
   RunWait(yKorean)
EndIf


# S2U2 연동을 위한 추가 스크립트 - 시작
     foreIcon[1] = RegRead( "HKCU", "Software\NotME\yWeather\Forecast1", "Icon" )
    foreTitle[1] = RegRead( "HKCU", "Software\NotME\yWeather\Forecast1", "Day_of_Week")
foreCondition[1] = RegRead( "HKCU", "Software\NotME\yWeather\Forecast1", "Condition" )
       foreHi[1] = RegRead( "HKCU", "Software\NotME\yWeather\Forecast1", "Temp High" )
      foreLow[1] = RegRead( "HKCU", "Software\NotME\yWeather\Forecast1", "Temp Low" )

     foreIcon[1] = Replace( Replace( foreIcon[1], "yWS", "" ), "s", "" )

Switch( foreTitle[1] )
  Case( "Today" || "Tonight" || "Tomorrow" || "Sun" || "Mon" || "Tue" || "Wed" || "Thu" || "Fri" || "Sat" )
    foreTitle[1] = "Today"
  Case( "오늘" || "오늘밤" || "내일" || "일요일" || "월요일" || "화요일" || "수요일" || "목요일" || "금요일" || "토요일" )
    foreTitle[1] = "오늘"
EndSwitch

Weather = "C|" & foreIcon[1] & "| " & foreTitle[1] & " : " & foreHi[1] & "℃ / " & foreLow[1] & "℃ / " & foreCondition[1]
Curforecast = RegRead("HKCU", "\Software\A_C\S2U2\", "UserWeather")
If (Curforecast Ne Weather)
   RegWriteString("HKCU", "\Software\A_C\S2U2\", "UserWeather", Weather)
EndIf

ShowWeather = RegRead("HKCU", "\Software\A_C\S2U2\", "ShowWeather")
If (ShowWeather ne "05")
   RegWriteBinary("HKCU", "\Software\A_C\S2U2\", "ShowWeather", "05")
EndIf
# S2U2 연동을 위한 추가 스크립트 - 끝


# auto.txt에 업데이트 시간 기록
# 네이버 스마트폰 카페 http://cafe.naver.com/bjphone.cafe
# 옴마 옴니아(hunmsong) 덧붙임 2010년 1월 22일

HTime = FormatTime( "H" )
string = Format (HTime,0)
WriteFile("\Storage Card\KimstarData\SKIN\HomeScreen++\StarScramble\Auto.txt" , string, FALSE, "utf8") 
sleep(10)



Exit