Python Forum

Full Version: Parssing Json.dump from PYTHON to PHP for output on browser
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import warnings
warnings.filterwarnings('ignore')
import en_core_web_sm
nlp= en_core_web_sm.load()
import spacy 
#nlp = spacy.load('en_core_web_sm')
from pyresparser import ResumeParser
from resume_parser import resumeparse
import argparse
import docx
import json
import os
import sys
import base64
#import numpy as np

#def create_json():
    
                
parser=argparse.ArgumentParser()
parser.add_argument('--file1',default=None)
args=parser.parse_args()


data1 = resumeparse.read_file(args.file1)
#print(data1)
data = ResumeParser(args.file1).get_extracted_data()

person_dict={}
keys=['mobile_number','email','total_experience']

person_dict['name']=data1['name']
for i in keys:
    person_dict[i]=data[i]

#return json.dumps(person_dict)

person_json = json.dumps(person_dict)

path=args.file1
path=path.split('.')[0]
path=path+'_result'+'.json'



with open(path, "w") as outfile:
    outfile.write(person_json) 
        

'''if __name__=='__main__':
    os.getcwd()
    print(os.getcwd)
    create_json()'''




PHP Code


<?php echo " hello shiva222Test<br>" ?>
<?php

// Use ls command to shell_exec
// function
$output = exec('python3 Users/shivasharma/basictools/basictools/resume/resume.py --file1=OmkarResume.pdf' );
$result= json_decode($output);
// Display the list of all file
// and directory
echo "$result";
?>





Hi Fellow Members, For the past 4 days I am stuck on a code from which I want to dump a JSON file with the result and then parses that JSON file to a PHP dashboard. I am able to dump the JSON file but am not able to parse JSON output on the browser via PHP. I am not getting any error for the same but output is not resulting on PHP browser. Also Attached Output and the FILE1HELP HELP HELP Wall Wall Wall Wall
In Windows you most give full path no: Users/shivasharma/ yes: C:/Users/shivasharma/

Test.
# json_out.py
js = '{"foo-bar": 12345}'
print(js)
<?php 
	$command = escapeshellcmd('python G:/div_code/answer/json_out.py');  
	$output =  shell_exec($command);  
	echo $output;     
    $result = json_decode($output);
    echo $result->{"foo-bar"};    
?> 
Output:
{"foo-bar": 12345} 12345
escapeshellcmd()
escapes all characters in a string that can trick a shell command into executing arbitrary commands.

shell_exec()
that returns all of the output streams as a string.