2019-05-09 11:59:28
-------------------

I wrote myself a hacky little uploader script, that uses Python3(.5+?) to
automagically create an SFTP batch script, for uploading here. The only thing
you need to do is provide it the name of the file(s) that you want to launch to
space.

Here it is in all it's cobbled together glory:


#!/usr/bin/env python3
import os
import subprocess
import tempfile
from pathlib import Path

LOCAL_GOPHER_CONTENT = '/path/to/circumlunar.space'
SUNDOG_NAME = 'wangofett'

files_to_sync = [
   #Path('random/test/test.txt'),
   #Path('random/test/test_two.txt'),
]

with tempfile.NamedTemporaryFile(mode='w+') as commands:
   print('cd gopher', file=commands)

   for file in files_to_sync:
       parts = file.parent.parts
       mkdir = '-mkdir '
       for part in parts:
           mkdir += part + '/'
           print(mkdir, file=commands)
           print(mkdir.replace('mkdir','chmod 705'), file=commands)

       print('put', file, file.parent, file=commands)
       print('chmod 704', file, file=commands)
   commands.flush()
   commands.seek(0)
   os.chdir(LOCAL_GOPHER_CONTENT)
   cmd = ['sftp', '-b', commands.name, f'{SUNDOG_NAME}@circumlunar.space']
   subprocess.run(cmd)