Python Forum
Parssing Json.dump from PYTHON to PHP for output on browser
Thread Rating:
  • 3 Vote(s) - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parssing Json.dump from PYTHON to PHP for output on browser
#1
Information 
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
likes this post

Attached Files

.json   OmkarResume_result.json (Size: 117 bytes / Downloads: 1)
.pdf   OmkarResume.pdf (Size: 52.19 KB / Downloads: 1)
Reply
#2
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.
likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parse json output to simple text or variable murali_datascience 1 2,412 Jun-25-2019, 02:56 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020