Add --regex option to only watch certain links.
This commit is contained in:
parent
2412a6ee35
commit
723dcee420
1 changed files with 18 additions and 11 deletions
|
@ -1,12 +1,13 @@
|
|||
import argparse
|
||||
import pyperclip
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
from voussoirkit import passwordy
|
||||
from voussoirkit import pathclass
|
||||
|
||||
def loop_once(extension):
|
||||
def loop_once(extension, regex=None):
|
||||
try:
|
||||
text = pyperclip.paste()
|
||||
except Exception:
|
||||
|
@ -17,7 +18,12 @@ def loop_once(extension):
|
|||
if len(text.split(sep=None, maxsplit=1)) > 1:
|
||||
return
|
||||
|
||||
if 'http://' in text or 'https://' in text:
|
||||
if 'http://' not in text and 'https://' not in text:
|
||||
return
|
||||
|
||||
if regex and not re.search(regex, text):
|
||||
return
|
||||
|
||||
path = pathclass.Path(passwordy.urandom_hex(12)).add_extension(extension)
|
||||
pyperclip.copy('')
|
||||
print(path.basename, text)
|
||||
|
@ -25,14 +31,14 @@ def loop_once(extension):
|
|||
h.write(text)
|
||||
h.close()
|
||||
|
||||
def loop_forever(extension):
|
||||
def loop_forever(extension, regex):
|
||||
while True:
|
||||
loop_once(extension=extension)
|
||||
loop_once(extension=extension, regex=regex)
|
||||
time.sleep(1)
|
||||
|
||||
def watchforlinks_argparse(args):
|
||||
try:
|
||||
loop_forever(extension=args.extension)
|
||||
loop_forever(extension=args.extension, regex=args.regex)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
@ -40,6 +46,7 @@ def main(argv):
|
|||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
|
||||
parser.add_argument('extension', nargs='?', default='generic')
|
||||
parser.add_argument('--regex', dest='regex', default=None)
|
||||
parser.set_defaults(func=watchforlinks_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
|
Loading…
Reference in a new issue