# STEP 3: get available forms (i9, etc.) forms = parser.available_forms() print(forms) # STEP 4: get form details (i.e. array of fields/questions object) details = parser.form_details('i9') print(details) # STEP 5: fill form with form_name and answers dict, returns bytes dummy_answers = { 'ssn': '123456789', 'first_name': 'lil\'', 'last_name': 'pea', 'middle_initial': '', 'address': '21 Pea Rd', 'apt_number': '1c', 'city': 'New York', 'state': 'NY', 'date_of_birth': '02/02/2019', 'employee_email': '*****@*****.**', 'employee_telephone': '1-800-PEA', 'cb_citizen': 'yes', 'today_date': '02/03/2019' } filled_form = parser.fill_form('i9', dummy_answers) # for debugging from pdf_utils import save save(filled_form, 'filled_test.pdf')
# STEP 3: get available forms (i9, etc.) forms = parser.available_forms() print(forms) # STEP 4: get form details (i.e. array of fields/questions object) details = parser.form_details('dmv44') print(details) # STEP 5: fill form with form_name and answers dict, returns bytes dummy_answers = { 'ssn': '123456789', 'first_name': 'lil\'', 'last_name': 'pea', 'middle_name': '', 'address': '21 Pea Rd', 'apt_number': '1c', 'city': 'New York', 'state': 'NY', 'date_of_birth': '02022019', 'telephone_number': '917-PEA-PEA', 'applying_for': 1, 'purpose': 4, 'organ': 1 } filled_form = parser.fill_form('dmv44', dummy_answers) # for debugging from pdf_utils import save save(filled_form, 'filled_test.pdf')
def start_questions(recipient_id, payload, txt=None): global user_data if not payload: payload = user_data[recipient_id]["current_form"] if recipient_id in user_data and 'done' in user_data[ recipient_id] and user_data[recipient_id]['done'] == True: if txt.isdigit(): account_sid = 'AC67c8a0b6b16986da80dc1ac0fdb26808' auth_token = '1db9a6a11f38faafa562d1e72607ba39' client = Client(account_sid, auth_token) message = client.messages \ .create( body=user_data[recipient_id]["public_url"], from_='+12153911286', to='+1'+txt ) else: print("form is already filled. please reset") return "" payload_correct = ''.join( [i.lower() for i in payload if i.isalpha() or i.isdigit()]) print(payload) print(payload_correct) parser = PDFParser() details = parser.form_details(payload_correct) print(details) txt_trans = "" if txt is not None: translate_client = translate.Client() txt_trans = translate_client.translate(txt, target_language='en') txt_trans = txt_trans['translatedText'] if recipient_id in user_data and 'in_progress' in user_data[recipient_id]: print("in progress") current_key = details[len(user_data[recipient_id]["answers"])]['id'] user_data[recipient_id]["answers"][current_key] = txt_trans if len(user_data[recipient_id]["answers"]) == len(details): print("done!") user_data[recipient_id]['done'] = True filled_form = parser.fill_form( user_data[recipient_id]["current_form"], user_data[recipient_id]["answers"]) import time timestamp = int(time.time()) save(filled_form, 'files/filled_test-{}.pdf'.format(timestamp)) user_info = bot.get_user_info(recipient_id) fname = user_info["first_name"] lname = user_info["last_name"] pdf_form = user_data[recipient_id]["current_form"] translate_client = translate.Client() target_lang = user_data[recipient_id]['lang'] translated_text = translate_client.translate( "You are done! Here is your file", target_language=target_lang) translated_text = translated_text['translatedText'] translated_text = translated_text bot.send_text_message(recipient_id, translated_text) storage_client = storage.Client() bucket_name = 'ezpz-files-public' bucket = storage_client.get_bucket(bucket_name) source_file_name = "/Users/tomeraharoni/Documents/Projects/devfest/files/filled_test-{}.pdf".format( timestamp) destination_blob_name = "{}-{}-{}-{}-filled.pdf".format( pdf_form, fname, lname, timestamp) blob = bucket.blob(destination_blob_name) blob.upload_from_filename(source_file_name) blob.make_public() bot.send_text_message(recipient_id, blob.public_url) user_data[recipient_id]['public_url'] = blob.public_url target_lang = user_data[recipient_id]['lang'] translated_text = translate_client.translate( "If you want the file sent to your phone, please type in your number", target_language=target_lang) translated_text = translated_text['translatedText'] bot.send_text_message(recipient_id, translated_text) return question_object = details[len(user_data[recipient_id]["answers"])] question_type = question_object["type"] question_text = question_object["question"] added_string = "" if question_type == "bool": added_string = "(Yes / No)" text_to_send = "{} {}".format(question_text, added_string) translate_client = translate.Client() target_lang = user_data[recipient_id]['lang'] if target_lang == 'en': translated_text = text_to_send else: translated_text = translate_client.translate( text_to_send, target_language=target_lang) translated_text = translated_text['translatedText'] bot.send_text_message(recipient_id, translated_text) else: print("first question!") user_data[recipient_id]["in_progress"] = True user_data[recipient_id]["answers"] = {} user_data[recipient_id]["current_form"] = payload_correct translate_client = translate.Client() target_lang = user_data[recipient_id]['lang'] filling_intro_text = 'Sure! I can help you with your {} form'.format( payload) filling_intro_text_tra = translate_client.translate( filling_intro_text, target_language=target_lang) filling_intro_text_tra = filling_intro_text_tra['translatedText'] bot.send_text_message(recipient_id, filling_intro_text_tra) question_object = details[0] question_type = question_object["type"] question_text = question_object["question"] added_string = "" if question_type == "bool": added_string = "(Yes / No)" elif question_type == "option": q_options = question_object["options"] added_string = "\n" for i in range(len(q_options)): added_string = added_string + \ "\n{}) {}".format(i, q_options[i]) text_to_send = "{} {}".format(question_text, added_string) if target_lang == 'en': translated_text = text_to_send else: translated_text = translate_client.translate( text_to_send, target_language=target_lang) translated_text = translated_text['translatedText'] bot.send_text_message(recipient_id, translated_text)