-
Notifications
You must be signed in to change notification settings - Fork 35
/
ddc.py
85 lines (71 loc) · 2.49 KB
/
ddc.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import time
import os
import random
import subprocess
import json
import re
from behavior.behavior import humanMove, humanTyping
from target import target
import pyautogui
"""
Important:
1. Update the coordinates of the browser url address bar. Use the command `xdotool getmouselocation` to detect coordinates on your screen.
2. Do not change the zoom level for the page in the browser! This will mess with coordinates! Default level must be 100% zoom level.
3. I assume that the binary name of Google Chrome is `google-chrome`. Change the code if your binary name is different.
4. Make sure the browser window is started in your leftmost screen!
I have a dual screen setup and sometimes I need to manually move my browser window to the correct screen ;)
"""
# collect keys
keys = []
def getCoords(n):
cmd = f'node coords.js "p:nth-of-type({n}) > a"'
# print(cmd)
coords = subprocess.check_output(cmd, shell=True).decode('utf8').strip()
# print(coords)
return json.loads(coords)
def getKey():
cmd = f'/usr/bin/node page_source'
ps = subprocess.check_output(cmd, shell=True).decode('utf8').strip()
if 'Not found' in ps:
return 'done'
else:
key = re.search(r'[0-9a-z]{32}', ps)
return key.group(0)
def visitPage():
# @UPDATE COORDINATES HERE
humanMove(168, 79) # click on the address bar to enter URL
pyautogui.typewrite(target)
# the following is not necessary, because JavaScript cannot record
# keydown/keyup events in the address bar
# humanTyping(target, speed=None, doubleHit=False)
time.sleep(random.uniform(1.95, 2.95))
def main():
"""
Get pixel coords with: `xdotool getmouselocation`
"""
os.system('google-chrome --remote-debugging-port=9222 --start-maximized --disable-notifications &')
time.sleep(4)
try:
while True:
time.sleep(random.uniform(.95, 1.25))
visitPage()
parsed = getCoords(random.randrange(1, 11))
keys.append(getKey())
for i in range(11):
x = parsed['x'] + random.randrange(0, int(parsed['width']))
y = parsed['y'] + random.randrange(0, int(parsed['height']))
# print(f'x={x}, y={y}')
humanMove(x, y)
time.sleep(random.uniform(1.15, 1.74))
key = getKey()
if key == 'done':
break
else:
keys.append(key)
parsed = getCoords(random.randrange(1, 11))
print(f'Got {len(set(keys))} unique keys')
except (Exception, KeyboardInterrupt) as e:
print(f'Error: {e}')
print(keys)
if __name__ == '__main__':
main()