-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.py
More file actions
155 lines (120 loc) · 4.66 KB
/
cli.py
File metadata and controls
155 lines (120 loc) · 4.66 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import typer
from agentx.seo import analyze_seo, get_keyword_suggestions, optimize_metadata
from agentx.performance import monitor_api, log_performance
from agentx.scraper import scrape_website
import click
import subprocess
import time
app = typer.Typer()
@app.command()
def optimize(url: str = typer.Argument(..., help="The URL of the webpage to optimize")):
"""
Optimize SEO for the provided webpage URL.
"""
typer.echo("Running SEO Optimization and Performance Monitoring...")
url = "https://ayushhh.medium.com/summer-of-bitcoin23-my-experience-1357a0f16495"
typer.echo(f"\nVisit this site: http://localhost:5000/seo?url={url}\n")
# seo_report = analyze_seo(url)
# typer.echo(f"SEO Report: {seo_report}")
# keyword_data = get_keyword_suggestions(url)
# typer.echo(f"Keyword Suggestions: {keyword_data}")
# current_html = "<html>... current metadata ...</html>"
# optimized_html = optimize_metadata(current_html)
# typer.echo("Optimized Metadata:")
# typer.echo(optimized_html)
# Monitor and log API performance
performance_report = monitor_api()
log_performance(performance_report)
# typer.echo("Performance data logged.")
@app.command()
def scrape():
url = typer.prompt("Enter the website URL")
typer.echo("Ensuring Playwright browsers are installed...")
try:
subprocess.run(["playwright", "install"], check=True)
except subprocess.CalledProcessError as e:
typer.echo("Failed to install Playwright dependencies.")
raise e
try:
process = subprocess.Popen(["python", "api.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except Exception as e:
typer.echo(f"Failed to start the API server: {e}")
raise e
time.sleep(2)
typer.echo("Flask API server started in the background.")
typer.echo(f"Access the scraped JSON at: http://127.0.0.1:5000/scrape?url={url}")
typer.echo("Press Ctrl+C to exit and stop the API server.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
typer.echo("Exiting CLI and terminating API server...")
process.terminate()
process.wait()
@app.command()
def brokenlink():
url = typer.prompt("Enter the website URL")
try:
process = subprocess.Popen(["python", "api.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except Exception as e:
typer.echo(f"Failed to start the API server: {e}")
raise e
time.sleep(2)
typer.echo("Flask API server started in the background.")
typer.echo(f"Access the scraped JSON at: http://127.0.0.1:5000/errorlink?url={url}")
typer.echo("Press Ctrl+C to exit and stop the API server.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
typer.echo("Exiting CLI and terminating API server...")
process.terminate()
process.wait()
@app.command()
def fix_errors():
url = typer.prompt("Enter the website URL")
try:
process = subprocess.Popen(["python", "api.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except Exception as e:
typer.echo(f"Failed to start the API server: {e}")
raise e
time.sleep(2)
typer.echo("Flask API server started in the background.")
typer.echo(f"Access the scraped JSON at: http://127.0.0.1:5000/update?url={url}")
typer.echo("Press Ctrl+C to exit and stop the API server.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
typer.echo("Exiting CLI and terminating API server...")
process.terminate()
process.wait()
@app.command()
def generate_content():
url = typer.prompt("Enter the website URL")
try:
process = subprocess.Popen(["python", "api.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except Exception as e:
typer.echo(f"Failed to start the API server: {e}")
raise e
time.sleep(2)
typer.echo("Flask API server started in the background.")
typer.echo(f"Access the scraped JSON at: http://127.0.0.1:5000/add?url={url}")
typer.echo("Press Ctrl+C to exit and stop the API server.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
typer.echo("Exiting CLI and terminating API server...")
process.terminate()
process.wait()
if __name__ == "__main__":
app()