|
import os
|
|
import time
|
|
import paramiko
|
|
import compiler
|
|
import nycklar.nodes as nodes
|
|
|
|
def conecta():
|
|
|
|
|
|
ssh = paramiko.SSHClient()
|
|
ssh.load_host_keys("nycklar/itrst")
|
|
|
|
|
|
project_dir = os.getcwd()
|
|
key_filename = os.path.join(project_dir, "nycklar", "go")
|
|
|
|
ssh.connect(nodes.realm, username=nodes.master, key_filename=key_filename)
|
|
sftp = ssh.open_sftp()
|
|
|
|
return ssh, sftp
|
|
|
|
def obtenCaja(userfile):
|
|
|
|
|
|
ruta_remota = nodes.avaimentekijä
|
|
print("Encoding...")
|
|
userfile_codificado = userfile.encode("utf-8")
|
|
|
|
print("Sending to compiler.")
|
|
username = compiler.do(userfile_codificado)
|
|
print("Username is: ", username)
|
|
caja = ruta_remota + username + ".txt"
|
|
|
|
return caja
|
|
|
|
def obtenTokens(sftp, caja):
|
|
|
|
with sftp.open(caja, 'rb') as archivo:
|
|
|
|
contenido_bytes = archivo.read()
|
|
|
|
tokens = contenido_bytes.decode('utf-8')
|
|
|
|
tokens = int(tokens)
|
|
|
|
return tokens
|
|
|
|
def restaToken(sftp, caja, tokens, work):
|
|
|
|
|
|
cuantos = 2
|
|
|
|
|
|
if work == 'picswap':
|
|
cuantos = 1
|
|
print(f"Work: {work}, tokens cost: {cuantos}")
|
|
time.sleep(1)
|
|
else:
|
|
print("The work specified doesn't exists.")
|
|
|
|
|
|
contenido_final = int(tokens) - cuantos
|
|
contenido_final = str(contenido_final)
|
|
|
|
|
|
print(contenido_final)
|
|
|
|
|
|
with sftp.open(caja, 'w') as archivo:
|
|
|
|
archivo.write(contenido_final)
|
|
|
|
return contenido_final
|
|
|
|
def cierraConexion(ssh, sftp ):
|
|
|
|
sftp.close()
|
|
ssh.close() |