diff --git a/Whatsapp_Chat_Exporter/__main__.py b/Whatsapp_Chat_Exporter/__main__.py index d9d6164..8111a4b 100644 --- a/Whatsapp_Chat_Exporter/__main__.py +++ b/Whatsapp_Chat_Exporter/__main__.py @@ -6,7 +6,7 @@ from Whatsapp_Chat_Exporter import extract from Whatsapp_Chat_Exporter import extract_iphone from Whatsapp_Chat_Exporter import extract_iphone_media from Whatsapp_Chat_Exporter.data_model import ChatStore -from Whatsapp_Chat_Exporter.utility import Crypt +from Whatsapp_Chat_Exporter.utility import Crypt, check_update from argparse import ArgumentParser import os import sqlite3 @@ -137,8 +137,20 @@ def main(): action='store_true', help="Do not output html files" ) + parser.add_argument( + "--check-update", + dest="check_update", + default=False, + action='store_true', + help="Check for updates" + ) args = parser.parse_args() + # Check for updates + if args.check_update: + exit(check_update()) + + # Sanity checks if args.android and args.iphone: print("You must define only one device type.") exit(1) diff --git a/Whatsapp_Chat_Exporter/utility.py b/Whatsapp_Chat_Exporter/utility.py index 6adcfde..960b8c4 100644 --- a/Whatsapp_Chat_Exporter/utility.py +++ b/Whatsapp_Chat_Exporter/utility.py @@ -38,6 +38,36 @@ def brute_force_offset(max_iv=200, max_db=200): for db in range(0, max_db): yield iv, iv + 16, db +def check_update(): + import urllib.request + import json + from sys import platform + from .__init__ import __version__ + + package_url_json = "https://pypi.org/pypi/whatsapp-chat-exporter/json" + try: + raw = urllib.request.urlopen(package_url_json) + except Exception: + print("Failed to check for updates.") + return 1 + else: + with raw: + package_info = json.load(raw) + latest_version = tuple(map(int, package_info["info"]["version"].split("."))) + current_version = tuple(map(int, __version__.split("."))) + if current_version < latest_version: + print("===============Update===============") + print("A newer version of WhatsApp Chat Exporter is available.") + print("Current version: " + __version__) + print("Latest version: " + package_info["info"]["version"]) + if platform == "win32": + print("Update with: pip install --upgrade whatsapp-chat-exporter") + else: + print("Update with: pip3 install --upgrade whatsapp-chat-exporter") + print("====================================") + else: + print("You are using the latest version of WhatsApp Chat Exporter.") + return 0 # iOS Specific