Advertisement
MohamedShamil

Untitled

Nov 19th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. from __future__ import print_function
  2. import pandas as pd
  3. from mailmerge import MailMerge
  4. from datetime import date
  5. import os
  6. # importing everything from tkinter
  7. from tkinter import *
  8. from tkinter import scrolledtext
  9.  
  10. # create gui window
  11. Main_window = Tk()
  12.  
  13. # set the configuration
  14. # of the window
  15. w = 400 # width for the Tk root
  16. h = 200 # height for the Tk root
  17.  
  18. # get screen width and height
  19. ws = Main_window.winfo_screenwidth() # width of the screen
  20. hs = Main_window.winfo_screenheight() # height of the screen
  21.  
  22. # calculate x and y coordinates for the Tk root window
  23. x = (ws/2) - (w/2)
  24. y = (hs/2) - (h/2)
  25.  
  26. # set the dimensions of the screen
  27. # and where it is placed
  28. Main_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
  29. Main_window.resizable(0, 0)
  30. my_label = Label(Main_window,
  31.                  text = "geeksforgeeks")
  32.  
  33. jd_out_path = './Finished JDs'
  34. template_1 = "jd_template.docx"
  35. label_text="...."
  36.  
  37. textw = scrolledtext.ScrolledText(Main_window,width=47,height=12)
  38. textw.grid(column=1, row=2,sticky=N+S+E+W)
  39.  
  40.    
  41.  
  42. Main_window.title("JD Maker 1.0 - MTO")
  43.  
  44. # Show a simple example
  45. csv_path = 'jd.csv'
  46. def Fill_JD():
  47.     Main_window.update_idletasks()
  48.     try:
  49.         # do something
  50.         try:
  51.             os.mkdir(jd_out_path) #create JD out directory
  52.         except:
  53.             print("JD directory already exists")
  54.         df= pd.read_csv(csv_path)
  55.         data=df.to_dict('records')
  56.        
  57.         #convert to str
  58.        
  59.         list_delim, tuple_delim = '-', '^'
  60.         for item in data:
  61.             res = dict()
  62.             for sub in item:
  63.                 # checking data types
  64.                 if isinstance(item[sub], list):
  65.                     res[sub] = list_delim.join([str(ele) for ele in item[sub]])
  66.                 elif isinstance(item[sub], tuple):
  67.                     res[sub] = tuple_delim.join(list([str(ele) for ele in item[sub]]))
  68.                 else:
  69.                     res[sub] = str(item[sub])
  70.             item = res
  71.             # --- end convert to str ---
  72.             document_1 = MailMerge(template_1)
  73.             document_1.merge(**res)
  74.        
  75.         #for item in data:
  76.             #print(item)  
  77.             #print("ITEM: ")
  78.             #print(item['name_english'])
  79.             label_text = "Now processing JD for: " + item['name_english']
  80.             textw.insert(END, label_text)
  81.             Main_window.update_idletasks()
  82.            
  83.             try:
  84.                 csv2_path =  item['name_english'] + '.csv'
  85.                 df2=pd.read_csv(csv2_path)
  86.                
  87.                 jd_tasks= pd.read_csv(csv2_path).to_dict('records')
  88.  
  89.                 for k in jd_tasks:
  90.                     k['job_task_marks'] = str(k['job_task_marks'])
  91.  
  92.                 document_1.merge_rows('job_task_marks', jd_tasks)
  93.                 # Save the document as example 1
  94.                 document_1.write(jd_out_path + "/" +  item['name_english'] + '_jd.docx')
  95.                 textw.insert(END, " -->(Done)\n")
  96.             except Exception as e:
  97.                 textw.insert(END, " -->(Error)\n")
  98.     except Exception as e:
  99.         # handle it
  100.         #raise Exception("Kommis kamah nibei vege. " + str(e))
  101.         textw.insert(END, " -->(Error)\n")
  102.  
  103. Fill_JD()
  104. Main_window.mainloop()
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement