mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-25 23:41:33 +00:00
Some PEP8
This commit is contained in:
@@ -1 +1 @@
|
|||||||
__version__ = "0.6"
|
__version__ = "0.6"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from .__init__ import __version__
|
from .__init__ import __version__
|
||||||
from Whatsapp_Chat_Exporter import extract, extract_iphone, extract_iphone_media
|
from Whatsapp_Chat_Exporter import extract, extract_iphone
|
||||||
|
from Whatsapp_Chat_Exporter import extract_iphone_media
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -40,7 +41,8 @@ def main():
|
|||||||
"--backup",
|
"--backup",
|
||||||
dest="backup",
|
dest="backup",
|
||||||
default=None,
|
default=None,
|
||||||
help="Path to Android (must be used together with -k)/iPhone WhatsApp backup")
|
help="Path to Android (must be used together "
|
||||||
|
"with -k)/iPhone WhatsApp backup")
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"-o",
|
"-o",
|
||||||
"--output",
|
"--output",
|
||||||
@@ -102,7 +104,8 @@ def main():
|
|||||||
db = open(options.backup, "rb").read()
|
db = open(options.backup, "rb").read()
|
||||||
is_crypt14 = False if "crypt12" in options.backup else True
|
is_crypt14 = False if "crypt12" in options.backup else True
|
||||||
if not extract.decrypt_backup(db, key, msg_db, is_crypt14):
|
if not extract.decrypt_backup(db, key, msg_db, is_crypt14):
|
||||||
print("Dependencies of decrypt_backup are not present. For details, see README.md")
|
print("Dependencies of decrypt_backup are not "
|
||||||
|
"present. For details, see README.md")
|
||||||
return False
|
return False
|
||||||
if options.wa is None:
|
if options.wa is None:
|
||||||
contact_db = "wa.db"
|
contact_db = "wa.db"
|
||||||
@@ -110,14 +113,14 @@ def main():
|
|||||||
contact_db = options.wa
|
contact_db = options.wa
|
||||||
if options.media is None:
|
if options.media is None:
|
||||||
options.media = "WhatsApp"
|
options.media = "WhatsApp"
|
||||||
|
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
msg_db = args[0]
|
msg_db = args[0]
|
||||||
|
|
||||||
if os.path.isfile(contact_db):
|
if os.path.isfile(contact_db):
|
||||||
with sqlite3.connect(contact_db) as db:
|
with sqlite3.connect(contact_db) as db:
|
||||||
contacts(db, data)
|
contacts(db, data)
|
||||||
|
|
||||||
elif options.iphone:
|
elif options.iphone:
|
||||||
messages = extract_iphone.messages
|
messages = extract_iphone.messages
|
||||||
media = extract_iphone.media
|
media = extract_iphone.media
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ def messages(db, data):
|
|||||||
f"Gathering messages...({total_row_number}/{total_row_number})", end="\r")
|
f"Gathering messages...({total_row_number}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|
||||||
def media(db, data, media_folder):
|
def media(db, data):
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
# Get media
|
# Get media
|
||||||
c.execute("""SELECT count() FROM ZWAMEDIAITEM""")
|
c.execute("""SELECT count() FROM ZWAMEDIAITEM""")
|
||||||
@@ -217,7 +217,7 @@ def create_html(data, output_folder, template=None):
|
|||||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||||
templateEnv.globals.update(determine_day=determine_day)
|
templateEnv.globals.update(determine_day=determine_day)
|
||||||
template = templateEnv.get_template(template_file)
|
template = templateEnv.get_template(template_file)
|
||||||
|
|
||||||
total_row_number = len(data)
|
total_row_number = len(data)
|
||||||
print(f"\nCreating HTML...(0/{total_row_number})", end="\r")
|
print(f"\nCreating HTML...(0/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,24 @@ import os
|
|||||||
import getpass
|
import getpass
|
||||||
try:
|
try:
|
||||||
from iphone_backup_decrypt import EncryptedBackup, RelativePath
|
from iphone_backup_decrypt import EncryptedBackup, RelativePath
|
||||||
except:
|
except ModuleNotFoundError:
|
||||||
support_encrypted = False
|
support_encrypted = False
|
||||||
else:
|
else:
|
||||||
support_encrypted = True
|
support_encrypted = True
|
||||||
|
|
||||||
|
|
||||||
def extract_encrypted(base_dir, password):
|
def extract_encrypted(base_dir, password):
|
||||||
backup = EncryptedBackup(backup_directory=base_dir, passphrase=password)
|
backup = EncryptedBackup(backup_directory=base_dir, passphrase=password)
|
||||||
print("Decrypting WhatsApp database...")
|
print("Decrypting WhatsApp database...")
|
||||||
backup.extract_file(relative_path=RelativePath.WHATSAPP_MESSAGES, output_filename="7c7fba66680ef796b916b067077cc246adacf01d")
|
backup.extract_file(relative_path=RelativePath.WHATSAPP_MESSAGES,
|
||||||
backup.extract_file(relative_path=RelativePath.WHATSAPP_CONTACTS, output_filename="ContactsV2.sqlite")
|
output_filename="7c7fba66680ef796b916b067077cc246adacf01d")
|
||||||
|
backup.extract_file(relative_path=RelativePath.WHATSAPP_CONTACTS,
|
||||||
|
output_filename="ContactsV2.sqlite")
|
||||||
data = backup.execute_sql("""SELECT count()
|
data = backup.execute_sql("""SELECT count()
|
||||||
FROM Files
|
FROM Files
|
||||||
WHERE relativePath
|
WHERE relativePath
|
||||||
LIKE 'Message/Media/%'"""
|
LIKE 'Message/Media/%'"""
|
||||||
)
|
)
|
||||||
total_row_number = data[0][0]
|
total_row_number = data[0][0]
|
||||||
print(f"Gathering media...(0/{total_row_number})", end="\r")
|
print(f"Gathering media...(0/{total_row_number})", end="\r")
|
||||||
data = backup.execute_sql("""SELECT fileID,
|
data = backup.execute_sql("""SELECT fileID,
|
||||||
@@ -30,7 +33,7 @@ def extract_encrypted(base_dir, password):
|
|||||||
FROM Files
|
FROM Files
|
||||||
WHERE relativePath
|
WHERE relativePath
|
||||||
LIKE 'Message/Media/%'"""
|
LIKE 'Message/Media/%'"""
|
||||||
)
|
)
|
||||||
if not os.path.isdir("Message"):
|
if not os.path.isdir("Message"):
|
||||||
os.mkdir("Message")
|
os.mkdir("Message")
|
||||||
if not os.path.isdir("Message/Media"):
|
if not os.path.isdir("Message/Media"):
|
||||||
@@ -43,7 +46,7 @@ def extract_encrypted(base_dir, password):
|
|||||||
flags = row[2]
|
flags = row[2]
|
||||||
file = row[3]
|
file = row[3]
|
||||||
if flags == 2:
|
if flags == 2:
|
||||||
try:
|
try:
|
||||||
os.mkdir(destination)
|
os.mkdir(destination)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
@@ -56,6 +59,7 @@ def extract_encrypted(base_dir, password):
|
|||||||
print(f"Gathering media...({i}/{total_row_number})", end="\r")
|
print(f"Gathering media...({i}/{total_row_number})", end="\r")
|
||||||
print(f"Gathering media...({total_row_number}/{total_row_number})", end="\r")
|
print(f"Gathering media...({total_row_number}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|
||||||
def is_encrypted(base_dir):
|
def is_encrypted(base_dir):
|
||||||
with sqlite3.connect(f"{base_dir}/Manifest.db") as f:
|
with sqlite3.connect(f"{base_dir}/Manifest.db") as f:
|
||||||
c = f.cursor()
|
c = f.cursor()
|
||||||
@@ -68,6 +72,7 @@ def is_encrypted(base_dir):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def extract_media(base_dir):
|
def extract_media(base_dir):
|
||||||
if is_encrypted(base_dir):
|
if is_encrypted(base_dir):
|
||||||
if not support_encrypted:
|
if not support_encrypted:
|
||||||
|
|||||||
9
setup.py
9
setup.py
@@ -12,12 +12,13 @@ setuptools.setup(
|
|||||||
version=version,
|
version=version,
|
||||||
author="KnugiHK",
|
author="KnugiHK",
|
||||||
author_email="info@knugi.com",
|
author_email="info@knugi.com",
|
||||||
description="A Whatsapp database parser that will give you the history of your Whatsapp conversations in HTML and JSON.",
|
description="A Whatsapp database parser that will give you the "
|
||||||
|
"history of your Whatsapp conversations in HTML and JSON.",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://github.com/KnugiHK/Whatsapp-Chat-Exporter",
|
url="https://github.com/KnugiHK/Whatsapp-Chat-Exporter",
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
package_data = {
|
package_data={
|
||||||
'': ['whatsapp.html']
|
'': ['whatsapp.html']
|
||||||
},
|
},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
@@ -38,7 +39,7 @@ setuptools.setup(
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
'jinja2'
|
'jinja2'
|
||||||
],
|
],
|
||||||
extras_require = {
|
extras_require={
|
||||||
'android_backup': ["pycryptodome"]
|
'android_backup': ["pycryptodome"]
|
||||||
},
|
},
|
||||||
entry_points={
|
entry_points={
|
||||||
@@ -46,4 +47,4 @@ setuptools.setup(
|
|||||||
"wtsexporter = Whatsapp_Chat_Exporter.__main__:main"
|
"wtsexporter = Whatsapp_Chat_Exporter.__main__:main"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user