-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
64 lines (55 loc) · 2.76 KB
/
Copy pathcli.py
File metadata and controls
64 lines (55 loc) · 2.76 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
import os
import typer
from rich.panel import Panel
from rich.console import Console
console = Console()
@app.command()
def setup():
"""Configure ClearSky application settings"""
console.print(Panel("ClearSky Setup", style="bold blue"))
# Check if .env file exists
if not os.path.exists(".env"):
with open(".env", "w") as f:
f.write("BLUESKY_USERNAME=\nBLUESKY_APP_PASSWORD=\nGEMINI_API_KEY=\n")
# Check if we already have credentials
username = settings.BLUESKY_USERNAME
password = settings.BLUESKY_APP_PASSWORD
gemini_key = settings.GEMINI_API_KEY or "AIzaSyA0dLTfkzxcZYP6KidlFClAyMLl6mea1y8"
# Only prompt if credentials are missing
if not username or not password:
username = typer.prompt("Enter Bluesky username", default=username)
password = typer.prompt("Enter Bluesky app password", hide_input=True, default=password or None)
else:
console.print("[green]Using existing credentials from .env file.[/green]")
# Update .env file only if values changed
with open(".env", "w") as f:
f.write(f"BLUESKY_USERNAME={username}\n")
f.write(f"BLUESKY_APP_PASSWORD={password}\n")
f.write(f"GEMINI_API_KEY={gemini_key}\n")
# Test Bluesky connection
console.print("Testing Bluesky connection...", end="")
bluesky_service.username = username
bluesky_service.app_password = password
if bluesky_service.login():
console.print("[green]Success![/green]")
else:
console.print("[red]Failed! Please check your credentials.[/red]")
# If login fails with existing credentials, prompt for new ones
if not (username != settings.BLUESKY_USERNAME or password != settings.BLUESKY_APP_PASSWORD):
console.print("[yellow]Would you like to enter new credentials?[/yellow]")
if typer.confirm("Enter new credentials?"):
username = typer.prompt("Enter Bluesky username")
password = typer.prompt("Enter Bluesky app password", hide_input=True)
# Update .env file with new credentials
with open(".env", "w") as f:
f.write(f"BLUESKY_USERNAME={username}\n")
f.write(f"BLUESKY_APP_PASSWORD={password}\n")
f.write(f"GEMINI_API_KEY={gemini_key}\n")
# Test new credentials
console.print("Testing Bluesky connection...", end="")
bluesky_service.username = username
bluesky_service.app_password = password
if bluesky_service.login():
console.print("[green]Success![/green]")
else:
console.print("[red]Failed! Please check your credentials.[/red]")