python 기상 망 위성 사진
https://github.com/MrWayneLee/weather-demo
코드 부분
파일 생 성 기능 다운로드
#
def downloadImg(imgDate, imgURLs, pathName):
a,s,f = 0,0,0
timeStart = time.time()
while a < len(imgURLs):
req = requests.get(imgURLs[a])
imgName = str(imgURLs[a])[-13:-9]
print(str(" " + imgDate + " " + imgName + " "))
if req.status_code == 200:
open(pathName + '\\' + os.path.basename(imgName) + '.png', 'wb').write(req.content)
print(" " + imgDate + " " + imgName + " ")
s += 1
del req
elif req.status_code == 404:
print(" " + imgDate + " " + imgName + " ")
f += 1
a += 1
timeEnd = time.time()
totalTime = round(timeEnd - timeStart, 2)
print(" ! :",totalTime," ")
print(" ", a, " ; ", s, " ; ", f, " ")
폴 더 만 들 기
def createFolder(pathName):
imgName_Year = pathName[0:4]
imgName_Month = pathName[4:6]
imgName_Day = pathName[6:8]
imgName_date = imgName_Year + '-' + imgName_Month + '-' + imgName_Day
mainPath = 'F:\\[Wayne Lee]\\ \\Python\\ '
newPathName = mainPath + '\\' + imgName_date
realPath = newPathName + '\\'
isExists = os.path.exists(newPathName)
if not isExists:
os.makedirs(newPathName)
print(" [" + imgName_date + "] ")
return realPath
else:
print(pathName + " ")
return realPath
시간 목록 생 성
def generateTime(imgUrl):
timeList = []
imgUrlList = []
h,j = 0,0
while h < 24:
m = 0
while m < 60:
timeList.append("{:0>4d}".format(h * 100 + m))
m += 15
h += 1
# print(timeList)
# print(len(timeList))
while j < len(timeList):
imgUrlList.append(str(imgUrl + timeList[j] + "00000.JPG"))
# print(timeList[j])
j += 1
return imgUrlList
# print(imgUrlList)
# print(len(imgUrlList))
다운로드 URL 목록 생 성
def downloadUrl(imgDate):
imgUrl = "http://image.nmc.cn/product/" + imgDate[0:4] + "/" + imgDate[4:6] + "/" + imgDate[6:8] + "/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_" + imgDate # + "0000" +"00000.JPG"
URLlist = list(generateTime(imgUrl))
return URLlist
주 함수
#
if __name__ == '__main__':
# imgUrl = "http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411044500000.JPG"
# imgUrl = "http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411"
# imgName = imgUrl[-21:-9]
while True:
print("[1] ")
print("[2] ")
print("[3] ")
choose = str(input(" :"))
if choose == "1":
imgDate = str(input(" [ 20200411]:"))
urlList = list(downloadUrl(imgDate))
break
elif choose == "2":
imgDate = time.strftime("%Y%m%d",time.localtime())
urlList = list(downloadUrl(imgDate))
break
elif choose == "3":
break
else:
print(" ! ")
다운로드 시작
pathName = createFolder(imgDate)
#
downloadImg(imgDate, urlList, pathName)
전체 코드
import requests
import time
import datetime
import os
#
def downloadImg(imgDate, imgURLs, pathName):
a,s,f = 0,0,0
timeStart = time.time()
while a < len(imgURLs):
req = requests.get(imgURLs[a])
imgName = str(imgURLs[a])[-13:-9]
print(str(" " + imgDate + " " + imgName + " "))
if req.status_code == 200:
open(pathName + '\\' + os.path.basename(imgName) + '.png', 'wb').write(req.content)
print(" " + imgDate + " " + imgName + " ")
s += 1
del req
elif req.status_code == 404:
print(" " + imgDate + " " + imgName + " ")
f += 1
a += 1
timeEnd = time.time()
totalTime = round(timeEnd - timeStart, 2)
print(" ! :",totalTime," ")
print(" ", a, " ; ", s, " ; ", f, " ")
#
def createFolder(pathName):
imgName_Year = pathName[0:4]
imgName_Month = pathName[4:6]
imgName_Day = pathName[6:8]
imgName_date = imgName_Year + '-' + imgName_Month + '-' + imgName_Day
mainPath = 'F:\\[Wayne Lee]\\ \\Python\\ '
newPathName = mainPath + '\\' + imgName_date
realPath = newPathName + '\\'
isExists = os.path.exists(newPathName)
if not isExists:
os.makedirs(newPathName)
print(" [" + imgName_date + "] ")
return realPath
else:
print(pathName + " ")
return realPath
#
def generateTime(imgUrl):
timeList = []
imgUrlList = []
h,j = 0,0
while h < 24:
m = 0
while m < 60:
timeList.append("{:0>4d}".format(h * 100 + m))
m += 15
h += 1
# print(timeList)
# print(len(timeList))
while j < len(timeList):
imgUrlList.append(str(imgUrl + timeList[j] + "00000.JPG"))
# print(timeList[j])
j += 1
return imgUrlList
# print(imgUrlList)
# print(len(imgUrlList))
# URL
def downloadUrl(imgDate):
imgUrl = "http://image.nmc.cn/product/" + imgDate[0:4] + "/" + imgDate[4:6] + "/" + imgDate[6:8] + "/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_" + imgDate # + "0000" +"00000.JPG"
URLlist = list(generateTime(imgUrl))
return URLlist
#
if __name__ == '__main__':
# imgUrl = "http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411044500000.JPG"
# imgUrl = "http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411"
# imgName = imgUrl[-21:-9]
while True:
print("[1] ")
print("[2] ")
print("[3] ")
choose = str(input(" :"))
if choose == "1":
imgDate = str(input(" [ 20200411]:"))
urlList = list(downloadUrl(imgDate))
break
elif choose == "2":
imgDate = time.strftime("%Y%m%d",time.localtime())
urlList = list(downloadUrl(imgDate))
break
elif choose == "3":
break
else:
print(" ! ")
#
pathName = createFolder(imgDate)
#
downloadImg(imgDate, urlList, pathName)
효과이상 은 python 이 날씨 망 위성 사진 을 기어 오 르 는 상세 한 내용 입 니 다.python 이 날씨 망 사진 을 기어 오 르 는 것 에 관 한 자 료 는 우리 의 다른 관련 글 을 주목 하 세 요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.