parent
184d2b47e9
commit
2edd6a328d
@ -1,44 +1,16 @@
|
|||||||
import datetime
|
import sqlite3
|
||||||
|
import time
|
||||||
|
|
||||||
def pretty_date(time=False):
|
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
|
||||||
"""
|
# Open database connection
|
||||||
Get a datetime object or a int() Epoch timestamp and return a
|
db = sqlite3.connect('bazarr.db')
|
||||||
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
|
c = db.cursor()
|
||||||
'just now', etc
|
|
||||||
"""
|
|
||||||
from datetime import datetime
|
|
||||||
now = datetime.now()
|
|
||||||
if type(time) is int:
|
|
||||||
diff = now - datetime.fromtimestamp(time)
|
|
||||||
elif isinstance(time,datetime):
|
|
||||||
diff = now - time
|
|
||||||
elif not time:
|
|
||||||
diff = now - now
|
|
||||||
second_diff = diff.seconds
|
|
||||||
day_diff = diff.days
|
|
||||||
|
|
||||||
if day_diff < 0:
|
# Get Sonarr API URL from database config table
|
||||||
return ''
|
history = c.execute('''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description) VALUES (?, ?, ?, ?, ?)''', (action, sonarrSeriesId, sonarrEpisodeId, time.time(), description))
|
||||||
|
|
||||||
if day_diff == 0:
|
# Commit changes to DB
|
||||||
if second_diff < 10:
|
db.commit()
|
||||||
return "just now"
|
|
||||||
if second_diff < 60:
|
# Close database connection
|
||||||
return str(second_diff) + " seconds ago"
|
db.close()
|
||||||
if second_diff < 120:
|
|
||||||
return "a minute ago"
|
|
||||||
if second_diff < 3600:
|
|
||||||
return str(second_diff / 60) + " minutes ago"
|
|
||||||
if second_diff < 7200:
|
|
||||||
return "an hour ago"
|
|
||||||
if second_diff < 86400:
|
|
||||||
return str(second_diff / 3600) + " hours ago"
|
|
||||||
if day_diff == 1:
|
|
||||||
return "Yesterday"
|
|
||||||
if day_diff < 7:
|
|
||||||
return str(day_diff) + " days ago"
|
|
||||||
if day_diff < 31:
|
|
||||||
return str(day_diff / 7) + " weeks ago"
|
|
||||||
if day_diff < 365:
|
|
||||||
return str(day_diff / 30) + " months ago"
|
|
||||||
return str(day_diff / 365) + " years ago"
|
|
||||||
|
Loading…
Reference in new issue