From 8a564ca9246dc5b8f1f584def4c2649eec22d916 Mon Sep 17 00:00:00 2001
From: jwenjian <1639301503@qq.com>
Date: Mon, 22 Jul 2019 22:13:00 +0800
Subject: [PATCH] add new section picture of the day add new module nasa client
add visitors in today badge
---
.gitignore | 3 ++-
README.md | 26 +++++++++++++++-----
main.py | 20 +++++++++++++++-
nasa_client/__init__.py | 53 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 94 insertions(+), 8 deletions(-)
create mode 100644 nasa_client/__init__.py
diff --git a/.gitignore b/.gitignore
index 62c8935..2483976 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-.idea/
\ No newline at end of file
+.idea/
+__pycache__/
diff --git a/README.md b/README.md
index 1d2c62c..c1bf048 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
-
+
@@ -16,18 +16,32 @@
+
+
+
+## :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
+
+
+
+
+
+
## 置顶 :thumbsup:
-- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 1 :speech_balloon:
+- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 2 :speech_balloon:
- [如果风险投资者问你“如果大公司进入市场与你竞争,怎么办?”,你应该如何回答?](https://github.com/jwenjian/ghiblog/issues/70) 1 :speech_balloon:
- [我喜欢的音乐](https://github.com/jwenjian/ghiblog/issues/67) 0 :speech_balloon:
- [我给GitHub的README做了个访客数量统计功能](https://github.com/jwenjian/ghiblog/issues/43) 1 :speech_balloon:
- [书单](https://github.com/jwenjian/ghiblog/issues/22) 0 :speech_balloon:
- [基于CircleCI自动生成并更新GitHub Issue博客的ReadMe](https://github.com/jwenjian/ghiblog/issues/1) 4 :speech_balloon:
## 最新 :new:
-- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 1 :speech_balloon: 2019-07-20 04:50:32
+- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 2 :speech_balloon: 2019-07-20 04:50:32
|[:+1:置顶](https://github.com/jwenjian/ghiblog/labels/%3A%2B1%3A%E7%BD%AE%E9%A1%B6) | [:video_game:生活](https://github.com/jwenjian/ghiblog/labels/%3Avideo_game%3A%E7%94%9F%E6%B4%BB) |
@@ -52,7 +66,7 @@
:+1:置顶 6:newspaper:
-- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 1 :speech_balloon:
+- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 2 :speech_balloon:
- [如果风险投资者问你“如果大公司进入市场与你竞争,怎么办?”,你应该如何回答?](https://github.com/jwenjian/ghiblog/issues/70) 1 :speech_balloon:
- [我喜欢的音乐](https://github.com/jwenjian/ghiblog/issues/67) 0 :speech_balloon:
- [我给GitHub的README做了个访客数量统计功能](https://github.com/jwenjian/ghiblog/issues/43) 1 :speech_balloon:
@@ -224,7 +238,7 @@
:snake:Python 10:newspaper:
- [[From Instapaper] : How to use Python virtualenv](https://github.com/jwenjian/ghiblog/issues/64) 1 :speech_balloon:
-- [[From Instapaper] : The Flask Mega-Tutorial Part I: Hello World! - miguelgrinberg.com](https://github.com/jwenjian/ghiblog/issues/62) 1 :speech_balloon:
+- [[From Instapaper] : The Flask Mega-Tutorial Part I: Hello World! - miguelgrinberg.com](https://github.com/jwenjian/ghiblog/issues/62) 2 :speech_balloon:
- [我给GitHub的README做了个访客数量统计功能](https://github.com/jwenjian/ghiblog/issues/43) 1 :speech_balloon:
- [Python: 对数组进行选择排序](https://github.com/jwenjian/ghiblog/issues/41) 0 :speech_balloon:
- [Python: 对数组进行插入排序](https://github.com/jwenjian/ghiblog/issues/40) 0 :speech_balloon:
@@ -240,7 +254,7 @@
:video_game:生活 8:newspaper:
-- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 1 :speech_balloon:
+- [影视节目单](https://github.com/jwenjian/ghiblog/issues/71) 2 :speech_balloon:
- [高铁/动车上插座都在什么位置](https://github.com/jwenjian/ghiblog/issues/59) 2 :speech_balloon:
- [书单](https://github.com/jwenjian/ghiblog/issues/22) 0 :speech_balloon:
- [2019年的第一次旅行](https://github.com/jwenjian/ghiblog/issues/17) 0 :speech_balloon:
diff --git a/main.py b/main.py
index e1a40b6..557f212 100644
--- a/main.py
+++ b/main.py
@@ -8,6 +8,7 @@
import time
import urllib.parse
import codecs
+from nasa_client import NasaClient
user: Github
ghiblog: Repository
@@ -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:
@@ -74,9 +76,25 @@ def bundle_summary_section():
+
+
+
-''' % (total_label_count, total_issue_count, cur_time, user_login, user_login, user_login, user_login)
+## :artificial_satellite:今日图片
+
+**%s**
+
+> %s
+
+
+
+
+
+''' % (
+ 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
diff --git a/nasa_client/__init__.py b/nasa_client/__init__.py
new file mode 100644
index 0000000..0ff375b
--- /dev/null
+++ b/nasa_client/__init__.py
@@ -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