Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
add new section picture of the day
Browse files Browse the repository at this point in the history
add new module nasa client
add visitors in today badge
  • Loading branch information
jwenjian committed Jul 22, 2019
1 parent 83e3468 commit 8a564ca
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
.idea/
__pycache__/
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img src="https://badgen.net/circleci/github/jwenjian/ghiblog"/>
<img src="https://badgen.net/badge/labels/21"/>
<img src="https://badgen.net/badge/issues/68"/>
<img src="https://badgen.net/badge/last-commit/2019-07-22 00:01:48"/>
<img src="https://badgen.net/badge/last-commit/2019-07-22 22:09:53"/>
<img src="https://badgen.net/github/forks/jwenjian/ghiblog"/>
<img src="https://badgen.net/github/stars/jwenjian/ghiblog"/>
<img src="https://badgen.net/github/watchers/jwenjian/ghiblog"/>
Expand All @@ -16,18 +16,32 @@
<a href="https://github.com/jwenjian/visitor-count-badge">
<img src="https://visitor-count-badge.herokuapp.com/total.svg?repo_id=jwenjian.ghiblog"/>
</a>
<a href="https://github.com/jwenjian/visitor-count-badge">
<img src="https://visitor-count-badge.herokuapp.com/today.svg?repo_id=jwenjian.ghiblog"/>
</a>
</p>

## :artificial_satellite:今日图片

**HDR: Earth's Circular Shadow on the Moon**

> What could create such a large circular shadow on the Moon? The Earth. Last week's full Moon -- the Buck Moon -- was so full that it fell almost exactly in a line with the Sun and the Earth. When that happens the Earth casts its shadow onto the Moon. The circularity of the Earth's shadow on the Moon was commented on by Aristotle and so has been noticed since at least the 4th century BC. What's new is humanity's ability to record this shadow with such high dynamic range (HDR). The featured HDR composite of last week's partial lunar eclipse combines 15 images and include an exposure as short as 1/400th of a second -- so as not to overexpose the brightest part -- and an exposure that lasted five seconds -- to bring up the dimmest part. This dimmest part -- inside Earth's umbra -- is not completely dark because some light is refracted through the Earth's atmosphere onto the Moon. A total lunar eclipse will occur next in 2021 May. Partial Lunar Eclipse in 2019 July: Some memorable images submitted to APOD
<center>
<img src="https://apod.nasa.gov/apod/image/1907/PartialLunarEclipse_Fattinnanzi_1080.jpg" title="HDR: Earth's Circular Shadow on the Moon" alt="What could create such a large circular shadow on the Moon? The Earth. Last week's full Moon -- the Buck Moon -- was so full that it fell almost exactly in a line with the Sun and the Earth. When that happens the Earth casts its shadow onto the Moon. The circularity of the Earth's shadow on the Moon was commented on by Aristotle and so has been noticed since at least the 4th century BC. What's new is humanity's ability to record this shadow with such high dynamic range (HDR). The featured HDR composite of last week's partial lunar eclipse combines 15 images and include an exposure as short as 1/400th of a second -- so as not to overexpose the brightest part -- and an exposure that lasted five seconds -- to bring up the dimmest part. This dimmest part -- inside Earth's umbra -- is not completely dark because some light is refracted through the Earth's atmosphere onto the Moon. A total lunar eclipse will occur next in 2021 May. Partial Lunar Eclipse in 2019 July: Some memorable images submitted to APOD"/>
</center>



