jobs-monorepo/cv/main.go
Elshimy Ziad Magdy Taha 0ab6954231 feat: add job analysis infrastructure and Glassdoor support
- Added new job analysis result repository and database migration system
- Expanded job creation to support Glassdoor as a new provider alongside LinkedIn
- Added CV analysis service launch configuration in VS Code
- Updated Makefile with new commands for scraper service and migrations
- Improved environment loading in cron analyzer to support local development
- Added error handling for unsupported job providers
- Integrated job analysis results
2025-10-24 15:10:20 +05:00

72 lines
1.7 KiB
Go

package main
import (
"log"
"os"
"github.com/jobs-scraper/infrastructure"
"github.com/jobs-scraper/internal/domain"
"github.com/jobs-scraper/internal/repo"
"github.com/jobs-scraper/internal/services"
"github.com/joho/godotenv"
)
func main() {
// Try to load .local.env first, then fallback to .env
if err := godotenv.Load("../.local.env"); err != nil {
log.Println("No .local.env file found, trying .env")
if err := godotenv.Load("../.env"); err != nil {
log.Println("No .env file found, using system environment variables")
}
}
dbConfig := infrastructure.LoadConfigFromEnv()
db, err := infrastructure.NewConnection(dbConfig)
if err != nil {
log.Fatal("Error connecting to db")
}
apiKey := os.Getenv("OPENROUTER_API_KEY")
model := os.Getenv("CV_AI_MODEL")
err = db.Ping()
if err != nil {
log.Fatal("Error pinging db")
}
log.Println("Successfully connected to db")
jobRepo := repo.NewJobRepository(db)
jobDescriptionRepo := repo.NewJobDescriptionRepository(db)
openRouterService := services.NewOpenRouterService(model, apiKey)
cv, err := os.ReadFile("../cv.txt")
if err != nil {
log.Fatalf("Failed to get cv: %v", err)
}
job, err := jobRepo.GetJobByID(4312925061)
if err != nil {
log.Fatalf("Failed to get job: %v", err)
}
jobDescription, jobCriteria, err := jobDescriptionRepo.GetJobDescriptionByJobID(job.ID)
if err != nil {
log.Fatalf("Failed to get job description: %v", err)
}
result, err := openRouterService.AnalyzeJobDescription(string(cv), domain.JobDescription{
JobID: job.ID,
Description: jobDescription,
Criteria: jobCriteria,
})
if err != nil {
log.Fatalf("Failed to get job analysis result: %v", err)
}
log.Println(result)
}