mayankjoin3

Studentinfo contact android 230

Apr 19th, 2026 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. import csv
  2. from datetime import datetime
  3.  
  4. # File paths
  5. student_file = "studentinfo.csv"
  6. input_file = "input.txt"
  7.  
  8. # Generate timestamp
  9. timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
  10. output_file = f"BTP_MTP_2027_output_{timestamp}.csv"
  11.  
  12. # Read studentinfo into dictionary (case-insensitive roll mapping)
  13. students = {}
  14.  
  15. with open(student_file, newline='', encoding='utf-8') as f:
  16.     reader = csv.DictReader(f)
  17.     for row in reader:
  18.         roll = row.get("Roll No", "").strip().lower()
  19.         students[roll] = {
  20.             "name": row.get("Name", "").strip(),
  21.             "roll": row.get("Roll No", "").strip(),
  22.             "email": row.get("email", "").strip(),
  23.             "aemail": row.get("aemail", "").strip(),
  24.             "contact": row.get("contact", "").strip()
  25.         }
  26.  
  27. # Read input rolls
  28. with open(input_file, 'r', encoding='utf-8') as f:
  29.     input_rolls = [line.strip() for line in f if line.strip()]
  30.  
  31. # Write output
  32. with open(output_file, 'w', newline='', encoding='utf-8') as f:
  33.     fieldnames = ["Name", "Roll No", "email", "aemail", "contact"]
  34.     writer = csv.DictWriter(f, fieldnames=fieldnames)
  35.     writer.writeheader()
  36.  
  37.     for roll in input_rolls:
  38.         key = roll.lower()
  39.  
  40.         if key in students:
  41.             s = students[key]
  42.             formatted_name = f"xIITP {s['name']} {s['roll'].upper()}"
  43.             writer.writerow({
  44.                 "Name": formatted_name.strip(),
  45.                 "Roll No": s["roll"],
  46.                 "email": s["email"],
  47.                 "aemail": s["aemail"],
  48.                 "contact": s["contact"]
  49.             })
  50.         else:
  51.             writer.writerow({
  52.                 "Name": "na",
  53.                 "Roll No": roll.strip(),
  54.                 "email": "na",
  55.                 "aemail": "na",
  56.                 "contact": "na"
  57.             })
  58.  
  59. print(f"Output file created: {output_file}")
Advertisement
Add Comment
Please, Sign In to add comment