Skip to content

Instantly share code, notes, and snippets.

@deadda7a
Created June 19, 2020 18:53
Show Gist options
  • Save deadda7a/76afd2654ef15b7787032904f1baa10a to your computer and use it in GitHub Desktop.
Save deadda7a/76afd2654ef15b7787032904f1baa10a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import urllib.request
import hashlib
import os
import shutil
from bs4 import BeautifulSoup
import sys
import time
def dlProgress(count, block_size, total_size):
global start_time
if count == 0:
start_time = time.time()
return
duration = time.time() - start_time
progress_size = int(count * block_size)
speed = int(progress_size / (1024 * duration))
percent = int(count * block_size * 100 / total_size)
sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds passed" %
(percent, progress_size / (1024 * 1024), speed, duration))
sys.stdout.flush()
page = urllib.request.urlopen('https://www.realvnc.com/de/connect/download/viewer/linux/')
suppe = BeautifulSoup(page, "html5lib")
downloadlinks = suppe.findAll("div", attrs={"class": "download-link"})
for link in downloadlinks:
if (link.find("span", attrs={"class": "download-link-type"}).text == "(DEB x64)"):
url = "https://www.realvnc.com" + link.find("a")["href"]
filename = url.split('/')[-1]
filetype = link.find("span", attrs={"class": "download-link-type"}).text
checksum = link.find("p", attrs={"class": "checksum"}).text
checksum = checksum.replace("SHA-256: ", "")
print("RealVNC: " + filename)
match = False
while not match:
urllib.request.urlretrieve(url, filename, reporthook=dlProgress)
downloadedHash = hashlib.sha256(open(filename, 'rb').read()).hexdigest()
print("\nsha256sum not matching")
if (downloadedHash == checksum):
match = True
print("sha256sum matched")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment