Skip to content

Instantly share code, notes, and snippets.

@elpatron68
Created July 15, 2017 17:20
Show Gist options
  • Save elpatron68/49d1dae1c736a6ec8e541a7e87b4b3cf to your computer and use it in GitHub Desktop.
Save elpatron68/49d1dae1c736a6ec8e541a7e87b4b3cf to your computer and use it in GitHub Desktop.
Ssh-upload Racing Room dedicated server result files for use with simresults.net
import os
import paramiko
from paramiko import SSHClient
from scp import SCPClient
from datetime import datetime
import webbrowser
# Constants (Settings)
SERVERADDRESS = '<Web server ip or domain name>'
SSHUSER = '<Ssh user name>'
SSHKEY = r'C:\path\to\ssh\private\key.key'
# Absolute path for upload
SERVERPATHABS = '~/html/simresults/'
# Realtive path (from webserver root)
SERVERPATHREL = '/simresults/'
RESULTPATH = r'C:\Users\<windows user>\AppData\Local\Sector3_Studios_AB\results\66416'
LEAGUENAME = '<League name>'
def uploadresults():
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# ssh.load_host_keys(SSHKEY)
print('Connection to server: ' + SERVERADDRESS)
ssh.connect(SERVERADDRESS, username=SSHUSER, key_filename=SSHKEY)
for file in os.listdir(RESULTPATH):
print('Processing file: ' + file)
print('Initialising ssh transport...')
scp = SCPClient(ssh.get_transport())
print('Uploading file...')
scp.put(RESULTPATH + '\\' + file, SERVERPATHABS + file)
print('Creating JSON results file')
jsonfile = createjson()
print('Uploading JSON results file')
scp.put(jsonfile, SERVERPATHABS + 'results.json')
def createjson():
index = 0
jsontext = ('{\n'
'"name":"' + LEAGUENAME + '",\n'
'"results":[\n')
for file in os.listdir(RESULTPATH):
timestamp = os.path.getctime(RESULTPATH + '\\' + file)
local_time = datetime.fromtimestamp(timestamp).strftime('%d.%m.%Y %H:%M:%S')
path = 'http://' + SERVERADDRESS + SERVERPATHREL + file
index += 1
jsontext += ('{\n'
'"name":"Result #' + str(index) + ' (' + local_time + ')",\n'
'"log":"' + path + '"\n'
'},\n')
# Remove last char (Komma)
jsontext = jsontext[:-2] + '\n]}'
# Write to file
jsonfile = r'.\results.json'
with open(jsonfile, 'w') as file:
file.write(jsontext)
return jsonfile
if __name__ == '__main__':
uploadresults()
url = 'http://simresults.net/remote?results=https://' + SERVERADDRESS + SERVERPATHREL + 'results.json'
webbrowser.open(url)
print('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment