Spaces:
Build error
Build error
Commit
·
02ccde5
1
Parent(s):
89eb9d6
basic agent
Browse files- app.py +28 -5
- data/class_schedule.json +39 -0
- data/credentials.json +1 -0
- data/gecici.py +26 -0
- requirements.txt +7 -4
- token.json +1 -0
- utils/__pycache__/calendar_reader.cpython-310.pyc +0 -0
- utils/__pycache__/gmail_sender.cpython-310.pyc +0 -0
- utils/__pycache__/planner.cpython-310.pyc +0 -0
- utils/calendar_reader.py +41 -0
- utils/gmail_sender.py +24 -0
- utils/planner.py +32 -0
- utils/tools.py +8 -0
app.py
CHANGED
|
@@ -1,7 +1,30 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
from utils.planner import generate_daily_plan
|
| 3 |
+
from utils.gmail_sender import send_email
|
| 4 |
|
| 5 |
+
if __name__ == "__main__":
|
| 6 |
+
daily_plan = generate_daily_plan()
|
| 7 |
+
send_email("📅 Günlük Planın Hazır!", daily_plan, "onculeresra76@gmail.com")
|
| 8 |
+
"""
|
| 9 |
+
# app.py
|
| 10 |
+
from smol_developer import SmolAgent, Tool
|
| 11 |
+
from tools import generate_day_plan_tool
|
| 12 |
|
| 13 |
+
tools = [
|
| 14 |
+
Tool(
|
| 15 |
+
name="generate_day_plan_tool",
|
| 16 |
+
func=generate_day_plan_tool,
|
| 17 |
+
description="Kullanıcının günlük takvimine ve derslerine göre bir gün planı hazırlar"
|
| 18 |
+
)
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
agent = SmolAgent(tools=tools)
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
print("Agent hazır. Lütfen bir istem girin.")
|
| 25 |
+
while True:
|
| 26 |
+
user_input = input("👤: ")
|
| 27 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 28 |
+
break
|
| 29 |
+
response = agent.run(user_input)
|
| 30 |
+
print(f"\n🤖: {response}\n")
|
data/class_schedule.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"monday": [
|
| 3 |
+
"09:00-09:40 | PYTHON PROGRAMMING FOR ARTIFICIAL INTELLIGENCE | A BLOK MF203 | Doç. Dr. FARUK SERİN",
|
| 4 |
+
"09:50-10:30 | PYTHON PROGRAMMING FOR ARTIFICIAL INTELLIGENCE | A BLOK MF203 | Doç. Dr. FARUK SERİN",
|
| 5 |
+
"10:40-11:20 | PYTHON PROGRAMMING FOR ARTIFICIAL INTELLIGENCE | A BLOK MF203 | Doç. Dr. FARUK SERİN",
|
| 6 |
+
"11:30-12:10 | PYTHON PROGRAMMING FOR ARTIFICIAL INTELLIGENCE | A BLOK MF203 | Doç. Dr. FARUK SERİN"
|
| 7 |
+
],
|
| 8 |
+
"tuesday": [
|
| 9 |
+
"08:10-08:50 | COMPUTER ARCHITECTURE | EL-K2-4 | Dr. Öğretim Üyesi VOLKAN YAMAÇLI",
|
| 10 |
+
"09:00-09:40 | COMPUTER ARCHITECTURE | EL-K2-4 | Dr. Öğretim Üyesi VOLKAN YAMAÇLI",
|
| 11 |
+
"09:50-10:30 | COMPUTER ARCHITECTURE | EL-K2-4 | Dr. Öğretim Üyesi VOLKAN YAMAÇLI",
|
| 12 |
+
"13:00-13:40 | BİÇİMSEL DİLLER VE SOYUT MAKİNELER | A BLOK MF304 | Doç. Dr. ÇİĞDEM ACI",
|
| 13 |
+
"13:50-14:30 | BİÇİMSEL DİLLER VE SOYUT MAKİNELER | A BLOK MF304 | Doç. Dr. ÇİĞDEM ACI",
|
| 14 |
+
"14:40-15:20 | BİÇİMSEL DİLLER VE SOYUT MAKİNELER | A BLOK MF304 | Doç. Dr. ÇİĞDEM ACI"
|
| 15 |
+
],
|
| 16 |
+
"wednesday": [
|
| 17 |
+
"08:10-08:50 | MICROPROCESSORS | A BLOK MF304 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 18 |
+
"09:00-09:40 | MICROPROCESSORS | A BLOK MF304 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 19 |
+
"09:50-10:30 | MICROPROCESSORS | A BLOK MF304 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 20 |
+
"10:40-11:20 | İŞ SAĞLIĞI VE GÜVENLİĞİ II | A BLOK MF304 | Gösterilmiyor",
|
| 21 |
+
"11:30-12:10 | İŞ SAĞLIĞI VE GÜVENLİĞİ II | A BLOK MF304 | Gösterilmiyor",
|
| 22 |
+
"13:00-13:40 | MICROPROCESSORS | EL-K2-4 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 23 |
+
"13:50-14:30 | MICROPROCESSORS | EL-K2-4 | Arş. Gör. Dr. ALİ CÜVİTOĞLU"
|
| 24 |
+
],
|
| 25 |
+
"thursday": [
|
| 26 |
+
"08:10-08:50 | BİTİRME ÖDEVİ II | K1-4 C.ACI | Doç. Dr. ÇİĞDEM ACI",
|
| 27 |
+
"10:40-11:20 | COMPUTER ARCHITECTURE | A BLOK MF304 | Dr. Öğretim Üyesi VOLKAN YAMAÇLI",
|
| 28 |
+
"11:30-12:10 | COMPUTER ARCHITECTURE | A BLOK MF304 | Dr. Öğretim Üyesi VOLKAN YAMAÇLI",
|
| 29 |
+
"16:20-17:00 | BİTİRME ÖDEVİ II | K1-4 C.ACI | Doç. Dr. ÇİĞDEM ACI"
|
| 30 |
+
],
|
| 31 |
+
"friday": [
|
| 32 |
+
"09:00-09:40 | DATA MINING | A BLOK MF203 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 33 |
+
"09:50-10:30 | DATA MINING | A BLOK MF203 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 34 |
+
"10:40-11:20 | DATA MINING | A BLOK MF203 | Arş. Gör. Dr. ALİ CÜVİTOĞLU",
|
| 35 |
+
"11:30-12:10 | DATA MINING | A BLOK MF203 | Arş. Gör. Dr. ALİ CÜVİTOĞLU"
|
| 36 |
+
],
|
| 37 |
+
"saturday": [],
|
| 38 |
+
"sunday": []
|
| 39 |
+
}
|
data/credentials.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"installed":{"client_id":"604824766950-h21v561mq16ek0ha94ic7jon21mn67ic.apps.googleusercontent.com","project_id":"daily-plan-agent","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"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","redirect_uris":["http://localhost"]}}
|
data/gecici.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
BU DOSYA TAKVİMİ OKUMAK İÇİN Yetkilendirme izni verir ve token.json dosyasını olşturur. Bir defa çalıştırmak yeterlidir.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from google.oauth2.credentials import Credentials
|
| 6 |
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
| 7 |
+
from googleapiclient.discovery import build
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
credentials_path = os.path.join("data", "credentials.json")
|
| 11 |
+
|
| 12 |
+
# Sadece takvimi okuma izni veriyoruz
|
| 13 |
+
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
flow = InstalledAppFlow.from_client_secrets_file(credentials_path, SCOPES)
|
| 17 |
+
|
| 18 |
+
creds = flow.run_local_server(port=0)
|
| 19 |
+
|
| 20 |
+
with open('token.json', 'w') as token:
|
| 21 |
+
token.write(creds.to_json())
|
| 22 |
+
|
| 23 |
+
print("Yetkilendirme başarılı, token.json oluşturuldu.")
|
| 24 |
+
|
| 25 |
+
if __name__ == '__main__':
|
| 26 |
+
main()
|
requirements.txt
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
smolagents
|
| 2 |
-
|
| 3 |
-
pytz
|
| 4 |
google-api-python-client
|
| 5 |
-
google-auth
|
| 6 |
google-auth-oauthlib
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
smolagents
|
| 2 |
+
openai
|
|
|
|
| 3 |
google-api-python-client
|
| 4 |
+
google-auth-httplib2
|
| 5 |
google-auth-oauthlib
|
| 6 |
+
pytz
|
| 7 |
+
python-dotenv
|
| 8 |
+
smol-developer
|
| 9 |
+
google-auth
|
| 10 |
+
|
token.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"token": "ya29.a0AZYkNZgwa6llRWqFaYYkMU3GIQpyYfnYbGPV6dduSZlc9z5YfF3ZLzB0Ad6dOULx0C49-ygfuncdGg574ZK9QYUEfPHonZoHr7ASY-flAaCcO1nk08sRF_zIr6Lbrr67VRdQ588oGLU2bC93ckGXB5XAQ-9cUONan72hoyOAaCgYKAdISARESFQHGX2Mi3po9y6w5fT2iVBxrlvNsjg0175", "refresh_token": "1//03UmRXrJcBBG_CgYIARAAGAMSNwF-L9IrFPorqxuyHu67HVI-wNvWnSPBCtU-DWsVNyFFJ95tRCa3rcjb3kUTB4brv-md-hYmpx8", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "604824766950-h21v561mq16ek0ha94ic7jon21mn67ic.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "universe_domain": "googleapis.com", "account": "", "expiry": "2025-05-03T13:54:42.681896Z"}
|
utils/__pycache__/calendar_reader.cpython-310.pyc
ADDED
|
Binary file (1.44 kB). View file
|
|
|
utils/__pycache__/gmail_sender.cpython-310.pyc
ADDED
|
Binary file (901 Bytes). View file
|
|
|
utils/__pycache__/planner.cpython-310.pyc
ADDED
|
Binary file (926 Bytes). View file
|
|
|
utils/calendar_reader.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from google.oauth2.credentials import Credentials
|
| 2 |
+
from googleapiclient.discovery import build
|
| 3 |
+
import datetime
|
| 4 |
+
import pytz
|
| 5 |
+
|
| 6 |
+
def get_todays_events():
|
| 7 |
+
creds = Credentials.from_authorized_user_file('token.json', ['https://www.googleapis.com/auth/calendar.readonly'])
|
| 8 |
+
service = build('calendar', 'v3', credentials=creds)
|
| 9 |
+
|
| 10 |
+
now = datetime.datetime.now(pytz.timezone("Europe/Istanbul"))
|
| 11 |
+
start_of_day = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
| 12 |
+
end_of_day = now.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 13 |
+
|
| 14 |
+
events_result = service.events().list(
|
| 15 |
+
calendarId='primary',
|
| 16 |
+
timeMin=start_of_day.isoformat(),
|
| 17 |
+
timeMax=end_of_day.isoformat(),
|
| 18 |
+
singleEvents=True,
|
| 19 |
+
orderBy='startTime'
|
| 20 |
+
).execute()
|
| 21 |
+
|
| 22 |
+
events = events_result.get('items', [])
|
| 23 |
+
unique = set()
|
| 24 |
+
formatted_events = []
|
| 25 |
+
|
| 26 |
+
for event in events:
|
| 27 |
+
summary = event.get('summary', 'İsimsiz Etkinlik')
|
| 28 |
+
start = event['start'].get('dateTime')
|
| 29 |
+
end = event['end'].get('dateTime')
|
| 30 |
+
if not start or not end:
|
| 31 |
+
continue # tüm günlük veya eksik bilgiler varsa geç
|
| 32 |
+
if (summary, start) in unique:
|
| 33 |
+
continue # yinelenenleri atla
|
| 34 |
+
unique.add((summary, start))
|
| 35 |
+
|
| 36 |
+
start_dt = datetime.datetime.fromisoformat(start)
|
| 37 |
+
end_dt = datetime.datetime.fromisoformat(end)
|
| 38 |
+
formatted = f"{summary}. ({start_dt.strftime('%H : %M')} - {end_dt.strftime('%H : %M')} / {start_dt.strftime('%d - %m - %Y')})"
|
| 39 |
+
formatted_events.append(formatted)
|
| 40 |
+
|
| 41 |
+
return formatted_events
|
utils/gmail_sender.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import smtplib
|
| 2 |
+
from email.mime.text import MIMEText
|
| 3 |
+
from email.mime.multipart import MIMEMultipart
|
| 4 |
+
|
| 5 |
+
def send_email(subject, body, to_email):
|
| 6 |
+
from_email = "alcmdrn7@gmail.com"
|
| 7 |
+
password = "mgse lffk thsu hbxs"
|
| 8 |
+
|
| 9 |
+
msg = MIMEMultipart()
|
| 10 |
+
msg["From"] = from_email
|
| 11 |
+
msg["To"] = to_email
|
| 12 |
+
msg["Subject"] = subject
|
| 13 |
+
|
| 14 |
+
msg.attach(MIMEText(body, "plain"))
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
server = smtplib.SMTP("smtp.gmail.com", 587)
|
| 18 |
+
server.starttls()
|
| 19 |
+
server.login(from_email, password)
|
| 20 |
+
server.send_message(msg)
|
| 21 |
+
server.quit()
|
| 22 |
+
print("✅ Plan başarıyla gönderildi.")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"❌ Mail gönderilemedi: {e}")
|
utils/planner.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.calendar_reader import get_todays_events
|
| 2 |
+
import json
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
def generate_daily_plan():
|
| 6 |
+
# 1. Ders programını oku
|
| 7 |
+
with open("data/class_schedule.json", "r", encoding="utf-8") as f:
|
| 8 |
+
class_schedule = json.load(f)
|
| 9 |
+
|
| 10 |
+
# 2. Bugünün haftalık ders gününü bul
|
| 11 |
+
weekday = datetime.datetime.now().strftime("%A").lower()
|
| 12 |
+
today_classes = class_schedule.get(weekday, [])
|
| 13 |
+
|
| 14 |
+
# 3. Takvimden etkinlikleri al
|
| 15 |
+
calendar_events = get_todays_events()
|
| 16 |
+
|
| 17 |
+
# 4. Birleştirip planı oluştur
|
| 18 |
+
plan_lines = ["📚 Ders Programı:"]
|
| 19 |
+
if today_classes:
|
| 20 |
+
for cls in today_classes:
|
| 21 |
+
plan_lines.append(f"- {cls}")
|
| 22 |
+
else:
|
| 23 |
+
plan_lines.append("Bugün ders yok.")
|
| 24 |
+
|
| 25 |
+
plan_lines.append("\n🗓️ Takvim Etkinlikleri:")
|
| 26 |
+
if calendar_events:
|
| 27 |
+
for event in calendar_events:
|
| 28 |
+
plan_lines.append(f"- {event}")
|
| 29 |
+
else:
|
| 30 |
+
plan_lines.append("Bugün etkinlik yok.")
|
| 31 |
+
|
| 32 |
+
return "\n".join(plan_lines)
|
utils/tools.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tools.py
|
| 2 |
+
from utils.planner import generate_daily_plan
|
| 3 |
+
|
| 4 |
+
def generate_day_plan_tool(input: str) -> str:
|
| 5 |
+
"""
|
| 6 |
+
Kullanıcının gününü planlar ve sade bir metin döner.
|
| 7 |
+
"""
|
| 8 |
+
return generate_daily_plan()
|