r/PyScript • • Jun 17 '22

How can I change the variable of JavaScript in pyscript?

I'm using pyscript. And I want to change the variable of JavaScript in pyscript.

For Example :

Python File Code :

import string
import os

#Program Version
py_current_version = 0
#Server Version
py_server_version = 0

#Get Program Version
f = open("version.txt", "r")

lines = f.readlines()
for line in lines:
    py_current_version = line;
f.close()

#Get Server Version
f = open("https://common.gaon.xyz/proj/MCD/versions.txt", "r")

lines = f.readlines()
for line in lines:
    py_server_version = line;
f.close()

if py_current_version == py_server_version:
    no_update_available = 1
else:
    no_update_available = 0
    os.system('wget https://common.gaon.xyz/MCD/latest.zip')
    update_file_download_complete = 1
    os.system('7z x latest.zip')
    update_complete = 1
    os.system('notepad changelog.txt')

HTML File Code :

<!DOCTYPE html>
<html>
	<head>
		<title>Updater</title>
		<meta charset="utf-8">
		<!--Load CSS-->
		<!--Load Bootstrap-->
		<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<!--Load Updater Style CSS-->
		<link href="./updater_style.css" rel="stylesheet">
		<!--Load PyScript-->
		<link href="./pyscript/pyscript.css" rel="stylesheet">
		<!--Load jQuery-->
		<script src="./jquery/3.6.0/jquery.min.js"></script>
	</head>
	<body>
		<style>
		
		</style>
		<script>
			function wait(sec) {
    			let start = Date.now(), now = start;
    			while (now - start < sec * 1000) {
        			now = Date.now();
    			}
			}

			var no_update_available;
			var update_file_download_complete;
			var update_complete;

			if(no_update_available == 0)
			{
				$("#progress_contents_ptag").text("Update Found!");
				document.getElementById("update_progress").value = 5;
				wait(3);
				$("#progress_contents_ptag").text("Downloading update file...");
				document.getElementById("update_progress").value = 10;

				if(update_file_download_complete == 1)
				{
					$("#progress_contents_ptag").text("Update file download complete!");
					document.getElementById("update_progress").value = 30;
					wait(3);
					$("#progress_contents_ptag").text("Terminating process...");
					document.getElementById("update_progress").value = 50;
					wait(3);
					$("#progress_contents_ptag").text("Extracting update file...");
					document.getElementById("update_progress").value = 80;
					if(update_complete == 1)
					{
						$("#progress_contents_ptag").text("Update completed! It will end in a few seconds.");
						document.getElementById("update_progress").value = 100;
						wait(3);
						exit();
					}
				}
			}
			else if(no_update_available == 1)
			{
				$("#progress_contents_ptag").text("There are no updates. It will end in a few seconds");
				$("#cancle_button").text("Close");
				wait(5);
				exit();
			}
		</script>
		<div id="contents_body">
			<div id="progress_contents">
				<p id="progress_contents_ptag" class="progress_title">Checking Update!</p>
			</div>
			<progress id="update_progress" max="100" value="0"></progress>
			<br><br>
			<button id="cancle_button" type="button" class="btn btn-secondary" onclick="exits()">취소</button>
		</div>

		<script>
			function exits(){
				window.close();
			}
		</script>
		<!--Load Scripts-->
		<!--Load Bootstrap-->
		<script src="./bootstrap/js/bootstrap.bundle.min.js"></script>
		<!--Load PyScript-->
		<script src="./pyscript/pyscript.js"></script>
		<py-env>
  - string
  - os
  - path:
  	- ./updater.py
</py-env>
		<!--
		<py-script src="./updater.py"></py-script>
		-->
	</body>
</html>

I want to change javascript's variable in pyscript. What should I do?

4 Upvotes

0 comments sorted by