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
- #get all csv files in the current directory
- #import os
- #path = os.getcwd()
- #extension = '.csv'
- #for root, dirs_list, files_list in os.walk(path):
- # for file_name in files_list:
- # if os.path.splitext(file_name)[-1] == extension:
- # file_name_path = os.path.join(root, file_name)
- # print(file_name)
- # print(file_name_path) # This is the full path of the filter file
- # this is the extension you want to detect
- #extension = '.csv'
- # Define the templates - assumes they are in the same directory as the code
- template_1 = "jd_template.docx"
- # Show a simple example
- csv_path = 'jd.csv'
- try:
- # do something
- df=pd.read_csv(csv_path)
- for idx,row in df.iterrows():
- global data
- data={
- '[name_english]': row['name_english'],
- '[name]': row['name'],
- '[present_address]': row['present_address'],
- '[phone]': row['phone'],
- '[id_card_no]': row['id_card_no'],
- '[date_of_birth]': row['date_of_birth'],
- '[permenant_address]': row['permenant_address'],
- '[emergency_contact_name]': row['emergency_contact_name'],
- '[emergency_contact_phone]': row['emergency_contact_phone'],
- '[job_no]': row['job_no'],
- '[job_name_and_rank]': row['job_name_and_rank'],
- '[job_purpose]': row['job_purpose'],
- '[unit]': row['unit'],
- '[jd_date]': row['jd_date'],
- '[basic_salary]': row['basic_salary'],
- '[service_allowance]': row['service_allowance'],
- '[supporting_co_allowance]': row['supporting_co_allowance'],
- '[name_2]': row['name_2'],
- '[job_title]': row['job_title'],
- '[sign_date]': row['sign_date']
- }
- print("Data Row is:" + data['[name]'])
- document_1 = MailMerge(template_1)
- print("Fields included in {}: {}".format(template_1,
- document_1.get_merge_fields()))
- # Merge in the values
- document_1.merge(
- name=data['[name]'],
- present_address=data['[present_address]'],
- phone=str(data['[phone]']),
- id_card_no=data['[id_card_no]'],
- date_of_birth=data['[date_of_birth]'],
- permenant_address=data['[permenant_address]'],
- emergency_contact_name=data['[emergency_contact_name]'],
- emergency_contact_phone=str(data['[emergency_contact_phone]']),
- job_no=str(data['[job_no]']),
- job_name_and_rank=data['[job_name_and_rank]'],
- job_purpose=data['[job_purpose]'],
- unit=data['[unit]'],
- jd_date=data['[jd_date]'],
- basic_salary=str(data['[basic_salary]']),
- service_allowance=str(data['[service_allowance]']),
- supporting_co_allowance=str(data['[supporting_co_allowance]']),
- name_2=data['[name_2]'],
- job_title=data['[job_title]'],
- sign_date=data['[sign_date]'],
- )
- csv2_path = data['[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(data['[name_english]'] + '_jd.docx')
- except Exception as e:
- # handle it
- raise Exception("Kommis kamah nibei vege. " + str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement