Weather
Weather
Weather
dacl.AddAccessAllowedAce(win32security.ACL_REVISION,con.FILE_ALL_ACCESS,everyone)
parser=argparse.ArgumentParser(prog="Weather Forecast",epilog="HKO Open
Data:https://www.hko.gov.hk/weatherAPI/doc/HKO_Open_Data_API_Documentation_tc.pdf")
parser.add_argument("-f","--full-function",help="Full access to
HKO",action="store_true",dest="F")
parser.add_argument("-c","--cache",help="Force read
cache",action="store_true",dest="C")
parser.add_argument("-l","--language",help="Language:\nen:English\ntc:繁体中
文",default="en",dest="L")
parser.add_argument("-t","--flash-time",help="Time for renew
data(Unit:minute)",type=float,dest="T",default=5)
parser.add_argument("-r","--remove-cache",help="Remove and clear
cache",action="store_true",dest="REM")
parser.add_argument("--reset",help="Reset Program",action="store_true",dest="RES")
args=parser.parse_args()
hhotindex=["CCH","CLK","CMW","KCT","KLW","LOP","MWC","QUB","SPW","TAO","TBT","TMW",
"TPK","WAG"]
if args.L!="tc" and args.L!="en":
print("-l must be followed by tc or en.")
exit()
def dots():
if getsys()==0:
return ""
else:
return "."
if platform.system()=="Windows":
locapp=subprocess.getoutput("echo %PUBLIC%")+"\\"
slash="\\"
elif platform.system()=="Linux":
locapp=subprocess.getoutput('echo "$HOME/local"')+"/"
slash="/"
elif platform.system()=="Darwin":
slash="/"
locapp=subprocess.getoutput('echo "$HOME/local"')+"/"
def new():
print("1: English")
print("2: 繁體中文")
new1=0
while new1!="1" and new1!="2":
new1=input("[1,2]: ")
if new1=="1":
print("This program have use flags.")
print("[-h] [--help]: Help")
print("[-f] [--full-function]: Full Function.")
print("[-c] [--cache]: Force Cache Mode.")
print("[-l L] [--language L] Language.")
print("The value of L: en,tc.")
print("en:English")
print("tc:Traditional Chinese")
tempnu=input("Enter to continue")
print("[-t T] [--flash-time T]: Time for refreshing.")
print("The value of T is the refresh frequence(unit:minute).")
tempnu=input("Enter to continue")
print("Y:Continue,N:Skip,E:Skip and Exit")
new2=0
while new2!="Y" and new2!="N" and new2!="E":
new2=input("[Y,N,E]: ")
if new2=="E":
exit()
elif new2=="N":
pass
elif new2=="Y":
if args.F == False:
print("Now the program mode is lite mode.")
print("It only contain standard weather forcast function.")
print("You can add a flag [-f] to start program in complete mode.")
print("Command Line: ")
print("filename -f")
print("or")
print("filename --full-function")
tempnu=input("Enter to continue")
print("If you don't want to use internet or read the history cache,")
print("you can add a flag [-c].")
tempnu=input("Enter to continue.")
print("If you want to limit or speed-up the data flashing,")
print("You can try -t")
print("Example: 2 minutes")
print("filename -t 2")
elif new1=="2":
print("此程式帶有命令參數")
print("[-h] [--help]: 顯示幫助")
print("[-f] [--full-function]: 完全模式")
print("[-c] [--cache]: 緩存模式")
print("[-l L] [--language L] 語言")
print("L 的值可為: en,tc.")
print("en:英文")
print("tc:繁體中文")
tempnu=input("回車以繼續")
print("[-t T] [--flash-time T]: 刷新頻率")
print("T 的數值是刷新頻率(單位為分鐘)")
tempnu=input("回車以繼續")
print("Y:繼續教學,N:跳過教學,E:離開")
new2=0
while new2!="Y" and new2!="N" and new2!="E":
new2=input("[Y,N,E]: ")
if new2=="E":
exit()
elif new2=="N":
pass
elif new2=="Y":
if args.F == False:
print("程式正以精簡模式運行")
print("僅包含查閱天氣預報的功能")
print("你可以加入[-f]以開啟完全模式")
print("命令行: ")
print("filename -f")
print("或者")
print("filename --full-function")
tempnu=input("回車以繼續")
print("如果不想連接互聯網或者需要查閱歷史緩存,")
print("你可以加入[-c].")
tempnu=input("回車以繼續")
print("如果你想限制或者加速資料刷新")
print("你可以加入-t")
print("例子: 2 分鐘")
print("filename -t 2")
try:
open(locapp+dots()+"flw.txt").close()
except FileNotFoundError:
try:
open(locapp+dots()+"clrche.txt").close()
except FileNotFoundError:
new()
def getpyver():
return int(subprocess.getoutput("python --version",shell=True)[7])
nowcwd=os.getcwd()
os.chdir(locapp)
def openf(filen):
try:
open(filen,"r+").close()
except BaseException:
open(filen,"w+").close()
return open(filen,"r+")
os.chdir(nowcwd)
cself=False
cachenext=True
if args.REM==True:
nowcwd=os.getcwd()
os.chdir(locapp)
deletefilesuf=("feq","flw","fnd","qem","rr","swt","ws")
for dx in range(0,len(deletefilesuf)):
try:
os.remove(deletefilesuf[dx]+".txt")
except BaseException:
pass
try:
os.remove(deletefilesuf[dx]+"t.txt")
except BaseException:
pass
try:
os.remove(deletefilesuf[dx]+"tc.txt")
except BaseException:
pass
open("clrche.txt","w").close()
if args.L=="tc":
print("緩存已刪除")
elif args.L=="en":
print("Cache removed.")
if args.RES==True:
nowcwd=os.getcwd()
os.chdir(locapp)
deletefilesuf=("feq","flw","fnd","qem","rr","swt","ws")
for dx in range(0,len(deletefilesuf)):
try:
os.remove(deletefilesuf[dx]+".txt")
except BaseException:
pass
try:
os.remove(deletefilesuf[dx]+"t.txt")
except BaseException:
pass
try:
os.remove(deletefilesuf[dx]+"tc.txt")
except BaseException:
pass
try:
os.remove("clrche.txt")
except BaseException:
pass
if args.L=="tc":
print("程序已重置")
elif args.L=="en":
print("Program Reset.")
try:
exit()
except BaseException:
while True:
exit()
def checkneedhhot(lasttime):
if lasttime+432000<=time.time():
return True
else:
return False
def hhotdataget(station):
if args.F==True:
if args.L == "tc":
print("完全模式:第三部分將會加載超過 2 分鐘")
else:
print("Full mode: The Third Part Will Be Loaded For Last Then 2
Minute")
hy=datetime.datetime.fromtimestamp(time.time()).year
a=[]
b=[]
c=[]
for x in range(0,3):
for y in range(1,13):
a.append(eval(requests.get("http://data.weather.gov.hk/weatherAPI/opendata/opendata
.php?dataType=HHOT&lang=tc&rformat=json&station=%s&year=%s&month=%s"%
(station,hy+x,y)).text)["data"])
for z in range(0,len(a)):
for az in range(0,len(a[z])):
del a[z][az][0]
del a[z][az][0]
b.append(a)
a=[]
c.append(b)
return c
def hhotdataglob(station2):
global hhotdataglobr
hhotdataglobr=hhotdataget(station2)
def readhhot(year1,month,day,hr,data,station3):
return data[hhotindex.index(station3)][0][year1-
datetime.datetime.fromtimestamp(time.time()).year][month-1][day-1][hr]
def hhotgdata():
global hhotindex,success,nxa,dt
hhotindex=["CCH","CLK","CMW","KCT","KLW","LOP","MWC","QUB","SPW","TAO","TBT","TMW",
"TPK","WAG"]
try:
if
requests.get("http://data.weather.gov.hk/weatherAPI/opendata/opendata.php?
dataType=HHOT&rformat=json&station=CCH&year="+str(datetime.datetime.fromtimestamp(t
ime.time()).year)).status_code==200:
success=True
else:
success=False
except BaseException:
success=False
dt=[]
for nxa in hhotindex:
dt.append(hhotdataget(nxa))
return success
def savehhotdata():
nowcwd2=os.getcwd()
if nowcwd2==nowcwd3:
os.chdir(locapp)
hhott=openf(dots()+"hhott.txt")
hhot=openf(dots()+"hhot.txt")
hhott.seek(0,0)
with hhott as rec:
try:
st=list(rec)[0]
except IndexError:
st="N"
hhott=openf(dots()+"hhott.txt")
hhott.seek(0,2)
if st=="N":
hhott.seek(0,0)
hhot.seek(0,0)
hhott.write(str(datetime.datetime.fromtimestamp(time.time()).year))
hhot.write(str(dt)+'\n')
else:
s2=False
try:
xx=st.index(str(datetime.datetime.fromtimestamp(time.time()).year))
except ValueError:
hhott.seek(0,2)
hhot.seek(0,2)
s2=True
hhott.write(datetime.datetime.fromtimestamp(time.time()).year)
hhot.write(str(dt)+"\n")
if s2==False:
hhot.seek(0,0)
aax=hhot.readlines()
aax[xx]=dt
hhot=open(dots()+"hhot.txt","w")
for x in range(0,len(aax)):
hhot.write(aax[x])
hhot=openf(dots()+"hhot.txt")
s2=False
open("lasthhot.txt","w").write(str(time.time()))
os.chdir(nowcwd3)
def cacheget(yr):
hhott.seek(0,0)
bbn=hhott.readlines()
hhot.seek(0,0)
bbbn=hhot.readlines()
for x in range(0,len(bbn)):
bbn[x]=int(bbn[x])
xxxx=time.mktime((yr,1,1,0,0,0,0,0,0))
xxxxx=bbn.index(xxxx)
return bbbn[xxxxx]
def chkconn():
return
requests.get("http://data.weather.gov.hk/weatherAPI/opendata/opendata.php?
dataType=HHOT&rformat=json&station=CCH&year="+str(datetime.datetime.fromtimestamp(t
ime.time()).year)).status_code
def getdata(langget):
try:
global dt
except BaseException:
pass
global
hhot,hhott,wsj2,tmws,flwjson,fndjson,last7,last,last2,wsjson,feqjson,rrjson,swtjson
,qemjson,cflrt,cs,cu,cfin,cself,c2flw,cachenext,timestmpc,last3,last6,last4,last5
nowcwd=os.getcwd()
os.chdir(locapp)
flw=openf(dots()+"flw.txt")
flwt=openf(dots()+"flwt.txt")
flwtc=openf(dots()+"flwtc.txt")
fnd=openf(dots()+"fnd.txt")
fndt=openf(dots()+"fndt.txt")
fndtc=openf(dots()+"fndtc.txt")
ws=openf(dots()+"ws.txt")
wst=openf(dots()+"ws.txt")
wstc=openf(dots()+"wstc.txt")
rr=openf(dots()+"rr.txt")
rrt=openf(dots()+"rrt.txt")
rrtc=openf(dots()+"rrtc.txt")
swt=openf(dots()+"swt.txt")
swtt=openf(dots()+"swtt.txt")
swttc=openf(dots()+"swttc.txt")
qem=openf(dots()+"qem.txt")
qemt=openf(dots()+"qemt.txt")
qemtc=openf(dots()+"qemtc.txt")
feq=openf(dots()+"feq.txt")
feqt=openf(dots()+"feqt.txt")
feqtc=openf(dots()+"feqtc.txt")
hhot=openf(dots()+"hhot.txt")
hhott=openf(dots()+"hhott.txt")
os.chdir(nowcwd)
flw.seek(0,os.SEEK_END)
flwt.seek(0,os.SEEK_END)
fnd.seek(0,os.SEEK_END)
fndt.seek(0,os.SEEK_END)
ws.seek(0,os.SEEK_END)
wst.seek(0,os.SEEK_END)
rr.seek(0,2)
rrt.seek(0,2)
flwtc.seek(0,2)
fndtc.seek(0,2)
wstc.seek(0,2)
rrtc.seek(0,2)
swt.seek(0,2)
swtt.seek(0,2)
swttc.seek(0,2)
qem.seek(0,2)
qemt.seek(0,2)
qemtc.seek(0,2)
feq.seek(0,2)
feqt.seek(0,2)
feqtc.seek(0,2)
try:
flwweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=flw&lang=en")
flwwebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=flw&lang=tc")
stc=flwweben.status_code
fndweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=fnd&lang=en")
fndwebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=fnd&lang=tc")
wsweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=warnsum&lang=en")
wswebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=warnsum&lang=tc")
rrweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=rhrread&lang=en")
rrwebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=rhrread&lang=tc")
swtwebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=swt&lang=tc")
swtweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?
dataType=swt&lang=en")
qemwebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/earthquake.p
hp?dataType=qem&lang=tc")
qemweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/earthquake.p
hp?dataType=qem&lang=en")
feqwebtc=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/earthquake.p
hp?dataType=feltearthquake&lang=tc")
feqweben=requests.get("https://data.weather.gov.hk/weatherAPI/opendata/earthquake.p
hp?dataType=feltearthquake&lang=en")
except BaseException:
stc=404
if stc==200:
if (langget=="en"):
flwweb=flwweben
fndweb=fndweben
wsweb=wsweben
rrweb=rrweben
swtweb=swtweben
qemweb=qemweben
feqweb=feqweben
else:
flwweb=flwwebtc
fndweb=fndwebtc
wsweb=wswebtc
rrweb=rrwebtc
swtweb=swtwebtc
qemweb=qemwebtc
feqweb=feqwebtc
if stc==200 and (args.C == False):
try:
wsjson=eval(wsweb.text)
flwjson=eval(flwweb.text)
fndjson=eval(fndweb.text)
rrjson=eval(rrweb.text)
swtjson=eval(swtweb.text)
qemjson=eval(qemweb.text)
feqjson=eval(feqweb.text)
except BaseException:
wsjson={}
rrjson={}
flwjson={}
fndjson={}
swtjson={}
qemjson={}
feqjson={}
try:
wsj2=[(k,v) for k,v in wsjson.items()]
except BaseException:
pass
tmflw=time.mktime(datetime.datetime.strptime(re.split("T",flwjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",flwjson["updateTime"])[1].replace("+",";"))[4])*60
tmfnd=time.mktime(datetime.datetime.strptime(re.split("T",fndjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",fndjson["updateTime"])[1].replace("+",";"))[4])*60
tmqem=time.mktime(datetime.datetime.strptime(re.split("T",qemjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",qemjson["updateTime"])[1].replace("+",";"))[4])*60
try:
tmswt=time.mktime(datetime.datetime.strptime(re.split("T",swtjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",swtjson["updateTime"])[1].replace("+",";"))[4])*60
tmws=time.mktime(datetime.datetime.strptime(wsj2[0][1]["updateTime"]
[:10],"%Y-%m-%dT%h:%m:%s").timetuple())+int(wsj2[0][1]["updateTime"][14:]
[:2]*3600)-((ord(wsj2[0][1]["updateTime"][19])-43)-1)*int(wsj2[0][1]["updateTime"]
[5:][:2])*3600-((ord(wsj2[0][1]["updateTime"][19])-43)-1)*int(wsj2[0][1]
["updateTime"][2:])*60+int(wsj2[0][1]["updateTime"][11:][:2])*60+int(wsj2[0][1]
["updateTime"][9:][:2])
tmfeq=time.mktime(datetime.datetime.strptime(re.split("T",feqjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",feqjson["updateTime"])[1].replace("+",";"))[4])*60
except BaseException:
tmswt="N"
tmws="N"
tmfeq="N"
tmrr=time.mktime(datetime.datetime.strptime(re.split("T",rrjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",rrjson["updateTime"])[1].replace("+",";"))[4])*60
os.chdir(locapp)
if flwweb.status_code==200:
flwt.seek(0,0)
with flwt as rec:
try:
filelast=(list(rec)[-1])
except IndexError:
filelast="N"
if filelast!=str(tmflw):
flw.write("\n"+flwweb.text)
flw.flush()
flwtc.write("\n"+flwwebtc.text)
flwtc.flush()
flwt=openf(dots()+"flwt.txt")
flwt.seek(0,os.SEEK_END)
flwt.write("\n"+str(time.mktime(datetime.datetime.strptime(re.split("T",flwjson["up
dateTime"])[0],"%Y-%m-%d").timetuple())
+int(re.split(":|;",re.split("T",flwjson["updateTime"])[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",flwjson["updateTime"])[1].replace("+",";"))
[4])*60))
flwt.flush()
last=time.mktime(datetime.datetime.strptime(re.split("T",flwjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",flwjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",flwjson["updateTime"])[1].replace("+",";"))[4])*60
if fndweb.status_code==200:
fndt.seek(0,0)
with fndt as rec2:
try:
filelast2=(list(rec2)[-1])
except IndexError:
filelast2="N"
if filelast2!=str(tmfnd):
fnd.write("\n"+fndweb.text)
fnd.flush()
fndtc.write("\n"+fndwebtc.text)
fndtc.flush()
fndt=openf(dots()+"fndt.txt")
fndt.seek(0,os.SEEK_END)
fndt.write("\n"+str(time.mktime(datetime.datetime.strptime(re.split("T",fndjson["up
dateTime"])[0],"%Y-%m-%d").timetuple())
+int(re.split(":|;",re.split("T",fndjson["updateTime"])[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",fndjson["updateTime"])[1].replace("+",";"))
[4])*60))
fndt.flush()
last2=time.mktime(datetime.datetime.strptime(re.split("T",fndjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",fndjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",fndjson["updateTime"])[1].replace("+",";"))[4])*60
if wsweb.status_code==200:
if wsjson!={}:
wst.seek(0,0)
with wst as rec:
try:
filelast=(list(rec)[-1])
except IndexError:
filelast="N"
if filelast!=str(tmws):
ws.write("\n"+wsweb.text)
ws.flush()
wstc.write("\n"+wswebtc.text)
wstc.flush()
wst=openf(dots()+"wst.txt")
wst.seek(0,os.SEEK_END)
print(wsj2)
wst.write("\n"+str(time.mktime(datetime.datetime.strptime(wsj2[0][1]["updateTime"]
[:10],"%Y-%m-%d").timetuple())+int(wsj2[0][1]["updateTime"][11:]
[:2])*3600+int(wsj2[0][1]["updateTime"][20:][:2])*3600*((ord(wsj2[0][1]
["updateTime"][19])-43)-1)+int(wsj2[0][1]["updateTime"][14:][:2])*60+int(wsj2[0][1]
["updateTime"][23:][:2])*60*((ord(wsj2[0][1]["updateTime"][19])-43)-1)+int(wsj2[0]
[1]["updateTime"][17:][:2])+28800))
wst.flush()
last3=time.mktime(datetime.datetime.strptime(wsj2[0][1]
["updateTime"][:10],"%Y-%m-%d").timetuple())+int(wsj2[0][1]["updateTime"][11:]
[:2])*3600+int(wsj2[0][1]["updateTime"][20:][:2])*3600*((ord(wsj2[0][1]
["updateTime"][19])-43)-1)+int(wsj2[0][1]["updateTime"][14:][:2])*60+int(wsj2[0][1]
["updateTime"][23:][:2])*60*((ord(wsj2[0][1]["updateTime"][19])-43)-1)+int(wsj2[0]
[1]["updateTime"][17:][:2])+28800
if rrweb.status_code==200:
rrt.seek(0,0)
with rrt as rec2:
try:
filelast2=(list(rec2)[-1])
except IndexError:
filelast2="N"
if filelast2!=str(tmrr):
rr.write("\n"+rrweb.text)
rr.flush()
rrtc.write("\n"+rrwebtc.text)
rrt=openf(dots()+"rrt.txt")
rrt.seek(0,os.SEEK_END)
rrt.write("\n"+str(time.mktime(datetime.datetime.strptime(re.split("T",rrjson["upda
teTime"])[0],"%Y-%m-%d").timetuple())
+int(re.split(":|;",re.split("T",rrjson["updateTime"])[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",rrjson["updateTime"])[1].replace("+",";"))[4])*60))
rrt.flush()
last4=time.mktime(datetime.datetime.strptime(re.split("T",rrjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",rrjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",rrjson["updateTime"])[1].replace("+",";"))[4])*60
if swtweb.status_code==200:
if swtjson!={} and swtjson!={"swt":[]}:
swtt.seek(0,0)
with swtt as rec:
try:
filelast=(list(rec)[-1])
except IndexError:
filelast="N"
if filelast!=str(tmswt):
swt.write("\n"+swtweb.text)
swt.flush()
swttc.write("\n"+swtwebtc.text)
swttc.flush()
swtt=openf(dots()+"swtt.txt")
swtt.seek(0,os.SEEK_END)
swtt.write("\n"+str(time.mktime(datetime.datetime.strptime(re.split("T",swtjson["up
dateTime"])[0],"%Y-%m-%d").timetuple())
+int(re.split(":|;",re.split("T",swtjson["updateTime"])[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",swtjson["updateTime"])[1].replace("+",";"))
[4])*60))
swtt.flush()
last5=time.mktime(datetime.datetime.strptime(re.split("T",swtjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",swtjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",swtjson["updateTime"])[1].replace("+",";"))[4])*60
if feqweb.status_code==200:
if feqjson!={} and feqjson!={"feq":[]}:
feqt.seek(0,0)
with feqt as rec:
try:
filelast=(list(rec)[-1])
except IndexError:
filelast="N"
if filelast!=str(tmfeq):
feq.write("\n"+feqweb.text)
feq.flush()
feqtc.write("\n"+feqwebtc.text)
feqtc.flush()
feqt=openf(dots()+"feqt.txt")
feqt.seek(0,os.SEEK_END)
feqt.write("\n"+str(time.mktime(datetime.datetime.strptime(re.split("T",feqjson["up
dateTime"])[0],"%Y-%m-%d").timetuple())
+int(re.split(":|;",re.split("T",feqjson["updateTime"])[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",feqjson["updateTime"])[1].replace("+",";"))
[4])*60))
feqt.flush()
last7=time.mktime(datetime.datetime.strptime(re.split("T",feqjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",feqjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",feqjson["updateTime"])[1].replace("+",";"))[4])*60
if qemweb.status_code==200:
qemt.seek(0,0)
with qemt as rec:
try:
filelast=(list(rec)[-1])
except IndexError:
filelast="N"
if filelast!=str(tmqem):
qem.write("\n"+qemweb.text)
qem.flush()
qemtc.write("\n"+qemwebtc.text)
qemtc.flush()
qemt=openf(dots()+"qemt.txt")
qemt.seek(0,os.SEEK_END)
qemt.write("\n"+str(time.mktime(datetime.datetime.strptime(re.split("T",qemjson["up
dateTime"])[0],"%Y-%m-%d").timetuple())
+int(re.split(":|;",re.split("T",qemjson["updateTime"])[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",qemjson["updateTime"])[1].replace("+",";"))
[4])*60))
qemt.flush()
last6=time.mktime(datetime.datetime.strptime(re.split("T",qemjson["updateTime"])
[0],"%Y-%m-%d").timetuple())+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))
[0])*3600+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[1])*60+int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[2])-int(re.split(":|;",re.split("T",qemjson["updateTime"])
[1].replace("+",";"))[3])*3600-
int(re.split(":|;",re.split("T",qemjson["updateTime"])[1].replace("+",";"))[4])*60
else:
os.chdir(locapp)
if os.path.getsize("flw.txt")<3 or os.path.getsize("flwt.txt")<12:
if args.L=="en":
print("Unstable network or cache mode.")
print("Error: No Historical Cache. Program will exit in 5
seconds.")
else:
print("離線模式或網絡斷線。")
print("無可用歷史緩存。程序將於 5 秒後退出")
time.sleep(5)
exit()
if cself==False:
if args.L=="en":
print("Unstable network or cache mode. Please select a version.")
else:
print("離線模式或網絡斷線。請選擇版本")
with open("flwt.txt","r") as c1:
cflwt=c1.readlines()
del cflwt[0]
for cs in range(1,len(cflwt)+1):
print("%d: %d/%d/%d %d:%d:%d" %
(cs,datetime.datetime.fromtimestamp(int(float(cflwt[cs-
1].replace("\n","")))).day,datetime.datetime.fromtimestamp(int(float(cflwt[cs-
1].replace("\n","")))).month,datetime.datetime.fromtimestamp(int(float(cflwt[cs-
1].replace("\n","")))).year,datetime.datetime.fromtimestamp(int(float(cflwt[cs-
1].replace("\n","")))).hour,datetime.datetime.fromtimestamp(int(float(cflwt[cs-
1].replace("\n","")))).minute,datetime.datetime.fromtimestamp(int(float(cflwt[cs-
1].replace("\n","")))).day))
if cs%10==0:
input("ENTER")
try:
if args.L=="en":
cu=int(input("Input a number: "))
else:
cu=int(input("輸入一個數字: "))
except BaseException:
if args.L=="en":
print("Invaild Input. Using the newest.")
else:
print("無效輸入。將使用最新緩存。")
cfin=cs
cself=True
if (cu<1 or cu>cs) and cself==False:
if args.L=="en":
print("Invaild Input. Using the newest.")
else:
print("無效輸入。將使用最新緩存。")
cfin=cs
else:
cfin=cu
cself=True
with open("flwt.txt","r") as c2:
c2flw=c2.readlines()
for x in range(0,len(c2flw)):
try:
c2flw[x]=int(float(c2flw[x].replace("\n","")))
except BaseException:
pass
del c2flw[0]
timestmpc=c2flw[cfin-1]
with open("flwt.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
if langget=="en":
tfn=""
else:
tfn="tc"
with open("flw"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
flwjson=eval(co1list[c3count])
with open("fndt.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
c3count=-1
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
if c3count==-1:
for x in range(0,len(c3flw)):
if c3flw[x]>=timestmpc:
c3count=x
break
with open("fnd"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
fndjson=eval(co1list[c3count])
try:
with open("wst.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
with open("ws"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
wsjson=eval(co1list[c3count])
except BaseException:
wsjson={}
with open("rrt.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
with open("rr"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
rrjson=eval(co1list[c3count])
try:
with open("swtt.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
with open("swt"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
swtjson=eval(co1list[c3count])
except BaseException:
swtjson={}
with open("qemt.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
c3count=-1
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
if c3count==-1:
for x in range(0,len(c3flw)):
if c3flw[x]>=timestmpc:
c3count=x
break
with open("qem"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
qemjson=eval(co1list[c3count])
try:
with open("feqt.txt","r") as c3:
c3flw=c3.readlines()
for x in range(0,len(c3flw)):
try:
c3flw[x]=int(float(c3flw[x].replace("\n","")))
except BaseException:
pass
del c3flw[0]
for x in range(0,len(c3flw)):
if c3flw[x]<=timestmpc:
c3count=x
with open("feq"+tfn+".txt","r") as co1:
co1list=co1.readlines()
for x in range(0,len(co1list)):
co1list[x]=co1list[x].replace("\n","")
del co1list[0]
feqjson=eval(co1list[c3count])
except BaseException:
feqjson={}
last=timestmpc
last2=timestmpc
last3=timestmpc
last4=timestmpc
last5=timestmpc
last6=timestmpc
last7=timestmpc
try:
asf=float(openf("lasthhot.txt").read())
except BaseException:
asf=0
if checkneedhhot(asf)==True:
zxzx=hhotgdata()
if zxzx==False:
dt=cacheget(datetime.datetime.fromtimestamp(time.time()).year)
else:
savehhotdata()
if chkconn()!=200:
dt=cacheget(datetime.datetime.fromtimestamp(time.time()).year)
else:
dt=cacheget(datetime.datetime.fromtimestamp(time.time()).year)
flw.close()
flwtc.close()
fnd.close()
ws.close()
flwt.close()
fndt.close()
fndtc.close()
wst.close()
wstc.close()
rr.close()
rrt.close()
rrtc.close()
swt.close()
swtt.close()
swttc.close()
feq.close()
feqt.close()
feqtc.close()
hhot.close()
hhott.close()
os.chdir(locapp)
if os.path.getsize("flw.txt")>1048576000:
while os.path.getsize("flw.txt")>1048576000:
with open("flw.txt","r") as ff:
linesd=ff.readlines()
del linesd[0]
with open("flw.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("flwt.txt","r") as gg:
linese=gg.readlines()
del linesd[0]
with open("flwt.txt","w") as gg:
for gh in linese:
gg.write(gh)
with open("flwtc.txt","r") as hh:
linesd=hh.readlines()
del linesd[0]
with open("flwtc.txt","w") as hh:
for hi in linesd:
hh.write(hi)
while os.path.getsize("fnd.txt")>1048576000:
with open("fnd.txt","r") as ff:
linesd=ff.readlines()
del linesd[0]
with open("fnd.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("fndt.txt","r") as gg:
linese=gg.readlines()
del linesd[0]
with open("fndt.txt","w") as gg:
for gh in linese:
gg.write(gh)
with open("fndtc.txt","r") as hh:
linesd=hh.readlines()
del linesd[0]
with open("fndtc.txt","w") as hh:
for hi in linesd:
hh.write(hi)
while os.path.getsize("ws.txt")>1048576000:
with open("ws.txt","r") as ff:
linesd=ff.readlines()
del linesd[0]
with open("ws.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("wst.txt","r") as gg:
linese=gg.readlines()
del linesd[0]
with open("wst.txt","w") as gg:
for gh in linese:
gg.write(gh)
with open("wstc.txt","r") as hh:
linesd=hh.readlines()
del linesd[0]
with open("wstc.txt","w") as hh:
for hi in linesd:
hh.write(hi)
with open("feq.txt","r") as ff:
linesd=ff.readlines()
del linesd[0]
with open("feq.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("feqt.txt","r") as gg:
linese=gg.readlines()
del linesd[0]
with open("feqt.txt","w") as gg:
for gh in linese:
gg.write(gh)
with open("feqtc.txt","r") as hh:
linesd=hh.readlines()
del linesd[0]
with open("feqtc.txt","w") as hh:
for hi in linesd:
hh.write(hi)
while os.path.getsize("rr.txt")>1048576000:
with open("rr.txt","r") as ff:
linesd=ff.readlines()
del linesd[0]
with open("rr.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("rrt.txt","r") as gg:
linese=gg.readlines()
del linesd[0]
with open("rrt.txt","w") as gg:
for gh in linese:
gg.write(gh)
with open("rrtc.txt","r") as hh:
linesd=hh.readlines()
del linesd[0]
with open("rrtc.txt","w") as hh:
for hi in linesd:
hh.write(hi)
while os.path.getsize("qem.txt")>1048576000:
with open("qem.txt","r") as ff:
linesd=ff.readlines()
del linesd[0]
with open("qem.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("qemt.txt","r") as gg:
linese=gg.readlines()
del linesd[0]
with open("qemt.txt","w") as gg:
for gh in linese:
gg.write(gh)
with open("qemtc.txt","r") as hh:
linesd=hh.readlines()
del linesd[0]
with open("qemtc.txt","w") as hh:
for hi in linesd:
hh.write(hi)
while os.path.getsize("hhot.txt")>1048576000:
with open("hhot.txt","r") as ff:
linesd=ff.readlines()
with open("hhot.txt","w") as ff:
for fe in linesd:
ff.write(fe)
with open("hhott.txt","r") as gg:
linese=gg.readlines()
with open("hhott.txt","w") as gg:
for gh in linese:
gg.write(gh)
flw=openf("flw.txt")
flwt=openf("flwt.txt")
fnd=openf("fnd.txt")
fndt=openf("fndt.txt")
ws=openf("ws.txt")
wst=openf("wst.txt")
rr=openf("rr.txt")
rrt=openf("rrt.txt")
flwtc=openf("flwtc.txt")
fndtc=openf("fndtc.txt")
wstc=openf("wstc.txt")
rrtc=openf("rrtc.txt")
feq=openf("feq.txt")
feqt=openf("feqt.txt")
feqtc=openf("feqtc.txt")
hhot=openf("hhot.txt")
hhott=openf("hhott.txt")
os.chdir(nowcwd)
return [stc,flwjson,fndjson]
engdict={"generalSituation":"General Situation","tcInfo":"Tropical Cyclone
Information","fireDangerWarning":"Fire Danger Warning
Message","forecastPeriod":"Forecast Period","forecastDesc":"Forecast
Description","outlook":"Outlook","updateTime":"Update
Time","forecastWind":"Forecast Wind","forecastMaxtemp":"Forecast Maximum
Temperature","forecastMintemp":"Forecast Minimum
Temperature","all":"All","forecastDate":"Date","forecastWeather":"Forecast
Weather","temp":"Temperature","rh":"Relative Humidity","seaTemp":"Sea
Temperature","nas":"There is no warning in force","WFIRER":"Red Fire Danger
Warning","WFIREY":"Yellow Fire Danger Warning","WFROST":"Frost Warning","WHOT":"Hot
Weather Warning","WCOLD":"Cold Weather Warning","WMSGNL":"Strong Monsoon
Signal","WFNTSA":"Special Announcement on Flooding in the northern New
Territories","WL":"Landslip Warning","WTCSGNL":"Tropical Cyclone Warning
Signal","TC1":"Standby Signal No.1","TC3":"Strong Wind Signal No.3","TC8NE":"No.8
Northeast Gale or Storm Signal","TC8SE":"No.8 Southeast Gale or Storm
Signal","TC8SW":"No.8 Southwest Gale or Storm Signal","TC8NW":"No.8 Northwest Gale
or Storm Signal","TC9":"Increasing Gale or Storm Signal No.9","TC10":"Hurricane
Signal No.10","WTMW":"Tsunami Warning","WTS":"Thunderstorm Warning","WRAINA":"Amber
Rainstorm Warning Signal","WRAINR":"Red Rainstorm Warning Signal","WRAINB":"Black
Rainstorm Warning Signal","ISSUE":"had issued at %s","REISSUE":"had reissued at
%s","CANCEL":"had cancelled at %s","EXTEND":"had extended to %s","UPDATE":"had
updated at %s","expire":"will be expire at %s","ia":"issue at %s","rainfall":"From
%s to %s,differents area's rainfall:","maint":"Maintenance
Flag","desc":"Description","message":"Message","nswt":"There are no Special Weather
Tips.","desc2":"Tips Content","place":"Place","mag":"Richter magnitude
scale","region":"Region","ptime":"Earthquake date and time (GMT +8)","nqem":"No
Report.","intensity":"Intensity"}
tcgdict={"generalSituation":"概況","tcInfo":"熱帶氣旋資訊","fireDangerWarning":"火災危
險警告信息","forecastPeriod":"預測時段","forecastDesc":"預測內容","outlook":"展
望","updateTime":"更新時間","forecastWind":"預測風向風速","forecastMaxtemp":"預測最高溫
度","forecastMintemp":"預測最低溫度","all":"全部","forecastDate":"日
期","forecastWeather":"預測天氣","temp":"溫度","rh":"相對濕度","seaTemp":"海面溫
度","WFIRER":"紅色火災危險警告","WFIREY":"黃色火災危險警告","WFROST":"霜凍警告","WHOT":"酷
熱天氣警告","WCOLD":"寒冷天氣警告","WMSGNL":"強烈季候風信號","WFNTSA":"新界北部水浸特別報
告","WL":"山泥傾瀉警告","WTCSGNL":"熱帶氣旋警告信號","TC1":"一號戒備信號","TC3":"三號強風信
號","TC8NE":"八號東北烈風或暴風信號","TC8SE":"八號東南烈風或暴風信號","TC8SW":"八號西南烈風或
暴風信號","TC8NW":"八號西北烈風或暴風信號","TC9":"九號烈風或暴風風力增強信號","TC10":"十號颶
風信號","WTMW":"海嘯警告","WTS":"雷暴警告","nas":"現時並無警告生效。","WRAINA":"黃色暴雨警
告信號","WRAINR":"紅色暴雨警告信號","WRAINB":"黑色暴雨警告信號","ISSUE":"發佈
於%s","REISSUE":"重發佈於%s","CANCEL":"於%s 取消","EXTEND":"延長至%s","UPDATE":"在%s 時更
新","expire":"將於%s 到期","rainfall":"從%s 到%s,各地區的降雨量","maint":"分區站維修
中","desc":"強度","message":"信息","nswt":"現時並無特別天氣提示。","desc2":"提示內
容","place":"位置","mag":"芮氏地震規模","region":"地區","ptime":"地震發生時間及日
期","nqem":"現時沒有特別報告","intensity":"强度"}
ensdict={"flw":"Local Weather Forecast","fnd":"9-day Weather
Forecast","warnsum":"Weather Warning Summary","warninfo":"Warning
Information","lang":"Language","num":"Please select a number:
","all":"All","exit":"Exit"}
tcsdict={"flw":"本港地區天氣預報","fnd":"九天天氣預報 ","warnsum":"天氣警告一
覽","warninfo":"詳細天氣警告資訊","lang":"更換語言","num":"輸入一個數字: ","all":"全
部","exit":"離開"}
endict={"flw":"Local Weather Forecast","fnd":"9-day Weather
Forecast","rhrread":"Current Weather","warnsum":"Weather Warning
Summary","warninfo":"Warning Information","swt":"Special Weather
Tips","lang":"Language","num":"Please select a number: ","fp":"Weather
Information","all":"All","exit":"Exit","eq":"Earthquake Information","qem":"Quick
Eahquake Messages","feltearthquake":"Locally Felt Earth Tremor
Report","cwi":"Climate and Weather Information","hhot":"Hourly heights of tides"}
tcdict={"flw":"本港地區天氣預報","fnd":"九天天氣預報","rhrread":"本港地區天氣報
告","warnsum":"天氣警告一覽","warninfo":"詳細天氣警告資訊","swt":"特別天氣提示","lang":"更
換語言","num":"輸入一個數字: ","fp":"天氣資訊","all":"全部","exit":"離開","eq":"地震資
訊","qem":"地震速報","feltearthquake":"本地有感地震報告","cwi":"氣象及天氣資訊","hhot":"每
小時潮汐高度"}
def selectl(lang):
global dict1,dicts1,gdict
if lang=="en":
dict1=endict
dicts1=ensdict
gdict=engdict
else:
dict1=tcdict
dicts1=tcsdict
gdict=tcgdict
def dinit(l):
global dtd,stca
dtd=getdata(l)
stca=dtd[0]
dinit(args.L)
selectl(args.L)
langfin=args.L
loopf1=False
loopf2=False
loopf3=False
t1=time.time()
t2=t1
while True:
t1=time.time()
if t2+float(args.T)*60.0<=t1:
t2=t1
getdata(langfin)
if args.F!=True:
print("1:",dicts1['flw'],"\n2:",dicts1['fnd'],"\n3:",dicts1['warnsum'],"\n4:",dicts
1['warninfo'],"\n5:",dicts1['lang']) #select
try:
getinputx=int(input(dicts1["num"]))
except KeyboardInterrupt:
if langfin=='en':
print("Exited")
else:
print("已離開")
exit()
except BaseException:
getinputx=255
getinput=getinputx
else:
if loopf1==False and loopf2==False:
print("0:",dict1["lang"])
print("1:",dict1["fp"])
print("2:",dict1["eq"])
print("3:",dict1["cwi"]
try:
getinput00=int(input(dict1["num"]))
except KeyboardInterrupt:
if langfin=='en':
print("Exited")
else:
print("已離開")
exit()
except BaseException:
getinput00=255
if getinput00==255 or getinput00>3 or getinput00<0:
getinput=255
getinput102=255
elif getinput00==0:
getinput=5
elif getinput00==1:
loopf1=True
loopf2=False
loopf3=False
elif getinput00==2:
loopf1=False
loopf2=True
loopf3=False
elif getinput00==3:
loopf1=False
loopf2=False
loopf3=True
while loopf1:
print("1:",dict1["flw"])
print("2:",dict1["fnd"])
print("3:",dict1["rhrread"])
print("4:",dict1["warnsum"])
print("5:",dict1["warninfo"])
print("6:",dict1["swt"])
print("7:",dict1["exit"])
try:
getinput01=int(input(dict1["num"]))
except KeyboardInterrupt:
print("\n")
getinput102=0
getinput=256
loopf1=False
except BaseException:
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
if getinput01>7 or getinput01<0:
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
elif getinput01==7:
getinput102=0
getinput=256
loopf1=False
else:
getinput102=0
if getinput01<3:
getinput=getinput01
break
elif getinput01>3 and getinput01<6:
getinput=getinput01-1
break
elif getinput01==3:
getinput=0
getinput102=1
break
elif getinput01==6:
getinput=0
getinput102=2
break
while loopf2:
print("1:",dict1["qem"])
print("2:",dict1["feltearthquake"])
print("3:",dict1["exit"])
try:
getinputsubmenu2=int(input(dict1["num"]))
except KeyboardInterrupt:
loopf2=False
getinput=256
getinput102=0
print("\n")
break
except BaseException:
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
getinput=0
getinputsubmenu2=10
if getinputsubmenu2>3:
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
getinput=0
getinputsubmenu2=10
if getinputsubmenu2==1:
getinput102=3
getinput=0
break
elif getinputsubmenu2==2:
getinput102=4
getinput=0
break
elif getinputsubmenu2==3:
loopf2=False
getinput=256
getinput102=0
print("\n")
break
while loopf3:
print("1:",dict1["hhot"])
try:
getinputsubmenu3=int(input(dict1["num"]))
except KeyboardInterrupt:
loopf3=False
getinput=256
getinput102=0
getinput103=0
print("\n")
break
except BaseException:
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
getinput=256
getinput102=0
if getinput==1:
if flwjson["generalSituation"]!="":
print(gdict["generalSituation"]+":\n",flwjson["generalSituation"])
if flwjson["tcInfo"]!="":
print(gdict["tcInfo"]+":\n",flwjson["tcInfo"])
if flwjson["fireDangerWarning"]!="":
print(gdict["fireDangerWarning"]+":\n",flwjson["fireDangerWarning"])
print(gdict["forecastPeriod"]+":",flwjson["forecastPeriod"])
print(gdict["forecastDesc"]+":",flwjson["forecastDesc"])
if flwjson["outlook"]!="":
print(gdict["outlook"]+":",flwjson["outlook"])
print("\n")
elif getinput==5:
print("\n")
print("1: English\n2: 繁體中文")
sl=int(input(dicts1["num"]))
if sl==1:
langfin="en"
elif sl==2:
langfin="tc"
selectl(langfin)
dinit(langfin)
print("\n")
elif getinput==256:
pass
elif getinput==255 or getinput>5:
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
elif getinput==2:
tofloop=True
print("\n")
n=datetime.datetime.fromtimestamp(last)
if fndjson["generalSituation"]!="":
print(gdict["generalSituation"]+":\n",fndjson["generalSituation"])
while tofloop==True:
print("1: "+gdict["generalSituation"])
if langfin=="en":
print("2: Tomorrow")
else:
print("2: 明日")
for nx in range(3,11):
n=datetime.datetime.fromtimestamp(last+(nx-1)*86400)
print(str(nx)+": "+str(n.day)+"/"+str(n.month)+"/"+str(n.year))
print("11: "+dicts1["all"])
print("12: "+dicts1["exit"])
try:
getinput2=input(dicts1["num"])
except KeyboardInterrupt:
tofloop=False
getinput2=12
print("\n")
break
try:
getinput2=int(getinput2)
except BaseException:
print("\n")
if langfin=="en":
print("Invaild input. Please retry.")
else:
print("無效輸入,請重試。")
print("\n")
getinput2=255
if getinput2==255:
pass
elif getinput2==1:
print("\n")
print(gdict["generalSituation"]+":\n",fndjson["generalSituation"])
print("\n")
elif getinput2==12:
tofloop=False
elif getinput2==11:
print("\n")
for tx in range(0,9):
print(gdict["forecastDate"]+":",str(fndjson["weatherForecast"]
[tx]["forecastDate"])[:4]+'-'+str(fndjson["weatherForecast"][tx]["forecastDate"])
[4:][:2]+"-"+str(fndjson["weatherForecast"][tx]["forecastDate"])[6:]
[:2],fndjson["weatherForecast"][tx]["week"])
print(gdict["forecastWind"]+":",fndjson["weatherForecast"][tx]
["forecastWind"])
print(gdict["forecastWeather"]+":",fndjson["weatherForecast"]
[tx]["forecastWeather"])
print(gdict["temp"]+":",str(fndjson["weatherForecast"][tx]
["forecastMintemp"]["value"])+"-"+str(fndjson["weatherForecast"][tx]
["forecastMaxtemp"]["value"])+chr(176)+fndjson["weatherForecast"][tx]
["forecastMaxtemp"]["unit"])
print(gdict["rh"]+":",str(fndjson["weatherForecast"][tx]
["forecastMinrh"]["value"])+"-"+str(fndjson["weatherForecast"][tx]["forecastMaxrh"]
["value"])+"%")
print("\n")
if langfin=="en":
input("Press Enter To Continue")
elif langfin=="tc":
input("回車以繼續")
print("\n")
print(fndjson["seaTemp"]["place"]+gdict["seaTemp"]
+":",str(fndjson["seaTemp"]["value"])+chr(176)+fndjson["seaTemp"]["unit"])
print("\n")
elif getinput>=2 and getinput<=10:
print("\n")
tx=getinput2-2
print(gdict["forecastDate"]+":",str(fndjson["weatherForecast"][tx]
["forecastDate"])[:4]+'-'+str(fndjson["weatherForecast"][tx]["forecastDate"])[4:]
[:2]+"-"+str(fndjson["weatherForecast"][tx]["forecastDate"])[6:]
[:2],fndjson["weatherForecast"][tx]["week"])
print(gdict["forecastWind"]+":",fndjson["weatherForecast"][tx]
["forecastWind"])
print(gdict["forecastWeather"]+":",fndjson["weatherForecast"][tx]
["forecastWeather"])
print(gdict["temp"]+":",str(fndjson["weatherForecast"][tx]
["forecastMintemp"]["value"])+"-"+str(fndjson["weatherForecast"][tx]
["forecastMaxtemp"]["value"])+chr(176)+fndjson["weatherForecast"][tx]
["forecastMaxtemp"]["unit"])
print(gdict["rh"]+":",str(fndjson["weatherForecast"][tx]
["forecastMinrh"]["value"])+"-"+str(fndjson["weatherForecast"][tx]["forecastMaxrh"]
["value"])+"%")
print("\n")
elif getinput2==256:
pass
elif getinput==3:
if len([(k,v) for k,v in wsjson.items()])==0:
print("\n")
print(gdict["nas"])
print("\n")
else:
wsterm=[(k,v) for k,v in wsjson.items()]
nowterm=[]
for wsax in range(0,len(wsterm)):
if wsterm[wsax][1]["actionCode"]!="CANCEL":
nowterm.append((wsterm[wsax][1]["code"]))
else:
nowterm.remove((wsterm[wsax][1]["code"]))
print("\n")
if langfin=="en":
print("The following warnings are issued:")
print("\n")
for wsbx in range(0,len(nowterm)):
if wsbx==len(nowterm)-1:
com=""
else:
com=","
print(gdict[nowterm[wsbx]]+com)
if langfin=="tc":
print("\n")
print("正在生效")
print()
elif getinput==4:
if len([(k,v) for k,v in wsjson.items()])==0:
print("\n")
print(gdict["nas"])
print("\n")
else:
wsterm=[(k,v) for k,v in wsjson.items()]
term=[]
for wsax in range(0,len(wsterm)):
try:
term.append((((wsterm[wsax][1]["code"])),wsterm[wsax][1]
["actionCode"],wsterm[wsax][1]["issueTime"],wsterm[wsax][1]
["expireTime"],wsterm[wsax][1]["updateTime"]))
except KeyError:
term.append((((wsterm[wsax][1]["code"])),wsterm[wsax][1]
["actionCode"],wsterm[wsax][1]["issueTime"],-1,wsterm[wsax][1]["updateTime"]))
ind1=["WFIREY","WFIRER","WFROST","WHOT","WCOLD","WMSGNL","WRAINA","WRAINR","WRAINB"
,"WFNTSA","WL","TC1","TC3","TC8NE","TC8SE","TC8NW","TC8SW","TC9","TC10","WTMW","WTS
"]
firew=[]
frostw=[]
hotw=[]
coldw=[]
msgnl=[]
rain=[]
fntsa=[]
wl=[]
tcsg=[]
wtmw=[]
wts=[]
for wx1 in term:
for wy1 in range(0,len(ind1)):
if wx1[0]==ind1[wy1]:
if wy1==0 or wy1==1:
firew.append(wx1)
elif wy1==2:
frostw.append(wx1)
elif wy1==3:
hotw.append(wx1)
elif wy1==4:
coldw.append(wx1)
elif wy1==5:
msgnl.append(wx1)
elif wy1==6 or wy1==7 or wy1==8:
rain.append(wx1)
elif wy1==9:
fntsa.append(wx1)
elif wy1==10:
wl.append(wx1)
elif wy1>=11 and wy1<=18:
tcsg.append(wx1)
elif wy1==19:
wtmw.append(wx1)
elif wy1==20:
wts.append(wx1)
print("\n")
if len(firew)>0:
for wz1 in firew:
print(wz1)
if wz1[1]=="ISSUE":
print(gdict[wz1[0]],gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(frostw)>0:
for wz1 in frostw:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(hotw)>0:
for wz1 in hotw:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(coldw)>0:
for wz1 in coldw:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(msgnl)>0:
for wz1 in msgnl:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(rain)>0:
for wz1 in rain:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(fntsa)>0:
for wz1 in fntsa:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(wl)>0:
for wz1 in wl:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(tcsg)>0:
for wz1 in tcsg:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(wtmw)>0:
for wz1 in wtmw:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
if len(wts)>0:
for wz1 in wts:
if wz1[1]=="ISSUE":
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
else:
print(gdict[wz1[0]]+gdict[wz1[1]] %
str(wz1[4].replace("T"," ").replace("+"," UTC+"))+",",gdict["ia"] %
str(wz1[2].replace("T"," ").replace("+"," UTC+")))
print("\n")
elif getinput102==1 and getinput==0:
if "lightning" in rrjson:
print("\n")
if langfin=="en":
print("From %s to %s," % (rrjson["lightning"]
["startTime"],rrjson["lightning"]["endTime"]))
else:
print("從%s 到%s," % (rrjson["lightning"]
["startTime"],rrjson["lightning"]["endTime"]))
for lx in rrjson["lightning"]["data"]:
if lx["occur"]==True:
if langfin=="en":
print("%s had occur lightning" % lx["place"])
else:
print("%s 有閃電" % lx["place"])
if langfin=="en":
input("Press Enter to continue")
else:
input("回車以繼續")
print("\n")
print(gdict["rainfall"] % (rrjson["rainfall"]["startTime"]
[:19].replace("T"," "),rrjson["rainfall"]["endTime"][:19].replace("T"," ")))
for lx in rrjson["rainfall"]["data"]:
if lx["main"]=="TRUE":
print(lx["place"],gdict["maint"])
elif "max" in lx and "min" in lx:
print(lx["place"]+": %s-%s" % (lx["min"],lx["max"])+lx["unit"])
elif "max" in lx and not("min" in lx):
print(lx["place"]+(": %s" % lx["max"])+lx["unit"])
elif not("max" in lx) and "min" in lx:
print(lx["place"]+(": %s" % lx["min"])+lx["unit"])
if langfin=="en":
input("Press Enter to continue")
else:
input("回車以繼續")
if langfin=="en":
print("\nUV index\nPeriod:%s\nPlace:%s\nValue:%d\n%s:%s"%
(rrjson["uvindex"]["recordDesc"],rrjson["uvindex"]["data"][0]
["place"],rrjson["uvindex"]["data"][0]["value"],gdict["desc"],rrjson["uvindex"]
["data"][0]["desc"]))
input("Press Enter to continue")
else:
print("\n 紫外線強度\n 時段:%s\n 位置:%s\n 數值:%d\n%s:%s"%(rrjson["uvindex"]
["recordDesc"],rrjson["uvindex"]["data"][0]["place"],rrjson["uvindex"]["data"][0]
["value"],gdict["desc"],rrjson["uvindex"]["data"][0]["desc"]))
input("回車以繼續")
if rrjson["warningMessage"]!="":
if langfin=="en":
print("Warning Message:",rrjson["warningMessage"])
input("Press Enter to continue")
else:
print("警告信息:",rrjson["warningMessage"])
input("回車以繼續")
print("\n")
if "mintempFrom00To09" in rrjson:
if rrjson["mintempFrom00To09"]!="":
if langfin=="en":
print("The minimum tempurature from midnight to 9
o'clock:",rrjson["mintempFrom00To09"])
else:
print("午夜至上午九時的最低溫度:",rrjson["mintempFrom00To09"])
print("\n")
if "rainfallFrom00To12" in rrjson:
if rrjson["rainfallFrom00To12"]!="":
if langfin=="en":
print("Accumulated rainfall at HKO from midnight to
noon:",rrjson["rainfallFrom00To12"])
else:
print("香港天文台從午夜至中午累計降雨
量:",rrjson["rainfallFrom00To12"])
print("\n")
if "rainfallLastMonth" in rrjson:
if rrjson["rainfallLastMonth"]!="":
if langfin=="en":
print("The total rainfall in last
month:",rrjson["rainfallLastMonth"])
else:
print("上個月降雨量:",rrjson["rainfallLastMonth"])
print("\n")
if "rainfallJanuaryToLastMonth" in rrjson:
if rrjson["rainfallJanuaryToLastMonth"]!="":
if langfin=="en":
print("Accumulated rainfall from January to last
month:",rrjson["mintempFrom00To09"])
else:
print("一月至上月累計降雨量:",rrjson["mintempFrom00To09"])
print("\n")
if langfin=="en":
print("Temperature: ")
else:
print("各區溫度: ")
for rz in range(0,len(rrjson["temperature"]["data"])):
print(rrjson["temperature"]["data"][rz]["place"]
+":",str(rrjson["temperature"]["data"][rz]["value"])+chr(176)+rrjson["temperature"]
["data"][rz]["unit"])
if langfin=="en":
input("Press Enter to continue")
else:
input("回車以繼續")
print("\n")
if langfin=="en":
print("Relative Humidity:",str(rrjson["humidity"]["data"][0]["value"])
+"%")
else:
print("相對濕度:",str(rrjson["humidity"]["data"][0]["value"])+"%")
elif getinput102==2 and getinput==0 and getinput!=256:
print("\n")
if swtjson=={} or swtjson=={"swt":[]}:
print(gdict["nswt"])
else:
print(gdict["desc2"]+":",swtjson["desc"])
print(gdict["updateTime"]+":",swtjson["updateTime"]
[:10],swtjson["updateTime"][14:][:8])
print("\n")
elif getinput102==3 and getinput==0:
print("\n")
print(gdict["place"]+": (%f,%f)"%(qemjson["lon"],qemjson["lat"]))
print(gdict["mag"]+":",qemjson["mag"])
print(gdict["region"]+":",qemjson["region"])
qemt=qemjson["ptime"]
qemt=qemt.replace("+","-")
qemta=re.split("-|:|T",qemt)
monthr={1:31,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,0:31,12:31}
monthneg=[12,1,2,3,4,5,6,7,8,9,10,11]
for qemx in range(0,len(qemta)):
qemta[qemx]=int(qemta[qemx])
qemta[4]=qemta[4]-qemta[7]
qemta[3]=qemta[3]-qemta[6]
if qemta[4]<0:
qemta[4]=qemta[4]+60
qemta[3]=qemta[3]-1
qemta[3]=qemta[3]+8
if qemta[3]<0:
qemta[3]=qemta[3]+24
qemta[2]=qemta[2]-1
if qemta[2]<0:
if qemta[1]-1!=2:
qemta[2]=qemta[2]+monthr[qemta[1]-1]
qemta[1]=qemta[1]-1
else:
qemta[1]=qemta[1]-1
if ((qemta[0]%4==0 and qemta[0]%100!=0) or (qemta[0]%400==0 and
qemta[0]%4000!=0)):
qemta[2]=qemta[2]+29
else:
qemta[2]=qemta[2]+28
if qemta[1]<1:
qemta[1]=monthneg[qemta[1]]
qemta[0]=qemta[0]-1
if qemta[3]==0:
qemta[3]="00"
if qemta[4]==0:
qemta[4]="00"
if qemta[5]==0:
qemta[5]="00"
print(gdict["ptime"]+":","%s/%s/%s %s:%s:%s"%
(qemta[0],qemta[1],qemta[2],qemta[3],qemta[4],qemta[5]))
print(gdict["updateTime"]+":",qemjson["updateTime"])
print("\n")
elif getinput102==4 and getinput==0:
if feqjson=={}:
print(gdict["nqem"])
else:
print("\n")
print(gdict["place"]+":(%s,%s)"%(feqjson["lon"],feqjson["lat"]))
print(gdict["mag"]+":",feqjson["mag"])
print(gdict["region"]+":",feqjson["region"])
print(gdict["ptime"]+":",feqjson["ptime"][:19])
print(gdict["details"]+":",feqjson["details"])
print(gdict["updateTime"]+":",feqjson["updateTime"])
print("\n")