File size: 2,076 Bytes
98693a0
 
 
 
252ed9e
98693a0
 
 
62551c5
 
252ed9e
 
 
62551c5
252ed9e
98693a0
 
 
22c2c4e
98693a0
 
 
 
 
252ed9e
 
 
98693a0
 
252ed9e
98693a0
 
 
252ed9e
 
 
 
 
 
 
 
 
98693a0
 
 
 
 
 
 
 
5a67092
252ed9e
5a67092
 
 
252ed9e
2f7882b
 
 
 
 
5b1c185
 
 
 
 
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
from fastapi import FastAPI
from google.oauth2 import service_account
from googleapiclient.discovery import build
import json
import os

app = FastAPI()

# Load credentials from Hugging Face Secrets
google_credentials = json.loads(os.getenv("GOOGLE_CREDENTIALS"))
creds = service_account.Credentials.from_service_account_info(
    google_credentials, scopes=["https://www.googleapis.com/auth/calendar.readonly"]
)

# Initialize Google Calendar API
service = build("calendar", "v3", credentials=creds)

# User preferences
user_interests = ["AI", "startup", "funding"]
preferred_locations = ["bangalore", "mumbai", "delhi", "pune", "chennai"]
event_types = ["webinar", "workshop", "accelerator", "summit"]

# Function to fetch events from Google Calendar
def get_events():
    events_result = service.events().list(
        calendarId="primary", maxResults=10, singleEvents=True, orderBy="startTime"
    ).execute()
    return events_result.get("items", [])

# Function to filter and format events
def filter_events(events):
    recommended = []
    for event in events:
        title = event.get("summary", "").lower()
        location = event.get("location", "No location specified")
        date = event["start"].get("dateTime", event["start"].get("date"))

        if any(keyword in title for keyword in user_interests + event_types) and any(
            city in location.lower() for city in preferred_locations
        ):
            recommended.append({"title": event["summary"], "date": date, "location": location})

    return recommended

@app.get("/")
def home():
    return {"message": "Welcome to the Startup Event Recommender API!"}

@app.get("/recommend_events")
def recommend_events():
    return {"message": "API is working!"}  # Just a test response for now

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)


@app.get("/routes")
def list_routes():
    return {"available_routes": [route.path for route in app.routes]}
    

import uvicorn

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)