Add age to posts
This commit is contained in:
parent
cc96622c71
commit
6ad0b5673e
17
app/app.py
17
app/app.py
|
|
@ -7,6 +7,7 @@ import json
|
||||||
import re
|
import re
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
@ -238,7 +239,7 @@ def get_saved():
|
||||||
WHERE
|
WHERE
|
||||||
saved = ?
|
saved = ?
|
||||||
ORDER BY
|
ORDER BY
|
||||||
score desc
|
created_utc desc
|
||||||
LIMIT ?
|
LIMIT ?
|
||||||
"""
|
"""
|
||||||
binds = [True, config.posts_per_page_load]
|
binds = [True, config.posts_per_page_load]
|
||||||
|
|
@ -306,6 +307,7 @@ def get_posts_from_select(cursor, select, binds):
|
||||||
posts = [json.loads(post[0]) for post in results]
|
posts = [json.loads(post[0]) for post in results]
|
||||||
add_media_html_to_posts(posts)
|
add_media_html_to_posts(posts)
|
||||||
add_subreddits_to_posts(posts)
|
add_subreddits_to_posts(posts)
|
||||||
|
add_age_to_posts(posts)
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
def add_media_html_to_posts(posts):
|
def add_media_html_to_posts(posts):
|
||||||
|
|
@ -325,7 +327,18 @@ def add_subreddits_to_posts(posts):
|
||||||
if "subreddit" not in post:
|
if "subreddit" not in post:
|
||||||
m = re.search(r"\/r\/([a-zA-Z0-9_]+)\/.*", post["permalink"])
|
m = re.search(r"\/r\/([a-zA-Z0-9_]+)\/.*", post["permalink"])
|
||||||
post["subreddit"] = m.group(1)
|
post["subreddit"] = m.group(1)
|
||||||
|
|
||||||
|
def add_age_to_posts(posts):
|
||||||
|
seconds = time.time()
|
||||||
|
for post in posts:
|
||||||
|
diff = seconds - int(post["created_utc"])
|
||||||
|
if diff < 3600:
|
||||||
|
post["age"] = str(int(diff//60))+'m'
|
||||||
|
elif diff < (3600 * 24):
|
||||||
|
post["age"] = str(int(diff//3600))+'h'
|
||||||
|
else:
|
||||||
|
post["age"] = str(int(diff//(3600*24)))+'d'
|
||||||
|
|
||||||
|
|
||||||
def get_media_html(file, priority=False):
|
def get_media_html(file, priority=False):
|
||||||
if file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.png') or file.endswith('.gif'):
|
if file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.png') or file.endswith('.gif'):
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
}
|
}
|
||||||
img, video {
|
img, video {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
max-height: 80vh;
|
||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
@ -50,9 +51,6 @@
|
||||||
}
|
}
|
||||||
/* desktop */
|
/* desktop */
|
||||||
@media (min-aspect-ratio: 1) {
|
@media (min-aspect-ratio: 1) {
|
||||||
img, video {
|
|
||||||
max-height: 80vh;
|
|
||||||
}
|
|
||||||
div.post {
|
div.post {
|
||||||
width: 70vw;
|
width: 70vw;
|
||||||
}
|
}
|
||||||
|
|
@ -71,9 +69,6 @@
|
||||||
}
|
}
|
||||||
/* phone */
|
/* phone */
|
||||||
@media (max-aspect-ratio: 1) {
|
@media (max-aspect-ratio: 1) {
|
||||||
img, video {
|
|
||||||
max-height: 100vh;
|
|
||||||
}
|
|
||||||
div.post {
|
div.post {
|
||||||
width: calc(100vw - 50px);
|
width: calc(100vw - 50px);
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
|
|
@ -195,6 +190,9 @@
|
||||||
{% if post.author %}
|
{% if post.author %}
|
||||||
— {{ post.author }}
|
— {{ post.author }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if post.age %}
|
||||||
|
— {{ post.age }}
|
||||||
|
{% endif %}
|
||||||
</h5>
|
</h5>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue