diff --git a/Pipfile b/Pipfile index afc7109..8586141 100644 --- a/Pipfile +++ b/Pipfile @@ -30,6 +30,7 @@ sqlparse = "==0.3.1" swapper = "==1.1.2.post1" whitenoise = "==3.3.1" django-allauth = "*" +pandas = "==0.24.1" [requires] python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index bdd2825..57cb13b 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "eb1d6025cfaf0b161b3b74d820636f70c43e4f24fde4efbd8862e6d52dc3b1fd" + "sha256": "cbc7d38e6c817f8495ccb546a5af33f91a9bc97536ac1c34f8fe31309a3b596c" }, "pipfile-spec": 6, "requires": { @@ -170,6 +170,32 @@ "index": "pypi", "version": "==3.2.1" }, + "numpy": { + "hashes": [ + "sha256:0aa2b318cf81eb1693fcfcbb8007e95e231d7e1aa24288137f3b19905736c3ee", + "sha256:163c78c04f47f26ca1b21068cea25ed7c5ecafe5f5ab2ea4895656a750582b56", + "sha256:1e37626bcb8895c4b3873fcfd54e9bfc5ffec8d0f525651d6985fcc5c6b6003c", + "sha256:264fd15590b3f02a1fbc095e7e1f37cdac698ff3829e12ffdcffdce3772f9d44", + "sha256:3d9e1554cd9b5999070c467b18e5ae3ebd7369f02706a8850816f576a954295f", + "sha256:40c24960cd5cec55222963f255858a1c47c6fa50a65a5b03fd7de75e3700eaaa", + "sha256:46f404314dbec78cb342904f9596f25f9b16e7cf304030f1339e553c8e77f51c", + "sha256:4847f0c993298b82fad809ea2916d857d0073dc17b0510fbbced663b3265929d", + "sha256:48e15612a8357393d176638c8f68a19273676877caea983f8baf188bad430379", + "sha256:6725d2797c65598778409aba8cd67077bb089d5b7d3d87c2719b206dc84ec05e", + "sha256:99f0ba97e369f02a21bb95faa3a0de55991fd5f0ece2e30a9e2eaebeac238921", + "sha256:a41f303b3f9157a31ce7203e3ca757a0c40c96669e72d9b6ee1bce8507638970", + "sha256:a4305564e93f5c4584f6758149fd446df39fd1e0a8c89ca0deb3cce56106a027", + "sha256:a551d8cc267c634774830086da42e4ba157fa41dd3b93982bc9501b284b0c689", + "sha256:a6bc9432c2640b008d5f29bad737714eb3e14bb8854878eacf3d7955c4e91c36", + "sha256:c60175d011a2e551a2f74c84e21e7c982489b96b6a5e4b030ecdeacf2914da68", + "sha256:e46e2384209c91996d5ec16744234d1c906ab79a701ce1a26155c9ec890b8dc8", + "sha256:e607b8cdc2ae5d5a63cd1bec30a15b5ed583ac6a39f04b7ba0f03fcfbf29c05b", + "sha256:e94a39d5c40fffe7696009dbd11bc14a349b377e03a384ed011e03d698787dd3", + "sha256:eb2286249ebfe8fcb5b425e5ec77e4736d53ee56d3ad296f8947f67150f495e3", + "sha256:fdee7540d12519865b423af411bd60ddb513d2eb2cd921149b732854995bbf8b" + ], + "version": "==1.18.3" + }, "oauthlib": { "hashes": [ "sha256:bee41cc35fcca6e988463cacc3bcb8a96224f470ca547e697b604cc697b2f889", @@ -177,6 +203,32 @@ ], "version": "==3.1.0" }, + "pandas": { + "hashes": [ + "sha256:02c830f951f3dc8c3164e2639a8961881390f7492f71a7835c2330f54539ad57", + "sha256:179015834c72a577486337394493cc2969feee9a04a2ea09f50c724e4b52ab42", + "sha256:3894960d43c64cfea5142ac783b101362f5008ee92e962392156a3f8d1558995", + "sha256:435821cb2501eabbcee7e83614bd710940dc0cf28b5afbc4bdb816c31cec71af", + "sha256:8294dea9aa1811f93558702856e3b68dd1dfd7e9dbc8e0865918a07ee0f21c2c", + "sha256:844e745ab27a9a01c86925fe776f9d2e09575e65f0bf8eba5090edddd655dffc", + "sha256:a08d49f5fa2a2243262fe5581cb89f6c0c7cc525b8d6411719ab9400a9dc4a82", + "sha256:a435c251246075337eb9fdc4160fd15c8a87cc0679d8d61fb5255d8d5a12f044", + "sha256:a799f03c0ec6d8687f425d7d6c075e8055a9a808f1ba87604d91f20507631d8d", + "sha256:aea72ce5b3a016b578cc05c04a2f68d9cafacf5d784b6fe832e66381cb62c719", + "sha256:c145e94c6da2af7eaf1fd827293ac1090a61a9b80150bebe99f8966a02378db9", + "sha256:c8a7b470c88c779301b73b23cabdbbd94b83b93040b2ccffa409e06df23831c0", + "sha256:c9e31b36abbd7b94c547d9047f13e1546e3ba967044cf4f9718575fcb7b81bb6", + "sha256:d960b7a03c33c328c723cfc2f8902a6291645f4efa0a5c1d4c5fa008cdc1ea77", + "sha256:da21fae4c173781b012217c9444f13c67449957a4d45184a9718268732c09564", + "sha256:db26c0fea0bd7d33c356da98bafd2c0dfb8f338e45e2824ff8f4f3e61b5c5f25", + "sha256:dc296c3f16ec620cfb4daf0f672e3c90f3920ece8261b2760cd0ebd9cd4daa55", + "sha256:e8da67cb2e9333ec30d53cfb96e27a4865d1648688e5471699070d35d8ab38cf", + "sha256:fb4f047a63f91f22aade4438aaf790400b96644e802daab4293e9b799802f93f", + "sha256:fef9939176cba0c2526ebeefffb8b9807543dc0954877b7226f751ec1294a869" + ], + "index": "pypi", + "version": "==0.24.1" + }, "pilkit": { "hashes": [ "sha256:ddb30c2f0198a147e56b151476c3bb9fe045fbfd5b0a0fa2a3148dba62d1559f" @@ -220,6 +272,13 @@ "index": "pypi", "version": "==2.6.1" }, + "python-dateutil": { + "hashes": [ + "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", + "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" + ], + "version": "==2.8.1" + }, "python3-openid": { "hashes": [ "sha256:0086da6b6ef3161cfe50fb1ee5cceaf2cda1700019fda03c2c5c440ca6abe4fa", diff --git a/article/templatetags/article_extras.py b/article/templatetags/article_extras.py index 65e451d..835f808 100644 --- a/article/templatetags/article_extras.py +++ b/article/templatetags/article_extras.py @@ -1,7 +1,11 @@ from django import template from django.db.models.aggregates import Count from ..models import ArticlePost,Category - +from django.utils import timezone +import math +import datetime +import requests + register = template.Library() @@ -20,11 +24,51 @@ def show_cats_tags(context): } -@register.inclusion_tag('article/inclusions/_resume.html') -def show_resume(): - return {} +@register.inclusion_tag('article/inclusions/_resume.html',takes_context=True) +def show_resume(context): + current_time = datetime.datetime.now().strftime("%Y/%m/%d") + return {'current_time':current_time} + + +@register.inclusion_tag('article/inclusions/_notification.html',takes_context=True) +def show_notification(context): + url = 'http://api.openweathermap.org/data/2.5/weather?q=Paris,fr&units=imperial&appid=2e37fd2364d867821f298280137eecc0' + r = requests.get(url).json() + paris_weather={} + + if r['cod']==200: + paris_weather = { + 'city':'Paris', + 'temperature' :float("{0:.2f}".format((r['main']['temp']-32)* 5/9)), + 'description' : r['weather'][0]['description'], + 'icon' : r['weather'][0]['icon'], + 'country':r['sys']['country']} + + return {'paris_weather':paris_weather} + + + +@register.filter(name='timesince_zh') +def time_since_zh(value): + now = timezone.now() + diff = now - value + + if diff.days == 0 and diff.seconds >= 0 and diff.seconds < 60: + return '刚刚' + + if diff.days == 0 and diff.seconds >= 60 and diff.seconds < 3600: + return str(math.floor(diff.seconds / 60)) + "分钟前" + + if diff.days == 0 and diff.seconds >= 3600 and diff.seconds < 86400: + return str(math.floor(diff.seconds / 3600)) + "小时前" + + if diff.days >= 1 and diff.days < 30: + return str(diff.days) + "天前" + + if diff.days >= 30 and diff.days < 365: + return str(math.floor(diff.days / 30)) + "个月前" + + if diff.days >= 365: + return str(math.floor(diff.days / 365)) + "年前" -@register.inclusion_tag('article/inclusions/_notification.html') -def show_notification(): - return {} \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 6b339b2..61e7c3e 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..8179e44 --- /dev/null +++ b/demo.py @@ -0,0 +1,15 @@ +import requests + +url = 'http://api.openweathermap.org/data/2.5/weather?q=Paris,fr&units=imperial&appid=2e37fd2364d867821f298280137eecc0' +r = requests.get(url).json() +paris_weather={} + +if r['cod']==200: + paris_weather = { + 'city':'Paris', + 'temperature' :float("{0:.2f}".format((r['main']['temp']-32)* 5/9)), + 'description' : r['weather'][0]['description'], + 'icon' : r['weather'][0]['icon'], + 'country':r['sys']['country']} + + diff --git a/media/avatar/20200424/my_photo.png b/media/avatar/20200424/my_photo.png new file mode 100644 index 0000000..f8799c1 Binary files /dev/null and b/media/avatar/20200424/my_photo.png differ diff --git a/my_blog/settings.py b/my_blog/settings.py index fc0a687..9482588 100644 --- a/my_blog/settings.py +++ b/my_blog/settings.py @@ -135,13 +135,13 @@ ] -AUTHENTICATION_BACKENDS = ( - # Django 后台可独立于 allauth 登录 - 'django.contrib.auth.backends.ModelBackend', +# AUTHENTICATION_BACKENDS = ( +# # Django 后台可独立于 allauth 登录 +# 'django.contrib.auth.backends.ModelBackend', - # 配置 allauth 独有的认证方法,如 email 登录 - 'allauth.account.auth_backends.AuthenticationBackend', -) +# # 配置 allauth 独有的认证方法,如 email 登录 +# 'allauth.account.auth_backends.AuthenticationBackend', +# ) diff --git a/static/images/self.jpg b/static/images/self.jpg new file mode 100644 index 0000000..4547e6d Binary files /dev/null and b/static/images/self.jpg differ diff --git a/templates/article/inclusions/_notification.html b/templates/article/inclusions/_notification.html index e914576..7ab679a 100644 --- a/templates/article/inclusions/_notification.html +++ b/templates/article/inclusions/_notification.html @@ -1,4 +1,4 @@ -
+ + +
+
+
+
+ Image +
+
+
+
+

+ {{ paris_weather.city }}, {{ paris_weather.country }} +
+ {{ paris_weather.temperature }} °c, {{ paris_weather.description }} +

+
+
+ +
+ + diff --git a/templates/article/inclusions/_resume.html b/templates/article/inclusions/_resume.html index 24b5c79..661cd72 100644 --- a/templates/article/inclusions/_resume.html +++ b/templates/article/inclusions/_resume.html @@ -7,6 +7,7 @@
About Me + {{ current_time }}

zeliang.yao@efrei.net

diff --git a/templates/article/list.html b/templates/article/list.html index 85fecb4..b0ba7ef 100644 --- a/templates/article/list.html +++ b/templates/article/list.html @@ -163,7 +163,8 @@
- {{ article.created|date:'Y-m-d' }} + + {{ article.created|timesince_zh }}

diff --git a/templates/header.html b/templates/header.html index c690826..cf6714d 100644 --- a/templates/header.html +++ b/templates/header.html @@ -1,26 +1,31 @@ {% load notifications_tags %} {% notifications_unread as unread_count %} - +{% load static %}