-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint-bot.py
75 lines (64 loc) · 2.17 KB
/
print-bot.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
import requests
from bs4 import BeautifulSoup
import webbrowser
import time
import pyautogui
import pyperclip
import os
def python_langchain():
url = 'https://js.langchain.com/docs/'
reqs = requests.get(url)
soup = BeautifulSoup(reqs.text, 'html.parser')
chrome_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'
urls = []
cnt = 0
for link in soup.find_all('a'):
href = link.get('href')
if href is None:
continue
if href.startswith("/") and href != "/":
if not href in urls:
print(href)
urls.append(href)
pyperclip.copy(f"{cnt}.pdf")
webbrowser.get(chrome_path).open(f"{url}{href}")
time.sleep(5)
pyautogui.hotkey('ctrl', 'p')
time.sleep(2)
pyautogui.press('enter')
time.sleep(2)
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
pyautogui.press('enter')
time.sleep(1)
pyautogui.hotkey('ctrl', 'w')
cnt += 1
cnt = 0
def visit_dir(directory):
global cnt
for root, _, files in os.walk(directory):
for file in files:
if os.path.exists(f"D:/resource/avatars/{cnt}.pdf"):
cnt += 1
continue
url = str(os.path.join(root, file))
url = url.replace("index.mdx", "").replace("index.md", "").replace(
".mdx", "").replace(".md", "").replace("\\", "/").replace("docs/", "")
url = "https://js.langchain.com/docs/" + url
pyperclip.copy(f"{cnt}.pdf")
webbrowser.get(
'C:/Program Files/Google/Chrome/Application/chrome.exe %s').open(url)
time.sleep(10)
pyautogui.hotkey('ctrl', 'p')
time.sleep(2)
pyautogui.press('enter')
time.sleep(2)
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
pyautogui.press('enter')
time.sleep(1)
pyautogui.hotkey('ctrl', 'w')
cnt += 1
def js_langchain():
visit_dir("docs")
js_langchain()