-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutomation_project.py
56 lines (38 loc) · 1.54 KB
/
Automation_project.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
import webbrowser, re
from googlesearch import search
def get_first_google_link(query_to_search):
try:
# Perform a Google search and get the first result
search_results = search(query_to_search, num_results=1)
first_result = next(search_results, None)
if first_result:
print(f"Opening the first result: {first_result}")
# Open the first result in the default web browser
webbrowser.open(first_result)
else:
print("No search results found.")
except Exception as e:
print(f"An error occurred: {e}")
def extract_headlines(file_path):
headlines = []
try:
with open(file_path, 'r', encoding='utf-8') as readme_file:
for line in readme_file:
# Use a regular expression to match Markdown-style headlines (lines starting with ##)
match = re.match(r'^##\s+(.+)', line)
if match:
headline = match.group(1)
headlines.append(headline)
except FileNotFoundError:
print(f"File not found: {file_path}")
return headlines
if __name__ == "__main__":
# Path to README file
readme_path = input("Enter the path to your README file: ")
headlines = extract_headlines(readme_path)
if headlines:
number = int(input("Type the number of the book: ")) - 1
query_to_search = str(headlines[number]) + " " + "read"
pdf_url = get_first_google_link(query_to_search)
else:
print("No headlines found.")