Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import pandas as pd
- from mailmerge import MailMerge
- from datetime import date
- import os
- # importing everything from tkinter
- from tkinter import *
- from tkinter import scrolledtext
- # create gui window
- Main_window = Tk()
- # set the configuration
- # of the window
- w = 400 # width for the Tk root
- h = 200 # height for the Tk root
- # get screen width and height
- ws = Main_window.winfo_screenwidth() # width of the screen
- hs = Main_window.winfo_screenheight() # height of the screen
- # calculate x and y coordinates for the Tk root window
- x = (ws/2) - (w/2)
- y = (hs/2) - (h/2)
- # set the dimensions of the screen
- # and where it is placed
- Main_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
- Main_window.resizable(0, 0)
- my_label = Label(Main_window,
- text = "geeksforgeeks")
- jd_out_path = './Finished JDs'
- template_1 = "jd_template.docx"
- label_text="...."
- textw = scrolledtext.ScrolledText(Main_window,width=47,height=12)
- textw.grid(column=1, row=2,sticky=N+S+E+W)
- Main_window.title("JD Maker 1.0 - MTO")
- # Show a simple example
- csv_path = 'jd.csv'
- def Fill_JD():
- Main_window.update_idletasks()
- try:
- # do something
- try:
- os.mkdir(jd_out_path) #create JD out directory
- except:
- print("JD directory already exists")
- df= pd.read_csv(csv_path)
- data=df.to_dict('records')
- #convert to str
- list_delim, tuple_delim = '-', '^'
- for item in data:
- res = dict()
- for sub in item:
- # checking data types
- if isinstance(item[sub], list):
- res[sub] = list_delim.join([str(ele) for ele in item[sub]])
- elif isinstance(item[sub], tuple):
- res[sub] = tuple_delim.join(list([str(ele) for ele in item[sub]]))
- else:
- res[sub] = str(item[sub])
- item = res
- # --- end convert to str ---
- document_1 = MailMerge(template_1)
- document_1.merge(**res)
- #for item in data:
- #print(item)
- #print("ITEM: ")
- #print(item['name_english'])
- label_text = "Now processing JD for: " + item['name_english']
- textw.insert(END, label_text)
- Main_window.update_idletasks()
- try:
- csv2_path = item['name_english'] + '.csv'
- df2=pd.read_csv(csv2_path)
- jd_tasks= pd.read_csv(csv2_path).to_dict('records')
- for k in jd_tasks:
- k['job_task_marks'] = str(k['job_task_marks'])
- document_1.merge_rows('job_task_marks', jd_tasks)
- # Save the document as example 1
- document_1.write(jd_out_path + "/" + item['name_english'] + '_jd.docx')
- textw.insert(END, " -->(Done)\n")
- except Exception as e:
- textw.insert(END, " -->(Error)\n")
- except Exception as e:
- # handle it
- #raise Exception("Kommis kamah nibei vege. " + str(e))
- textw.insert(END, " -->(Error)\n")
- Fill_JD()
- Main_window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement