mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-21 21:44:40 +00:00
Handle the wording of time unit in calls
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import datetime
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
@@ -12,8 +11,8 @@ from markupsafe import escape as htmle
|
|||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
|
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
|
||||||
from Whatsapp_Chat_Exporter.utility import MAX_SIZE, ROW_SIZE, DbType, determine_metadata, JidType
|
from Whatsapp_Chat_Exporter.utility import MAX_SIZE, ROW_SIZE, DbType, convert_time_unit, determine_metadata
|
||||||
from Whatsapp_Chat_Exporter.utility import rendering, Crypt, Device, get_file_name, setup_template
|
from Whatsapp_Chat_Exporter.utility import rendering, Crypt, Device, get_file_name, setup_template, JidType
|
||||||
from Whatsapp_Chat_Exporter.utility import brute_force_offset, CRYPT14_OFFSETS, get_status_location
|
from Whatsapp_Chat_Exporter.utility import brute_force_offset, CRYPT14_OFFSETS, get_status_location
|
||||||
from Whatsapp_Chat_Exporter.utility import get_chat_condition, slugify, convert_size, chat_is_empty
|
from Whatsapp_Chat_Exporter.utility import get_chat_condition, slugify, convert_size, chat_is_empty
|
||||||
|
|
||||||
@@ -734,13 +733,11 @@ def calls(db, data, timezone_offset, filter_chat):
|
|||||||
elif content['call_result'] == 3:
|
elif content['call_result'] == 3:
|
||||||
call.data += "unavailable."
|
call.data += "unavailable."
|
||||||
elif content['call_result'] == 5:
|
elif content['call_result'] == 5:
|
||||||
call_time = str(datetime.timedelta(seconds=content['duration']))
|
call_time = convert_time_unit(content['duration'])
|
||||||
if "day" not in call_time and call_time.startswith("0:"):
|
|
||||||
call_time = call_time[2:]
|
|
||||||
call_bytes = convert_size(content['bytes_transferred'])
|
call_bytes = convert_size(content['bytes_transferred'])
|
||||||
call.data += (
|
call.data += (
|
||||||
f"initiated and lasted for {call_time} "
|
f"initiated and lasted for {call_time} "
|
||||||
f"with {call_bytes} transferred."
|
f"with {call_bytes} data transferred."
|
||||||
)
|
)
|
||||||
chat.add_message(content["_id"], call)
|
chat.add_message(content["_id"], call)
|
||||||
content = c.fetchone()
|
content = c.fetchone()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import re
|
|||||||
import math
|
import math
|
||||||
from bleach import clean as sanitize
|
from bleach import clean as sanitize
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from Whatsapp_Chat_Exporter.data_model import ChatStore
|
from Whatsapp_Chat_Exporter.data_model import ChatStore
|
||||||
try:
|
try:
|
||||||
@@ -24,6 +24,26 @@ MAX_SIZE = 4 * 1024 * 1024 # Default 4MB
|
|||||||
ROW_SIZE = 0x3D0
|
ROW_SIZE = 0x3D0
|
||||||
|
|
||||||
|
|
||||||
|
def convert_time_unit(time_second: int):
|
||||||
|
time = str(timedelta(seconds=time_second))
|
||||||
|
if "day" not in time:
|
||||||
|
if time_second < 1:
|
||||||
|
time = "less than a second"
|
||||||
|
elif time_second == 1:
|
||||||
|
time = "a second"
|
||||||
|
elif time_second < 60:
|
||||||
|
time = time[5:][1 if time_second < 10 else 0:] + " seconds"
|
||||||
|
elif time_second == 60:
|
||||||
|
time = "a minute"
|
||||||
|
elif time_second < 3600:
|
||||||
|
time = time[2:] + " minutes"
|
||||||
|
elif time_second == 3600:
|
||||||
|
time = "an hour"
|
||||||
|
else:
|
||||||
|
time += " hour"
|
||||||
|
return time
|
||||||
|
|
||||||
|
|
||||||
def convert_size(size_bytes):
|
def convert_size(size_bytes):
|
||||||
"""From https://stackoverflow.com/a/14822210/9478891
|
"""From https://stackoverflow.com/a/14822210/9478891
|
||||||
Authors: james-sapam & other contributors
|
Authors: james-sapam & other contributors
|
||||||
|
|||||||
Reference in New Issue
Block a user