2020-08-20 17:57:32 +00:00
|
|
|
import argparse
|
2020-05-15 04:40:50 +00:00
|
|
|
import pyperclip
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from voussoirkit import passwordy
|
2020-08-20 17:57:32 +00:00
|
|
|
from voussoirkit import pathclass
|
2020-05-15 04:40:50 +00:00
|
|
|
|
2020-08-20 17:57:32 +00:00
|
|
|
def loop_once(extension):
|
2020-05-15 04:40:50 +00:00
|
|
|
try:
|
|
|
|
text = pyperclip.paste()
|
|
|
|
except Exception:
|
|
|
|
return
|
|
|
|
|
2020-08-20 17:57:32 +00:00
|
|
|
text = text.strip()
|
|
|
|
|
|
|
|
if len(text.split(sep=None, maxsplit=1)) > 1:
|
2020-05-15 04:40:50 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if 'http://' in text or 'https://' in text:
|
2020-08-20 17:57:32 +00:00
|
|
|
path = pathclass.Path(passwordy.urandom_hex(12)).add_extension(extension)
|
2020-05-15 04:40:50 +00:00
|
|
|
pyperclip.copy('')
|
2020-08-20 17:57:32 +00:00
|
|
|
print(path.basename, text)
|
|
|
|
h = open(path.absolute_path, 'w', encoding='utf-8')
|
2020-05-15 04:40:50 +00:00
|
|
|
h.write(text)
|
|
|
|
h.close()
|
|
|
|
|
2020-08-20 17:57:32 +00:00
|
|
|
def loop_forever(extension):
|
2020-05-15 04:40:50 +00:00
|
|
|
while True:
|
2020-08-20 17:57:32 +00:00
|
|
|
loop_once(extension=extension)
|
2020-05-15 04:40:50 +00:00
|
|
|
time.sleep(1)
|
|
|
|
|
2020-08-20 17:57:32 +00:00
|
|
|
def watchforlinks_argparse(args):
|
2020-05-15 04:40:50 +00:00
|
|
|
try:
|
2020-08-20 17:57:32 +00:00
|
|
|
loop_forever(extension=args.extension)
|
2020-05-15 04:40:50 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
|
2020-08-20 17:57:32 +00:00
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
|
|
|
parser.add_argument('extension', nargs='?', default='generic')
|
|
|
|
parser.set_defaults(func=watchforlinks_argparse)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
return args.func(args)
|
2020-05-15 04:40:50 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|