#!/usr/bin/env python3
from __future__ import unicode_literals

import hashlib
import urllib.request
import json

versions_info = json.load(open('update/versions.json'))
version = versions_info['latest']
URL = versions_info['versions'][version]['bin'][0]

data = urllib.request.urlopen(URL).read()

# Read template page
with open('download.html.in', 'r', encoding='utf-8') as tmplf:
    template = tmplf.read()

sha256sum = hashlib.sha256(data).hexdigest()
template = template.replace('@PROGRAM_VERSION@', version)
template = template.replace('@PROGRAM_URL@', URL)
template = template.replace('@PROGRAM_SHA256SUM@', sha256sum)
template = template.replace('@EXE_URL@', versions_info['versions'][version]['exe'][0])
template = template.replace('@EXE_SHA256SUM@', versions_info['versions'][version]['exe'][1])
template = template.replace('@TAR_URL@', versions_info['versions'][version]['tar'][0])
template = template.replace('@TAR_SHA256SUM@', versions_info['versions'][version]['tar'][1])
with open('download.html', 'w', encoding='utf-8') as dlf:
    dlf.write(template)

@@ -61,45 +61,8 @@
 ls%0A%0A
-import hashlib%0Aimport urllib.request%0A
 impo
@@ -69,16 +69,16 @@
 rt json%0A
+
 %0Aversion
@@ -160,19 +160,28 @@
 atest'%5D%0A
-URL
+version_dict
  = versi
@@ -213,61 +213,8 @@
 ion%5D
-%5B'bin'%5D%5B0%5D%0A%0Adata = urllib.request.urlopen(URL).read()
 %0A%0A# 
@@ -328,53 +328,8 @@
 ()%0A%0A
-sha256sum = hashlib.sha256(data).hexdigest()%0A
 temp
@@ -427,19 +427,38 @@
 _URL@', 
-URL
+version_dict%5B'bin'%5D%5B0%5D
 )%0Atempla
@@ -506,17 +506,30 @@
 @', 
-sha256sum
+version_dict%5B'bin'%5D%5B1%5D
 )%0Ate
@@ -578,35 +578,13 @@
 sion
-s_info%5B'versions'%5D%5Bversion%5D
+_dict
 %5B'ex
@@ -649,35 +649,13 @@
 sion
-s_info%5B'versions'%5D%5Bversion%5D
+_dict
 %5B'ex
@@ -714,35 +714,13 @@
 sion
-s_info%5B'versions'%5D%5Bversion%5D
+_dict
 %5B'ta
@@ -785,35 +785,13 @@
 sion
-s_info%5B'versions'%5D%5Bversion%5D
+_dict
 %5B'ta

Use program checksum from versions.json