-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathykgodot.py
executable file
·47 lines (42 loc) · 1.18 KB
/
ykgodot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/python
import time
from subprocess import check_call,DEVNULL
from urllib.parse import urlparse
import pyperclip
# Remember to run tldextract --update as root.
import tldextract
from retrying import retry
try:
from pync import Notifier
def notify(text):
Notifier.notify(text, title='YK Godot')
except ImportError:
try:
from gi.repository import Notify
def notify(text):
app='YK Godot'
Notify.init(app)
notification = Notify.Notification.new(app, text, 'dialog-information')
notification.show()
except ImportError:
def notify(text):
pass
@retry(stop_max_delay=10000,wait_fixed=20)
def wait_for_card():
check_call(["gpg", "--card-status"], stdout=DEVNULL, stderr=DEVNULL)
def generate_password(domain):
check_call(["pass", "-c", domain], stdout=DEVNULL, stderr=DEVNULL)
old_value = pyperclip.paste()
while True:
current_value = pyperclip.paste()
if current_value != old_value:
old_value = current_value
domain = tldextract.extract(urlparse(current_value).netloc).domain
if domain:
try:
wait_for_card()
generate_password(domain)
notify('Password copied')
except:
pass
time.sleep(0.2)