I can't seem to find any previous questions, tutorials, or youtube videos to help with my issue. The project is creating 500 random personas, exporting that information into a csv then filling in a fillable PDF form. Once I get it up and running I'll be able to hand it over to HR to help them filling out their forms. I'm able to create one report but for the life of me can't figure out how to make the other 499. Every time I try it overwrites the previous result.
My random persona generator:
import random
import sys
sys.stdout = open('roles.csv', 'a')
def role_generator():
firstnames = open ('first_names.txt').read().splitlines()
lastnames = open ('last_names.txt').read().splitlines()
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
for num in range(500):
first = random.choice(firstnames)
last = random.choice(lastnames)
day = random.randint(1, 29)
month = random.choice(months)
year = random.randint(1960, 2001)
idnumber = random.randint(1234567, 9999999)
print(f'1, last name, {last}\n2, first name, {first}\n3, id number, {idnumber}\n4, date of birth, {day}-{month}-{year}\n')
role_generator()
My PDF filler:
import os
os.system('pdfforms inspect screening*.pdf')
os.system('pdfforms fill roles.csv '
'screening.pdf '
'screening_1.pdf')
I'm very new to programming so please break any answers down Barney style so I can understand. I'm using Python 3.6 on an Ubuntu OS. All the coding you see is what I've pieced together so far from my research.
Thank you!
UPDATE:
At the request of Vitor Baptista, this is how the program saves the csv file:
screening.pdf
1, last name, Hendrickson
2, first name, Jane
3, id number, 8190287
4, date of birth, 6-Feb-1991
From what I gather you need to have the pdf file in the first column and first row of the csv file. Then you need to label where each entry will go in the pdf form. I did this through the inspect command above, which created a JSON file. I then looked through the JSON to see what numerical value each field had so I could label them appropriately in the csv.
roles.csvfile? Just a 5~10 lines would help.