# main.py import datetime import streamlit as st from google.oauth2.credentials import Credentials from googleapiclient.discovery import build from typing import List, Dict import json import os from pathlib import Path # Configuration SCOPES = ['https://www.googleapis.com/auth/calendar'] TIMEZONE = 'Asia/Kolkata' STUDY_HOURS = 10 # Adjust based on your capacity TOPICS_FILE = 'syllabus.json' TEST_QUESTIONS_FILE = 'test_bank.json' # Dummy data - Replace with your actual syllabus and questions if not Path(TOPICS_FILE).exists(): with open(TOPICS_FILE, 'w') as f: json.dump({ "Physics": ["Vectors", "Kinematics", "Laws of Motion"], "Chemistry": ["Atomic Structure", "Chemical Bonding", "States of Matter"], "Maths": ["Algebra", "Trigonometry", "Calculus"] }, f) if not Path(TEST_QUESTIONS_FILE).exists(): with open(TEST_QUESTIONS_FILE, 'w') as f: json.dump({ "Vectors": [ {"question": "What is a vector?", "options": ["Magnitude only", "Direction only", "Both"], "answer": 2} ] }, f) def get_calendar_service(): """Authenticate with Google Calendar""" creds = None if os.path.exists('token.json'): creds = Credentials.from_authorized_user_file('token.json', SCOPES) return build('calendar', 'v3', credentials=creds) def generate_schedule(start_date: datetime.date, end_date: datetime.date) -> Dict: """Generate initial study schedule""" schedule = {} current_date = start_date with open(TOPICS_FILE) as f: topics = json.load(f) while current_date <= end_date: daily_schedule = [] for subject, chapters in topics.items(): if chapters: daily_schedule.append({ "subject": subject, "topic": chapters.pop(0), "duration": 2 # hours per topic }) schedule[current_date.isoformat()] = daily_schedule current_date += datetime.timedelta(days=1) return schedule def update_calendar(schedule: Dict): """Sync schedule with Google Calendar""" service = get_calendar_service() for date, topics in schedule.items(): start_time = datetime.datetime.fromisoformat(date) + datetime.timedelta(hours=9) for topic in topics: end_time = start_time + datetime.timedelta(hours=topic['duration']) event = { 'summary': f"{topic['subject']}: {topic['topic']}", 'start': {'dateTime': start_time.isoformat(), 'timeZone': TIMEZONE}, 'end': {'dateTime': end_time.isoformat(), 'timeZone': TIMEZONE}, 'reminders': {'useDefault': True} } service.events().insert( calendarId='primary', body=event ).execute() start_time = end_time def daily_review(): """Daily progress assessment""" st.subheader("Daily Review") performance = st.slider("Rate today's productivity (1-5)", 1, 5) completed = st.multiselect("Select completed topics", options=st.session_state.today_topics) return { "performance": performance, "completed": completed } def main(): st.title("EAMCET Study Planner") if 'schedule' not in st.session_state: st.session_state.schedule = generate_schedule( start_date=datetime.date(2024, 4, 1), end_date=datetime.date(2024, 5, 1) ) # Calendar Sync Section st.header("Calendar Sync") if st.button("Sync with Google Calendar"): update_calendar(st.session_state.schedule) st.success("Schedule synced with Google Calendar!") # Daily Planner Section today = datetime.date.today().isoformat() st.header(f"Today's Schedule - {today}") if today in st.session_state.schedule: st.session_state.today_topics = [f"{t['subject']} - {t['topic']}" for t in st.session_state.schedule[today]] for topic in st.session_state.schedule[today]: st.markdown(f"**{topic['subject']}** ({topic['duration']}hrs): {topic['topic']}") else: st.info("No scheduled topics for today") # Daily Test Section st.header("Daily Test") with open(TEST_QUESTIONS_FILE) as f: test_bank = json.load(f) selected_topic = st.selectbox("Select topic for test", options=list(test_bank.keys())) for question in test_bank[selected_topic]: st.write(question['question']) answer = st.radio("Options", options=question['options'], index=None) if answer == question['options'][question['answer']]: st.success("Correct!") # Daily Review Section if st.button("End Day"): review = daily_review() # Adjust schedule based on review st.session_state.schedule = adjust_schedule(review) st.experimental_rerun() if __name__ == "__main__": main()