Download the entire radar puzzle for a certain area of the day
1 #!/usr/bin/env Python32 #-*-coding:utf-8-*-3Quyu = {'Tohoku':'ANEC','North China':'ANCN','East China':'AECN','Central China':'ACCN',4 'South China':'ASCN','Southwest':'ASWC','Northwest':'ANWC','Changjiang':'ABCJ',5 'Huang Huai':'abhh','Southeast Coast':'ACES','National':'ACHN'}6 7 8 defGetrenderpic (year, month, day, region):9 " "Ten Download the entire radar puzzle for a certain area of the day One Call: Getrenderpic (2015, 12, 23, ' East China ') A " " - ImportRequests - ImportOS the Import Time -now =time.localtime () - if(year, month, day) > (now[0], now[1], now[2]): - Print('Date Error') + return - ifRegion not inchQuyu: + Print('Zone Error, availability zone:') A Print(Quyu.keys ()) at return -Date = str (year) + STR (month). Zfill (2) + str (day). Zfill (2) -Dirc ='/home/td/desktop/radar/'+ Date +'/'+ Region#Modify the picture storage directory here - Try: - os.makedirs (DIRC) - except: in Pass - Os.chdir (DIRC) to ifDay = = Now[2]: +Flag =True - forhhinchRange (0, 24): the forMminchRange (0, 51, 10): * ifflag: $ if(hh = = Now[3] andmm > Now[4])orHH > Now[3]:Panax Notoginseng return -Time = str (hh). Zfill (2) + str (mm). Zfill (2) theURL ='http://www.moc.cma.gov.cn/mocimg/radar/mosaic/' ++ Quyu[region] +'/qref/'+ STR (YEAR) +'/'+ STR (month). Zfill (2) A+'/'+ STR (day). Zfill (2) +'/'+ Quyu[region] +'. QREF000.' the+ Date +'.'+ Time +'00.GIF' + Print(URL) -Pic =requests.get (URL) $fp = open (date + time +'xx'+'. gif','WB') $ fp.write (pic.content) - fp.close () - the if __name__=='__main__': -Getrenderpic (2015, 12, 23,'East China')
Just tried a bit today's East China radar, downloaded more than 100 pictures.
Python Download area radar puzzle