Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Python-based Signal APK downloader
#!/usr/bin/env python3
import requests
import urllib.request
import hashlib
import sys
from simplejson.errors import JSONDecodeError
url = "https://updates.signal.org/android/latest.json"
try:
response = requests.get(url=url)
data = response.json()
except JSONDecodeError:
print("ERROR: Can't decode json file.")
sys.exit(1)
except requests.exceptions.ConnectionError:
print("ERROR: Can't connect to signal.org.")
sys.exit(1)
print("Signal APK download from signal.org")
print("Available version: {}".format(data["versionName"]))
decision = input("Do you want to download this version? (y/N) ")
if decision in ("y, Y, yes, Yes"):
print(" Starting download …")
url_parts = data["url"].split("/")
file_name = url_parts[4]
original_sha256 = data["sha256sum"]
with urllib.request.urlopen(data["url"]) as response, \
open(file_name, 'wb') as out_file:
data = response.read()
out_file.write(data)
print(" Download complete.")
decision = input("Do you want to check file integrity? (y/N) ")
if decision in ("y, Y, yes, Yes"):
sha256_hash = hashlib.sha256()
with open(file_name, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
if sha256_hash.hexdigest() == original_sha256:
print(" Integrity check okay.")
else:
print(" ERROR: Hashes differ.")
print("Done. Good bye.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.