mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-07-21 04:56:42 +02:00
Add offline availability of w3css
This commit is contained in:
@@ -103,6 +103,11 @@ def main():
|
|||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Move the media directory to output directory if the flag is set, otherwise copy it")
|
help="Move the media directory to output directory if the flag is set, otherwise copy it")
|
||||||
|
parser.add_option(
|
||||||
|
"--offline",
|
||||||
|
dest="offline",
|
||||||
|
default=None,
|
||||||
|
help="Relative path to offline static files")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if options.android and options.iphone:
|
if options.android and options.iphone:
|
||||||
@@ -194,7 +199,7 @@ def main():
|
|||||||
messages(db, data)
|
messages(db, data)
|
||||||
media(db, data, options.media)
|
media(db, data, options.media)
|
||||||
vcard(db, data)
|
vcard(db, data)
|
||||||
create_html(data, options.output, options.template, options.embedded)
|
create_html(data, options.output, options.template, options.embedded, options.offline)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
"The message database does not exist. You may specify the path "
|
"The message database does not exist. You may specify the path "
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ def vcard(db, data):
|
|||||||
print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r")
|
print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|
||||||
def create_html(data, output_folder, template=None, embedded=False):
|
def create_html(data, output_folder, template=None, embedded=False, offline_static=False):
|
||||||
if template is None:
|
if template is None:
|
||||||
template_dir = os.path.dirname(__file__)
|
template_dir = os.path.dirname(__file__)
|
||||||
template_file = "whatsapp.html"
|
template_file = "whatsapp.html"
|
||||||
@@ -450,6 +450,18 @@ def create_html(data, output_folder, template=None, embedded=False):
|
|||||||
if not os.path.isdir(output_folder):
|
if not os.path.isdir(output_folder):
|
||||||
os.mkdir(output_folder)
|
os.mkdir(output_folder)
|
||||||
|
|
||||||
|
w3css = "https://www.w3schools.com/w3css/4/w3.css"
|
||||||
|
if offline_static:
|
||||||
|
import urllib.request
|
||||||
|
static_folder = os.path.join(output_folder, offline_static)
|
||||||
|
if not os.path.isdir(static_folder):
|
||||||
|
os.mkdir(static_folder)
|
||||||
|
w3css_path = os.path.join(static_folder, "w3.css")
|
||||||
|
if not os.path.isfile(w3css_path):
|
||||||
|
with urllib.request.urlopen(w3css) as resp:
|
||||||
|
with open(w3css_path, "wb") as f: f.write(resp.read())
|
||||||
|
w3css = os.path.join(offline_static, "w3.css")
|
||||||
|
|
||||||
for current, contact in enumerate(data):
|
for current, contact in enumerate(data):
|
||||||
if len(data[contact]["messages"]) == 0:
|
if len(data[contact]["messages"]) == 0:
|
||||||
continue
|
continue
|
||||||
@@ -474,7 +486,8 @@ def create_html(data, output_folder, template=None, embedded=False):
|
|||||||
name=name,
|
name=name,
|
||||||
msgs=data[contact]["messages"].values(),
|
msgs=data[contact]["messages"].values(),
|
||||||
my_avatar=None,
|
my_avatar=None,
|
||||||
their_avatar=f"WhatsApp/Avatars/{contact}.j"
|
their_avatar=f"WhatsApp/Avatars/{contact}.j",
|
||||||
|
w3css=w3css
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if current % 10 == 0:
|
if current % 10 == 0:
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ def vcard(db, data):
|
|||||||
print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r")
|
print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|
||||||
def create_html(data, output_folder, template=None, embedded=False):
|
def create_html(data, output_folder, template=None, embedded=False, offline_static=False):
|
||||||
if template is None:
|
if template is None:
|
||||||
template_dir = os.path.dirname(__file__)
|
template_dir = os.path.dirname(__file__)
|
||||||
template_file = "whatsapp.html"
|
template_file = "whatsapp.html"
|
||||||
@@ -247,6 +247,18 @@ def create_html(data, output_folder, template=None, embedded=False):
|
|||||||
if not os.path.isdir(output_folder):
|
if not os.path.isdir(output_folder):
|
||||||
os.mkdir(output_folder)
|
os.mkdir(output_folder)
|
||||||
|
|
||||||
|
w3css = "https://www.w3schools.com/w3css/4/w3.css"
|
||||||
|
if offline_static:
|
||||||
|
import urllib.request
|
||||||
|
static_folder = os.path.join(output_folder, offline_static)
|
||||||
|
if not os.path.isdir(static_folder):
|
||||||
|
os.mkdir(static_folder)
|
||||||
|
w3css_path = os.path.join(static_folder, "w3.css")
|
||||||
|
if not os.path.isfile(w3css_path):
|
||||||
|
with urllib.request.urlopen(w3css) as resp:
|
||||||
|
with open(w3css_path, "wb") as f: f.write(resp.read())
|
||||||
|
w3css = os.path.join(offline_static, "w3.css")
|
||||||
|
|
||||||
for current, contact in enumerate(data):
|
for current, contact in enumerate(data):
|
||||||
if len(data[contact]["messages"]) == 0:
|
if len(data[contact]["messages"]) == 0:
|
||||||
continue
|
continue
|
||||||
@@ -272,7 +284,8 @@ def create_html(data, output_folder, template=None, embedded=False):
|
|||||||
name=name,
|
name=name,
|
||||||
msgs=data[contact]["messages"].values(),
|
msgs=data[contact]["messages"].values(),
|
||||||
my_avatar=None,
|
my_avatar=None,
|
||||||
their_avatar=f"WhatsApp/Avatars/{contact}.j"
|
their_avatar=f"WhatsApp/Avatars/{contact}.j",
|
||||||
|
w3css=w3css
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if current % 10 == 0:
|
if current % 10 == 0:
|
||||||
|
|||||||
@@ -458,7 +458,7 @@ def vcard(db, data):
|
|||||||
print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r")
|
print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|
||||||
def create_html(data, output_folder, template=None, embedded=False):
|
def create_html(data, output_folder, template=None, embedded=False, offline_static=False):
|
||||||
if template is None:
|
if template is None:
|
||||||
template_dir = os.path.dirname(__file__)
|
template_dir = os.path.dirname(__file__)
|
||||||
template_file = "whatsapp.html"
|
template_file = "whatsapp.html"
|
||||||
@@ -477,6 +477,18 @@ def create_html(data, output_folder, template=None, embedded=False):
|
|||||||
if not os.path.isdir(output_folder):
|
if not os.path.isdir(output_folder):
|
||||||
os.mkdir(output_folder)
|
os.mkdir(output_folder)
|
||||||
|
|
||||||
|
w3css = "https://www.w3schools.com/w3css/4/w3.css"
|
||||||
|
if offline_static:
|
||||||
|
import urllib.request
|
||||||
|
static_folder = os.path.join(output_folder, offline_static)
|
||||||
|
if not os.path.isdir(static_folder):
|
||||||
|
os.mkdir(static_folder)
|
||||||
|
w3css_path = os.path.join(static_folder, "w3.css")
|
||||||
|
if not os.path.isfile(w3css_path):
|
||||||
|
with urllib.request.urlopen(w3css) as resp:
|
||||||
|
with open(w3css_path, "wb") as f: f.write(resp.read())
|
||||||
|
w3css = os.path.join(offline_static, "w3.css")
|
||||||
|
|
||||||
for current, contact in enumerate(data):
|
for current, contact in enumerate(data):
|
||||||
if len(data[contact].messages) == 0:
|
if len(data[contact].messages) == 0:
|
||||||
continue
|
continue
|
||||||
@@ -501,7 +513,8 @@ def create_html(data, output_folder, template=None, embedded=False):
|
|||||||
name=name,
|
name=name,
|
||||||
msgs=data[contact].messages.values(),
|
msgs=data[contact].messages.values(),
|
||||||
my_avatar=None,
|
my_avatar=None,
|
||||||
their_avatar=f"WhatsApp/Avatars/{contact}.j"
|
their_avatar=f"WhatsApp/Avatars/{contact}.j",
|
||||||
|
w3css=w3css
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if current % 10 == 0:
|
if current % 10 == 0:
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Whatsapp - {{ name }}</title>
|
<title>Whatsapp - {{ name }}</title>
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<meta charset="UTF-8">
|
||||||
|
<link rel="stylesheet" href="{{w3css}}">
|
||||||
<style>
|
<style>
|
||||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+HK:wght@300;400&display=swap');
|
html, body {
|
||||||
html {
|
|
||||||
font-family: 'Noto Sans HK', sans-serif;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user