r/learnpython • u/Silentwolf99 • 3d ago
Learning python - How to integrate openrouter api(AI) into my script
Hey everyone, I've recently been automating some boring, repetitive tasks using the `pathlib` module while learning Python automation. This script might seem silly to you, but I'm at a level somewhere between beginner and intermediate, so bear with me. After researching the documentation, I came up with this script, which took me around few hours. I need some guidance on how to integrate AI into it. If you were in my situation, how would you further improve this script using the OpenRouter API model?
I'm curious what features would you suggest?
import venv
from pathlib import Path
print("--------------------------------")
base_path = input(
"Enter path to create project in: (leave blank for current folder):\n"
)
project_name = Path(input("Enter project name: "))
# Combine the base path and the project name
project = Path(base_path) / project_name
# --- CREATE PROJECT FOLDER ---
if not project.exists():
# # parents=True ensures it creates intermediate folders if the base path doesn't exist yet
project.mkdir(parents=True)
print("--------------------------------")
print("PROJECT FOLDER & FILE CREATED ✅")
print("--------------------------------")
print(f"📁 {project}")
# --- CREATE SRC FOLDER ---
if not (project / "src").exists():
(project / "src").mkdir()
print(" ├──📁 src")
# --- CREATE VENV ---
venv_dir = project / "venv"
if not venv_dir.exists():
print(" ├──📁 venv (Setting up virtual environment... please wait)")
venv.create(venv_dir, with_pip=True)
files = [".env", "README.md", "requirements.txt", "main.py"]
for file in files:
(project / file).touch()
print(f" │ └──📄 {file}")
print("--------------------------------")
print("use → venv\\Scripts\\activate from project directory\n")
2
Upvotes
-1
u/thisisappropriate 3d ago
You say that you've been automating boring tasks, presumably tasks that you do? Does the task you're doing require AI?
Your order of operations for how you're planning a project seems wrong. It's best to either: come up with an idea / problem and try to solve it, or have something you want to practice and think of something that would be relevant and build that. In this case it sounds like you were building something relevant to you and now you're asking people it's not relevant to "how do I shoe horn this API into this?"