python 用于从NASA的Solar Dynamics Observatory(SDO)RSS feed下载最新图像的Python脚本。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用于从NASA的Solar Dynamics Observatory(SDO)RSS feed下载最新图像的Python脚本。相关的知识,希望对你有一定的参考价值。

# GetSDO.py
#
# A basic Python script to download the latest image from NASA's Solar Dynamics
# Observatory RSS feed.
#
# I use it to set the screensaver image source on my Mac
#
# More 'advanced' development will continue at: https://github.com/mint5auce/getSDO
#
# Requires: Universal Feed Parser (https://github.com/kurtmckee/feedparser
# / https://pythonhosted.org/feedparser/)
#
# Based on BigPicture.py by: Henry Cooke (me@prehensile.co.uk)
# https://gist.github.com/prehensile/675906

import feedparser
import urllib2

import os
import datetime

# Feed Config
fdir = '/Users/jonh/Pictures/sdo-feed/'
sdo_rss_root = 'http://feeds.feedburner.com/nasa/'
sdo_rss_views = ['aia_131', 'aia_171', 'aia_193', 'aia_211', 'aia_304', 'aia_335', 'aia_1700'] # Pretty ones only + 1700 for sun spots

# File and date config
today = datetime.date.today().strftime("%Y%m%d")
purgeday = (datetime.date.today() - datetime.timedelta(days=8)).strftime("%Y%m%d")
sdofiles = [f for f in os.listdir(fdir) if os.path.isfile(os.path.join(fdir, f))]
sdofiles.remove('.DS_Store')

# Parse RSS
# Get first image from each seperate type
for view in sdo_rss_views:
    sdo_rss = sdo_rss_root + view + '?format=xml'
    feed = feedparser.parse( sdo_rss )
    items = feed[ "items" ]
    url = items[0]['media_content'][0]['url'] # Just get first item

    # Download image
    try:
            data = urllib2.urlopen( url ).read()
            fname = view + '_' + url.split('/')[-1] # Feed images use same name, hence prefix
            fout = fdir+fname
            # @TODO: Don't download again if it exisits
            if fname not in sdofiles:
                output = open( fout, 'wb' )
                output.write( data )
                output.close()
                print 'File downloaded: ', fname
            else:
                print 'File skipped: ', fname
    except:
            print 'URL error: ', url
            pass

以上是关于python 用于从NASA的Solar Dynamics Observatory(SDO)RSS feed下载最新图像的Python脚本。的主要内容,如果未能解决你的问题,请参考以下文章

用 Python 监控 NASA TV 直播画面

sql [CreateTableFromFieldListIncludingTypes]从字段列表创建表动态地包括类型,比例和精度#table #create #dyna

细节!从solar winds黑客入侵事件中看供应链安全

未处理的异常:从 jsonplaceholder.typecode.com/photos 获取 Json 时,类型“List<dynamic>”不是“Map<String, dyna

ATLAS/ICESAT-2 NASA 数据产品详细介绍及相关说明文档

ATLAS/ICESAT-2 NASA 数据产品详细介绍及相关说明文档