使用 Flask 微框架用 Python 編寫的微服務。
程式碼經過重新組織,使其能夠更輕鬆地在 AWS 的 Elastic Beanstalk 服務上運行。
與之前版本相比的變化是:
您可以在名為“prevCodeOrganization”的分支中找到先前程式碼的凍結版本
很多人使用 NASA 建立的這個 API 的實例。如果您需要此 API 的極其可靠的版本,您可能想要建立自己的 API 版本。你可以用這段程式碼做到這一點!該 API 傳回的所有資訊實際上只是從每日天文照片網站 (APOD) 中取得。
沒有人觀看此儲存庫與每日天文照片網站有任何關係,因此我們無法處理與其內容直接相關的問題。請直接聯絡他們。
virtualenv
環境conda
環境git clone https://github.com/nasa/apod-api
cd
進入新目錄 cd apod-api
lib
中pip install -r requirements.txt -t lib
lib
加入到 PYTHONPATH 並運行伺服器PYTHONPATH=./lib python application.py
virtualenv
環境git clone https://github.com/nasa/apod-api
cd
進入新目錄 cd apod-api
env
python -m venv venv
. v env S cripts A ctivate
pip install -r requirements.txt
python application.py
conda
環境git clone https://github.com/nasa/apod-api
cd
進入新目錄 cd apod-api
env
conda create --prefix ./env
conda activate ./env
pip install -r requirements.txt
python application.py
git clone https://github.com/nasa/apod-api.git
cd
進入新目錄 cd apod-api
docker build . -t apod-api
docker run -p 5000:5000 apod-api
/<version>/apod
此服務中只有一個端點,它採用 2 個可選欄位作為 http GET 請求的參數。名義上回傳一個 JSON 字典。
api_key
|演示: DEMO_KEY
| https://api.nasa.gov/#signUpdate
YYYY-MM-DD 格式的字串,指示 APOD 影像的日期(例如:2014-11-03)。預設為今天的日期。必須是在 1995 年 6 月 16 日之後,APOD 圖片發布的第一天。沒有透過此 API 提供明天的圖像。concept_tags
布林值True|False
指示概念標籤是否應與回應的其餘部分一起傳回。概念標籤不一定包含在解釋中,而是源自於與描述文字相關聯的常見搜尋標籤。 (比純文字搜尋更好。)預設為 False。hd
一個布林值True|False
參數,指示是否應傳回高解析度影像。這是為了遺留目的而存在的,它總是被服務忽略,並且無論如何都會返回高解析度的 URL。count
一個正count
,不大於 100。不能與date
或start_date
和end_date
一起使用。start_date
YYYY-MM-DD 格式的字串,指示日期範圍的開始時間。從start_date
到end_date
範圍內的所有影像都會以 JSON 陣列形式傳回。不能與date
一起使用。end_date
YYYY-MM-DD 格式的字串,指示日期範圍的結束日期。如果指定start_date
而沒有end_date
,則end_date
預設為目前日期。thumbs
布林參數True|False
指示 API 是否應傳回視訊檔案的縮圖 URL。如果設定為True
,API 將傳回影片縮圖的 URL。如果 APOD 不是視頻,則忽略此參數。傳回字段
resource
描述反應說明的image_set
或planet
字典,完全由結構化端點決定。concept_tags
提供選項的布林值反映。由於預設值而包含在回應中。title
圖像的標題。date
影像的日期。由於預設值而包含在回應中。url
當天 APOD 圖片或影片的 URL。hdurl
當天任何高解析度圖像的 URL。無論「hd」參數設定如何,都會傳回,但如果 APOD 中最初不存在該參數,則在回應中將被省略。media_type
傳回的媒體(資料)的類型。根據內容可以是“圖像”或“視訊”。explanation
提供的圖像文字解釋。concepts
文本解釋中最相關的概念。僅當concept_tags
設定為 True 時才提供。thumbnail_url
影片縮圖的 URL。copyright
版權所有者的姓名。service_version
使用的服務版本。例子
localhost:5000/v1/apod ? api_key=DEMO_KEY & date=2014-10-01 & concept_tags=True
{
resource : {
image_set : "apod"
},
concept_tags : "True" ,
date : "2013-10-01" ,
title : "Filaments of the Vela Supernova Remnant" ,
url : "http://apod.nasa.gov/apod/image/1310/velafilaments_jadescope_960.jpg" ,
explanation : "The explosion is over but the consequences continue. About eleven
thousand years ago a star in the constellation of Vela could be seen to explode,
creating a strange point of light briefly visible to humans living near the
beginning of recorded history. The outer layers of the star crashed into the
interstellar medium, driving a shock wave that is still visible today. A roughly
spherical, expanding shock wave is visible in X-rays. The above image captures some
of that filamentary and gigantic shock in visible light. As gas flies away from the
detonated star, it decays and reacts with the interstellar medium, producing light
in many different colors and energy bands. Remaining at the center of the Vela
Supernova Remnant is a pulsar, a star as dense as nuclear matter that rotates
completely around more than ten times in a single second." ,
concepts : {
0 : "Astronomy" ,
1 : "Star" ,
2 : "Sun" ,
3 : "Milky Way" ,
4 : "Hubble Space Telescope" ,
5 : "Earth" ,
6 : "Nebula" ,
7 : "Interstellar medium"
}
}
https://api.nasa.gov/planetary/apod ? api_key=DEMO_KEY & count=5
[
{
"copyright" : "Panther Observatory" ,
"date" : "2006-04-15" ,
"explanation" : "In this stunning cosmic vista, galaxy M81 is on the left surrounded by blue spiral arms. On the right marked by massive gas and dust clouds, is M82. These two mammoth galaxies have been locked in gravitational combat for the past billion years. The gravity from each galaxy dramatically affects the other during each hundred million-year pass. Last go-round, M82's gravity likely raised density waves rippling around M81, resulting in the richness of M81's spiral arms. But M81 left M82 with violent star forming regions and colliding gas clouds so energetic the galaxy glows in X-rays. In a few billion years only one galaxy will remain." ,
"hdurl" : "https://apod.nasa.gov/apod/image/0604/M81_M82_schedler_c80.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Galaxy Wars: M81 versus M82" ,
"url" : "https://apod.nasa.gov/apod/image/0604/M81_M82_schedler_c25.jpg"
},
{
"date" : "2013-07-22" ,
"explanation" : "You are here. Everyone you've ever known is here. Every human who has ever lived -- is here. Pictured above is the Earth-Moon system as captured by the Cassini mission orbiting Saturn in the outer Solar System. Earth is the brighter and bluer of the two spots near the center, while the Moon is visible to its lower right. Images of Earth from Saturn were taken on Friday. Quickly released unprocessed images were released Saturday showing several streaks that are not stars but rather cosmic rays that struck the digital camera while it was taking the image. The above processed image was released earlier today. At nearly the same time, many humans on Earth were snapping their own pictures of Saturn. Note: Today's APOD has been updated." ,
"hdurl" : "https://apod.nasa.gov/apod/image/1307/earthmoon2_cassini_946.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Earth and Moon from Saturn" ,
"url" : "https://apod.nasa.gov/apod/image/1307/earthmoon2_cassini_960.jpg"
},
{
"copyright" : "Joe Orman" ,
"date" : "2000-04-06" ,
"explanation": "Rising before the Sun on February 2nd, astrophotographer Joe Orman anticipated this apparition of the bright morning star Venus near a lovely crescent Moon above a neighbor's house in suburban Phoenix, Arizona, USA. Fortunately, the alignment of bright planets and the Moon is one of the most inspiring sights in the night sky and one that is often easy to enjoy and share without any special equipment. Take tonight, for example. Those blessed with clear skies can simply step outside near sunset and view a young crescent Moon very near three bright planets in the west Jupiter, Mars, and Saturn. Jupiter will be the unmistakable brightest star near the Moon with a reddish Mars just to Jupiter's north and pale yellow Saturn directly above. Of course, these sky shows create an evocative picture but the planets and Moon just appear to be near each other -- they are actually only approximately lined up and lie in widely separated orbits. Unfortunately, next month's highly publicized alignment of planets on May 5th will be lost from view in the Sun's glare but such planetary alignments occur repeatedly and pose no danger to planet Earth.",
"hdurl" : "https://apod.nasa.gov/apod/image/0004/vm_orman_big.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Venus, Moon, and Neighbors" ,
"url" : "https://apod.nasa.gov/apod/image/0004/vm_orman.jpg"
},
{
"date" : "2014-07-12" ,
"explanation": "A new star, likely the brightest supernova in recorded human history, lit up planet Earth's sky in the year 1006 AD. The expanding debris cloud from the stellar explosion, found in the southerly constellation of Lupus, still puts on a cosmic light show across the electromagnetic spectrum. In fact, this composite view includes X-ray data in blue from the Chandra Observatory, optical data in yellowish hues, and radio image data in red. Now known as the SN 1006 supernova remnant, the debris cloud appears to be about 60 light-years across and is understood to represent the remains of a white dwarf star. Part of a binary star system, the compact white dwarf gradually captured material from its companion star. The buildup in mass finally triggered a thermonuclear explosion that destroyed the dwarf star. Because the distance to the supernova remnant is about 7,000 light-years, that explosion actually happened 7,000 years before the light reached Earth in 1006. Shockwaves in the remnant accelerate particles to extreme energies and are thought to be a source of the mysterious cosmic rays.",
"hdurl" : "https://apod.nasa.gov/apod/image/1407/sn1006c.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "SN 1006 Supernova Remnant" ,
"url" : "https://apod.nasa.gov/apod/image/1407/sn1006c_c800.jpg"
},
{
"date" : "1997-01-21" ,
"explanation": "In Jules Verne's science fiction classic A Journey to the Center of the Earth, Professor Hardwigg and his fellow explorers encounter many strange and exciting wonders. What wonders lie at the center of our Galaxy? Astronomers now know of some of the bizarre objects which exist there, like vast dust clouds,r bright young stars, swirling rings of gas, and possibly even a large black hole. Much of the Galactic center region is shielded from our view in visible light by the intervening dust and gas. But it can be explored using other forms of electromagnetic radiation, like radio, infrared, X-rays, and gamma rays. This beautiful high resolution image of the Galactic center region in infrared light was made by the SPIRIT III telescope onboard the Midcourse Space Experiment. The center itself appears as a bright spot near the middle of the roughly 1x3 degree field of view, the plane of the Galaxy is vertical, and the north galactic pole is towards the right. The picture is in false color - starlight appears blue while dust is greenish grey, tending to red in the cooler areas.",
"hdurl" : "https://apod.nasa.gov/apod/image/9701/galcen_msx_big.gif" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Journey to the Center of the Galaxy rn Credit:" ,
"url" : "https://apod.nasa.gov/apod/image/9701/galcen_msx.jpg"
}
]
https://api.nasa.gov/planetary/apod ? api_key=DEMO_KEY & start_date=2017-07-08 & end_date=2017-07-10
[
{
"copyright" : "T. Rector" ,
"date" : "2017-07-08" ,
"explanation" : "Similar in size to large, bright spiral galaxies in our neighborhood, IC 342 is a mere 10 million light-years distant in the long-necked, northern constellation Camelopardalis. A sprawling island universe, IC 342 would otherwise be a prominent galaxy in our night sky, but it is hidden from clear view and only glimpsed through the veil of stars, gas and dust clouds along the plane of our own Milky Way galaxy. Even though IC 342's light is dimmed by intervening cosmic clouds, this sharp telescopic image traces the galaxy's own obscuring dust, blue star clusters, and glowing pink star forming regions along spiral arms that wind far from the galaxy's core. IC 342 may have undergone a recent burst of star formation activity and is close enough to have gravitationally influenced the evolution of the local group of galaxies and the Milky Way." ,
"hdurl" : "https://apod.nasa.gov/apod/image/1707/ic342_rector2048.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Hidden Galaxy IC 342" ,
"url" : "https://apod.nasa.gov/apod/image/1707/ic342_rector1024s.jpg"
},
{
"date" : "2017-07-09" ,
"explanation" : "Can you find your favorite country or city? Surprisingly, on this world-wide nightscape, city lights make this task quite possible. Human-made lights highlight particularly developed or populated areas of the Earth's surface, including the seaboards of Europe, the eastern United States, and Japan. Many large cities are located near rivers or oceans so that they can exchange goods cheaply by boat. Particularly dark areas include the central parts of South America, Africa, Asia, and Australia. The featured composite was created from images that were collected during cloud-free periods in April and October 2012 by the Suomi-NPP satellite, from a polar orbit about 824 kilometers above the surface, using its Visible Infrared Imaging Radiometer Suite (VIIRS)." ,
"hdurl" : "https://apod.nasa.gov/apod/image/1707/EarthAtNight_SuomiNPP_3600.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Earth at Night" ,
"url" : "https://apod.nasa.gov/apod/image/1707/EarthAtNight_SuomiNPP_1080.jpg"
},
{
"date" : "2017-07-10" ,
"explanation" : "What's happening around the center of this spiral galaxy? Seen in total, NGC 1512 appears to be a barred spiral galaxy -- a type of spiral that has a straight bar of stars across its center. This bar crosses an outer ring, though, a ring not seen as it surrounds the pictured region. Featured in this Hubble Space Telescope image is an inner ring -- one that itself surrounds the nucleus of the spiral. The two rings are connected not only by a bar of bright stars but by dark lanes of dust. Inside of this inner ring, dust continues to spiral right into the very center -- possibly the location of a large black hole. The rings are bright with newly formed stars which may have been triggered by the collision of NGC 1512 with its galactic neighbor, NGC 1510." ,
"hdurl" : "https://apod.nasa.gov/apod/image/1707/NGC1512_Schmidt_1342.jpg" ,
"media_type" : "image" ,
"service_version" : "v1" ,
"title" : "Spiral Galaxy NGC 1512: The Nuclear Ring" ,
"url" : "https://apod.nasa.gov/apod/image/1707/NGC1512_Schmidt_960.jpg"
}
]
如果您要重新顯示圖像,您可能需要檢查是否有版權。任何沒有版權回傳欄位的內容通常都是 NASA 的且屬於公共領域。請參閱每日天文照片主網站上的「關於圖像權限」部分以了解更多資訊。
APOD 解析器不是 API 本身的一部分。 rather 旨在透過 Python 快速存取 APOD API,而無需您自己編寫太多額外程式碼。它可以在 apod_parser 資料夾中找到。
首先導入apod_object_parser.py
檔。
現在使用get_data
函數並將您的 API 金鑰作為唯一參數傳遞。您可以在此處取得 API 金鑰
response = apod_object_parser . get_data ( < your_api_key > )
-> apod_object_parser.get_date(response)
-> apod_object_parser.get_explaination(response)
-> apod_object_parser.get_hdurl(response)
-> apod_object_parser.get_media_type(response)
-> apod_object_parser.get_service_version(response)
-> apod_object_parser.get_title(response)
-> apod_object_parser.get_url(response)
有關完整文件和更多功能,請按一下此處存取 apod 解析器的自述文件
該API的部署版本是基於eb
分支。先前部署的版本位於eb_previous
分支中。 master
分支用作開發,因為無論如何,大多數拉取請求都會進入主分支。
由於使用該服務的人數較多,因此該 API 使用 Elastic beanstalk 部署在 AWS 上。但是,如果您打算自己使用它,它足夠小,可以安裝在單一微型 EC2 或任何其他小型雲端電腦上。
如果您發現此儲存庫有用,請為其加註星標。使用 github 問題追蹤器提供有關此儲存庫的回饋。
我們確實接受公眾的拉取請求。請注意,我們的回覆可能會很慢。請耐心等待。
而且,擁有該儲存庫權限的人並不是能夠調試 APOD 網站本身問題的人。如果您願意做出貢獻,現在我們可以對測試進行一些關注。