## 置顶 :thumbsup:
- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>1 :speech_balloon:</sup>
- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>2 :speech_balloon:</sup>
- [如果风险投资者问你“如果大公司进入市场与你竞争,怎么办?”,你应该如何回答?](https://github.com/jwenjian/ghiblog/issues/70) <sup>1 :speech_balloon:</sup>
- [我喜欢的音乐](https://github.com/jwenjian/ghiblog/issues/67) <sup>0 :speech_balloon:</sup>
- [我给GitHub的README做了个访客数量统计功能](https://github.com/jwenjian/ghiblog/issues/43) <sup>1 :speech_balloon:</sup>
- [书单](https://github.com/jwenjian/ghiblog/issues/22) <sup>0 :speech_balloon:</sup>
- [基于CircleCI自动生成并更新GitHub Issue博客的ReadMe](https://github.com/jwenjian/ghiblog/issues/1) <sup>4 :speech_balloon:</sup>
## 最新 :new:
- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>1 :speech_balloon:</sup> 2019-07-20 04:50:32
- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>2 :speech_balloon:</sup> 2019-07-20 04:50:32

<sub>|</sub><sub>[:+1:置顶](https://github.com/jwenjian/ghiblog/labels/%3A%2B1%3A%E7%BD%AE%E9%A1%B6) | </sub><sub>[:video_game:生活](https://github.com/jwenjian/ghiblog/labels/%3Avideo_game%3A%E7%94%9F%E6%B4%BB) | </sub>

Expand All @@ -52,7 +66,7 @@
<details>
<summary>:+1:置顶 <sup>6:newspaper:</sup></summary>

- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>1 :speech_balloon:</sup>
- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>2 :speech_balloon:</sup>
- [如果风险投资者问你“如果大公司进入市场与你竞争,怎么办?”,你应该如何回答?](https://github.com/jwenjian/ghiblog/issues/70) <sup>1 :speech_balloon:</sup>
- [我喜欢的音乐](https://github.com/jwenjian/ghiblog/issues/67) <sup>0 :speech_balloon:</sup>
- [我给GitHub的README做了个访客数量统计功能](https://github.com/jwenjian/ghiblog/issues/43) <sup>1 :speech_balloon:</sup>
Expand Down Expand Up @@ -224,7 +238,7 @@
<summary>:snake:Python <sup>10:newspaper:</sup></summary>

- [[From Instapaper] : How to use Python virtualenv](https://github.com/jwenjian/ghiblog/issues/64) <sup>1 :speech_balloon:</sup>
- [[From Instapaper] : The Flask Mega-Tutorial Part I: Hello World! - miguelgrinberg.com](https://github.com/jwenjian/ghiblog/issues/62) <sup>1 :speech_balloon:</sup>
- [[From Instapaper] : The Flask Mega-Tutorial Part I: Hello World! - miguelgrinberg.com](https://github.com/jwenjian/ghiblog/issues/62) <sup>2 :speech_balloon:</sup>
- [我给GitHub的README做了个访客数量统计功能](https://github.com/jwenjian/ghiblog/issues/43) <sup>1 :speech_balloon:</sup>
- [Python: 对数组进行选择排序](https://github.com/jwenjian/ghiblog/issues/41) <sup>0 :speech_balloon:</sup>
- [Python: 对数组进行插入排序](https://github.com/jwenjian/ghiblog/issues/40) <sup>0 :speech_balloon:</sup>
Expand All @@ -240,7 +254,7 @@
<details>
<summary>:video_game:生活 <sup>8:newspaper:</sup></summary>

- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>1 :speech_balloon:</sup>
- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) <sup>2 :speech_balloon:</sup>
- [高铁/动车上插座都在什么位置](https://github.com/jwenjian/ghiblog/issues/59) <sup>2 :speech_balloon:</sup>
- [书单](https://github.com/jwenjian/ghiblog/issues/22) <sup>0 :speech_balloon:</sup>
- [2019年的第一次旅行](https://github.com/jwenjian/ghiblog/issues/17) <sup>0 :speech_balloon:</sup>
Expand Down
20 changes: 19 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import urllib.parse
import codecs
from nasa_client import NasaClient

user: Github
ghiblog: Repository
Expand Down Expand Up @@ -55,6 +56,7 @@ def bundle_summary_section():
total_issue_count = ghiblog.get_issues().totalCount

user_login = user.get_user().login
pic_of_the_day = NasaClient().get_picture_of_the_day()

summary_section = '''
# GitHub Issues Blog :tada::tada::tada:
Expand All @@ -74,9 +76,25 @@ def bundle_summary_section():
<a href="https://github.com/jwenjian/visitor-count-badge">
<img src="https://visitor-count-badge.herokuapp.com/total.svg?repo_id=jwenjian.ghiblog"/>
</a>
<a href="https://github.com/jwenjian/visitor-count-badge">
<img src="https://visitor-count-badge.herokuapp.com/today.svg?repo_id=jwenjian.ghiblog"/>
</a>
</p>
''' % (total_label_count, total_issue_count, cur_time, user_login, user_login, user_login, user_login)
## :artificial_satellite:今日图片
**%s**
> %s
<center>
<img src="%s" title="%s" alt="%s"/>
</center>
''' % (
total_label_count, total_issue_count, cur_time, user_login, user_login, user_login, user_login,
pic_of_the_day.title, pic_of_the_day.explanation, pic_of_the_day.url,
pic_of_the_day.title, pic_of_the_day.explanation)

return summary_section

Expand Down
53 changes: 53 additions & 0 deletions nasa_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import json
from urllib import request


class NasaPictureOfTheDay(object):
"""
Data object representing result of NASA apod API
"""

def __init__(self, copyright=None, explanation=None, hd_url=None, media_type=None, service_version=None, title=None,
url=None):
self.copyright = copyright
self.explanation = explanation
self.hd_url = hd_url
self.media_type = media_type
self.service_version = service_version
self.title = title
self.url = url

def __str__(self):
return 'copyright = %s, explanation = %s, hd_url = %s, media_type = %s, service_version = %s, title = %s, url = %s' % (
self.copyright, self.explanation, self.hd_url, self.media_type, self.service_version, self.title, self.url)


class NasaClient(object):
def get_picture_of_the_day(self) -> NasaPictureOfTheDay:
"""
Get picture of the day from NASA using the DEMO_KEY, api definition here: https://api.nasa.gov/api.html#apod
:return: The src of the picture of the day
"""
req = request.Request(url='https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY')

try:
with request.urlopen(req, timeout=10) as resp:
result = resp.read()
return json.loads(result, object_hook=lambda j: NasaPictureOfTheDay(copyright=j['copyright'],
explanation=j['explanation'],
hd_url=j['hdurl'],
media_type=j['media_type'],
service_version=j[
'service_version'],
title=j['title'],
url=j['url']))
except Exception as e:
print(e)
"""
If cannot get picture of the day from NASA api, then use the 404.jpg from http.cat
"""
pic_404 = NasaPictureOfTheDay()
pic_404.title = 'You can\'t see me, Meow~~!'
pic_404.url = 'https://http.cat/404.jpg'
pic_404.explanation = 'Failed to get picture of the day from NASA api, so here is a little cute cat for you, see you tomorrow!'
return pic_404

0 comments on commit 8a564ca

Please sign in to comment.