fork download
  1. #import sqlite3
  2.  
  3. # Sample college data (from provided Excel)
  4. college_data = [
  5. ("ABC Engineering", "Maharashtra", "Mumbai", "UG", 85, 120000),
  6. ("XYZ Institute", "Karnataka", "Bangalore", "PG", 75, 150000),
  7. ("Techno College", "Tamil Nadu", "Chennai", "UG", 90, 100000),
  8. ("Alpha University", "Delhi", "New Delhi", "PG", 80, 180000),
  9. ("Beta College", "Gujarat", "Ahmedabad", "UG", 70, 90000),
  10. ("Gamma Institute", "Rajasthan", "Jaipur", "UG", 88, 110000),
  11. ("Delta Tech", "Punjab", "Ludhiana", "PG", 78, 160000),
  12. ("Omega University", "Kerala", "Kochi", "UG", 92, 130000),
  13. ("Sunrise College", "UP", "Lucknow", "UG", 65, 85000),
  14. ("Future Institute", "MP", "Bhopal", "PG", 82, 140000),
  15. ]
  16.  
  17. # Sample review data
  18. review_data = [
  19. ("ABC Engineering", "Great faculty and modern labs!", 4.5),
  20. ("ABC Engineering", "Campus is vibrant but fees are high.", 3.8),
  21. ("XYZ Institute", "Excellent placement support.", 4.2),
  22. ("Techno College", "Good infrastructure, average hostel.", 3.5),
  23. ("Alpha University", "Top-notch research facilities.", 4.8),
  24. ]
  25.  
  26. def init_db():
  27. # Connect to SQLite database (creates college.db if it doesn't exist)
  28. conn = sqlite3.connect("college.db")
  29. cursor = conn.cursor()
  30.  
  31. # Create colleges table
  32. cursor.execute("""
  33. CREATE TABLE IF NOT EXISTS colleges (
  34. name TEXT NOT NULL,
  35. state TEXT NOT NULL,
  36. location TEXT NOT NULL,
  37. course_level TEXT NOT NULL,
  38. cutoff REAL NOT NULL,
  39. fees REAL NOT NULL
  40. )
  41. """)
  42.  
  43. # Create reviews table
  44. cursor.execute("""
  45. CREATE TABLE IF NOT EXISTS reviews (
  46. id INTEGER PRIMARY KEY AUTOINCREMENT,
  47. college_name TEXT NOT NULL,
  48. review_text TEXT NOT NULL,
  49. rating REAL NOT NULL,
  50. FOREIGN KEY (college_name) REFERENCES colleges(name)
  51. )
  52. """)
  53.  
  54. # Insert college data
  55. cursor.executemany("""
  56. INSERT OR REPLACE INTO colleges (name, state, location, course_level, cutoff, fees)
  57. VALUES (?, ?, ?, ?, ?, ?)
  58. """, college_data)
  59.  
  60. # Insert review data
  61. cursor.executemany("""
  62. INSERT OR REPLACE INTO reviews (college_name, review_text, rating)
  63. VALUES (?, ?, ?)
  64. """, review_data)
  65.  
  66. # Commit and close
  67. conn.commit()
  68. conn.close()
  69. print("Database initialized successfully.")
  70.  
  71. if __name__ == "__main__":
  72. init_db()
Success #stdin #stdout 0.02s 25480KB
stdin
Standard input is empty
stdout
#import sqlite3

# Sample college data (from provided Excel)
college_data = [
    ("ABC Engineering", "Maharashtra", "Mumbai", "UG", 85, 120000),
    ("XYZ Institute", "Karnataka", "Bangalore", "PG", 75, 150000),
    ("Techno College", "Tamil Nadu", "Chennai", "UG", 90, 100000),
    ("Alpha University", "Delhi", "New Delhi", "PG", 80, 180000),
    ("Beta College", "Gujarat", "Ahmedabad", "UG", 70, 90000),
    ("Gamma Institute", "Rajasthan", "Jaipur", "UG", 88, 110000),
    ("Delta Tech", "Punjab", "Ludhiana", "PG", 78, 160000),
    ("Omega University", "Kerala", "Kochi", "UG", 92, 130000),
    ("Sunrise College", "UP", "Lucknow", "UG", 65, 85000),
    ("Future Institute", "MP", "Bhopal", "PG", 82, 140000),
]

# Sample review data
review_data = [
    ("ABC Engineering", "Great faculty and modern labs!", 4.5),
    ("ABC Engineering", "Campus is vibrant but fees are high.", 3.8),
    ("XYZ Institute", "Excellent placement support.", 4.2),
    ("Techno College", "Good infrastructure, average hostel.", 3.5),
    ("Alpha University", "Top-notch research facilities.", 4.8),
]

def init_db():
    # Connect to SQLite database (creates college.db if it doesn't exist)
    conn = sqlite3.connect("college.db")
    cursor = conn.cursor()

    # Create colleges table
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS colleges (
            name TEXT NOT NULL,
            state TEXT NOT NULL,
            location TEXT NOT NULL,
            course_level TEXT NOT NULL,
            cutoff REAL NOT NULL,
            fees REAL NOT NULL
        )
    """)

    # Create reviews table
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS reviews (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            college_name TEXT NOT NULL,
            review_text TEXT NOT NULL,
            rating REAL NOT NULL,
            FOREIGN KEY (college_name) REFERENCES colleges(name)
        )
    """)

    # Insert college data
    cursor.executemany("""
        INSERT OR REPLACE INTO colleges (name, state, location, course_level, cutoff, fees)
        VALUES (?, ?, ?, ?, ?, ?)
    """, college_data)

    # Insert review data
    cursor.executemany("""
        INSERT OR REPLACE INTO reviews (college_name, review_text, rating)
        VALUES (?, ?, ?)
    """, review_data)

    # Commit and close
    conn.commit()
    conn.close()
    print("Database initialized successfully.")

if __name__ == "__main__":
    init_db()