fork download
  1. import pandas as pd
  2. import urllib.parse
  3. import webbrowser
  4. import os
  5.  
  6. def load_excel_data():
  7. """Load supplier data from the Excel file."""
  8. try:
  9. # Assuming the Excel file is in the same directory as the script
  10. excel_path = os.path.join(os.path.dirname(__file__), "RM_Suppliers_List_Preparation_Draft_w_Notes - example.xlsx")
  11. # Read the 'Main' sheet
  12. suppliers_df = pd.read_excel(excel_path, sheet_name='Main')
  13. print("Supplier data loaded successfully!")
  14. return suppliers_df
  15. except Exception as e:
  16. print(f"Failed to load Excel file: {str(e)}")
  17. exit()
  18.  
  19. def get_suppliers_for_material(suppliers_df, material_no):
  20. """Filter suppliers that produce the specified raw material."""
  21. try:
  22. # Filter suppliers that produce the requested material
  23. filtered = suppliers_df[suppliers_df['RM Nr.'] == material_no]
  24. # Group by supplier name and ID
  25. grouped = filtered.groupby(['Supp. Name', 'Supp. ID']).first().reset_index()
  26. return grouped.to_dict('records')
  27. except Exception as e:
  28. print(f"Error filtering suppliers: {str(e)}")
  29. return []
  30.  
  31. def generate_emails(suppliers, material_no, total_tons, months, delivery_day):
  32. """Generate email drafts for selected suppliers."""
  33. if not suppliers:
  34. print("No suppliers selected.")
  35. return
  36.  
  37. for supplier in suppliers:
  38. subject = f"Request for Quotation - {material_no}"
  39. body = f"""Dear {supplier['Supp. Name']},
  40.  
  41. We would like to request a quotation for the following raw material:
  42.  
  43. - Material Number: {material_no}
  44. - Total Quantity Required: {total_tons} tons (over {months} months)
  45. - Delivery Start Date: {delivery_day}
  46.  
  47. Please provide your best offer at your earliest convenience.
  48.  
  49. Best regards,
  50. [Your Name]"""
  51.  
  52. # URL encode the subject and body
  53. subject_encoded = urllib.parse.quote(subject)
  54. body_encoded = urllib.parse.quote(body)
  55. # Generate mailto link (assuming email is not in the data, using a placeholder)
  56. mailto_link = f"mailto:example@example.com?subject={subject_encoded}&body={body_encoded}"
  57. print(f"Generating email for {supplier['Supp. Name']}...")
  58. webbrowser.open(mailto_link)
  59.  
  60. def main():
  61. # Load supplier data
  62. suppliers_df = load_excel_data()
  63.  
  64. # Get user input
  65. material_no = input("Enter Raw Material Number: ").strip()
  66. monthly_tons = input("Enter Monthly Needed Tons: ").strip()
  67. months = input("Enter Number of Months: ").strip()
  68. delivery_day = input("Enter Delivery Start Day: ").strip()
  69.  
  70. # Validate inputs
  71. if not all([material_no, monthly_tons, months, delivery_day]):
  72. print("Error: Please fill all fields.")
  73. return
  74.  
  75. try:
  76. monthly_tons = float(monthly_tons)
  77. months = int(months)
  78. total_tons = monthly_tons * months
  79. except ValueError:
  80. print("Error: Invalid numeric input.")
  81. return
  82.  
  83. # Get suppliers for the specified material
  84. suppliers = get_suppliers_for_material(suppliers_df, material_no)
  85. if not suppliers:
  86. print(f"No suppliers found for material {material_no}.")
  87. return
  88.  
  89. # Display suppliers
  90. print("\nSuppliers found:")
  91. for idx, supplier in enumerate(suppliers):
  92. print(f"{idx + 1}. {supplier['Supp. Name']} (ID: {supplier['Supp. ID']})")
  93.  
  94. # Select suppliers
  95. selected_indices = input("\nEnter the numbers of the suppliers to contact (e.g., 1 3 5): ").strip().split()
  96. try:
  97. selected_indices = [int(idx) - 1 for idx in selected_indices]
  98. selected_suppliers = [suppliers[i] for i in selected_indices]
  99. except (ValueError, IndexError):
  100. print("Error: Invalid selection.")
  101. return
  102.  
  103. # Generate emails
  104. generate_emails(selected_suppliers, material_no, total_tons, months, delivery_day)
  105. print("Email generation complete.")
  106.  
  107. if __name__ == "__main__":
  108. main()
  109. sel = L.curselection()
  110. lab.config(text=str(sel))
  111.  
  112. lab.pack()
  113. F2.pack(side=Tkinter.TOP)
  114.  
  115. poll()
  116. Tkinter.mainloop()
Success #stdin #stdout 2.56s 78816KB
stdin
Standard input is empty
stdout
Failed to load Excel file: [Errno 2] No such file or directory: '/home/mtJsFm/./RM_Suppliers_List_Preparation_Draft_w_Notes - example.xlsx'