Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import time
- from prompter import yesno
- import os.path
- import os
- import zipfile
- import urllib.request
- import requests
- import queue
- import math
- from ruamel.std.zipfile import delete_from_zip_file
- from winreg import *
- queue.Queue()
- #cesta = Assets\CS_addon\Smejki\RailVehicles\Electric\460080\ActualizationAutoRun\
- class Download:
- def download_file(self,url,basepath):
- procenta = 0
- procentastare = 0
- local_filename = os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip"))
- r = requests.get(url, stream=True)
- with open(local_filename, 'wb') as f:
- for chunk in r.iter_content(chunk_size=1024):
- if chunk:
- f.write(chunk)
- if math.floor(procenta) != procentastare:
- procentastare = math.floor(procenta)
- print("Staženo cca. "+str(math.floor(procenta))+"%")
- procenta = procenta + 0.00068990608114481
- return local_filename
- class Main:
- def __init__(self):
- download = Download()
- basepath = os.getcwd()
- filepath = os.path.abspath(os.path.join(basepath, "Dialogs", "DriverInstructions" ,"AssignmentDialogListItem.ed"))
- try:
- staraverzef = open(filepath, "r")
- staraverze = staraverzef.read()
- staraverzef.close()
- except:
- print("Soubor stará verze nebyl nalezen!")
- input(os.getcwd())
- staraverze = 0
- if staraverze == "":
- staraverze = "0"
- with urllib.request.urlopen("http://jachyhm.cz/verze460.txt") as url:
- novaverze = int(url.read())
- if int(staraverze) < int(novaverze):
- try:
- print("Aktualizace EMU460!")
- print("Stahuji!")
- download.download_file("http://jachyhm.cz/460autoaktualizace.rwp",basepath)
- except:
- print("Chyba při stahování! Nelze navázat spojení se serverem!")
- else:
- print("Úspěšně staženo, rozbaluji...")
- delete_from_zip_file(os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip")), pattern=".*.exe")
- with zipfile.ZipFile(os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip")),"r") as zip_ref:
- zip_ref.extractall(os.path.abspath(basepath))
- novaverzef = open(filepath, "w")
- novaverzef.write(str(novaverze))
- novaverzef.close()
- os.remove(os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip")))
- m=Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement