sshare/sshare

58 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
import getpass
import importlib.util
import os
import os.path
import pyclip
import time
import subprocess
import sys
def main():
config = Config()
file = _latest("/home/gnarwhal/Pictures/Screenshots")
(_, extension) = os.path.splitext(file)
id = time.time_ns()
target_file_name = f"{id}{extension}"
print(f"=> Selected file '{file}'")
target_url = f"https://{config.ssh_target}/sshare/{target_file_name}"
pyclip.copy(target_url)
subprocess.run([
"scp",
f"-P {config.ssh_port}",
file,
f"{config.ssh_user}@{config.ssh_target}:{config.ssh_dir}/{target_file_name}",
])
print(f"=> File uploaded to {target_url}")
def _latest(directory, key=os.path.getmtime):
files = map(lambda file: f"{directory}/{file}", os.listdir(directory))
selection = next(files)
selection_key = key(selection)
for file in files:
new_key = key(file)
if new_key > selection_key:
selection = file
selection_key = key
return selection
class Config:
def __init__(self):
self.ssh_port = 2222
self.ssh_user = getpass.getuser()
self.ssh_target = "monodon.me"
self.ssh_dir = "~/sshare/"
if __name__ == '__main__':
main()