Skip to content

Commit 60b9dcd

Browse files
committed
Add 🔥 and ❄️ emojis for "hot" and "cold" statuses
fix #16
1 parent 7d90c0a commit 60b9dcd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

database.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
import logging
24
import shortener
35
import timeago
@@ -9,6 +11,8 @@
911
from helper import development
1012
from apis.telegram import send_message
1113

14+
TWO_HOURS = datetime.timedelta(hours=2)
15+
TWO_DAYS = datetime.timedelta(days=2)
1216

1317
class StoryPost(ndb.Model):
1418
title = ndb.StringProperty()
@@ -76,8 +80,18 @@ def add(cls, story):
7680
published = datetime.datetime.fromtimestamp(story.get('time'))
7781
ago = timeago.format(now, published)
7882

83+
# Add 🔥 emoji if story is hot and gained required score in less than 2 hours,
84+
# or add ❄️ if it took it more than 2 days
85+
status_emoji = ''
86+
delta = now - published
87+
if delta <= TWO_HOURS:
88+
status_emoji = '🔥 '
89+
elif delta >= TWO_DAYS:
90+
status_emoji = '❄️ '
91+
7992
# Add title
80-
message = '<b>{title}</b> (Score: {score}+ {ago})\n\n'.format(ago=ago, **story)
93+
message = '<b>{title}</b> ({status_emoji}Score: {score}+ {ago})\n\n'.format(
94+
ago=ago, status_emoji=status_emoji, **story)
8195

8296
# Add link
8397
message += '<b>Link:</b> {}\n'.format(short_url)
@@ -107,8 +121,8 @@ def add(cls, story):
107121
if result and result.get('ok'):
108122
telegram_message_id = result.get('result').get('message_id')
109123
post = cls(id=story_id, title=story.get('title'), url=story.get('url'),
110-
score=story.get('score'), text=story.get('text'),
111-
short_url=short_url, short_hn_url=short_hn_url,
112-
message=message, telegram_message_id=telegram_message_id)
124+
score=story.get('score'), text=story.get('text'),
125+
short_url=short_url, short_hn_url=short_hn_url,
126+
message=message, telegram_message_id=telegram_message_id)
113127
post.put()
114128
post.add_memcache()

0 commit comments

Comments
 (0)