0

Using PHP Laravel 5. Can't seem to find out how to do this specific thing. I have data in a python script. Running a python command will post successfully to my PHP method and will execute the following when i hard code api key and secret.

    $api_key = 1;
    $api_secret = 'sesame';

    //if api id and secret match, get oldest job with available timestamp before current time with status of 0

    if ($api_key == 1 and $api_secret == 'sesame') {

        $current_dt = '';
        $current_dt = date('Y.m.d H:i:s');

        $first_job_that_qualifies = \App\Job::orderBy('created_at', 'desc')
            ->where('status', 0)
            ->where('available_ts', '<', $current_dt)
            ->first();

        if ($first_job_that_qualifies != null){

            $first_job_that_qualifies->status = 1;
            $first_job_that_qualifies->save();
        }


    }


    }

Now i would like to take the hard-coded values away and check them with the data I'm passing from python.

    data = {
        'api_key': api_key,
        'api_secret': api_secret,
        }

    print data

    r = requests.post(quasar_url, data=data)
    print r.text

How would I call that dictionary "data" from python in my PHP function so I can use that in my initial if statement?

Thanks!

Michael Scarpa
  • 121
  • 2
  • 13
  • I dont understand what you are asking ... `exec("python some_prog.py some command line args");` would call a python script from php – Joran Beasley Apr 07 '15 at 17:30
  • I have 3 python scripts (configuration, server, and run). Configuration grabs data from a yml file. The data has api_secret and api_key in it: api_key: 1 api_secret: sesame The server file takes the key and secret and posts it to a url route in my laravel php project. I then want the laravel method that it passes it to to open the data it passed (api_key and api_secret) and then execute the if statement if secret and key from the passed data match what the if statement says. i see i didnt post where i hardcode the api secret and key – Michael Scarpa Apr 07 '15 at 17:32
  • sorry i pressed enter im still typing – Michael Scarpa Apr 07 '15 at 17:32
  • $api_key = 1; $api_secret = 'sesame'; – Michael Scarpa Apr 07 '15 at 17:36
  • thats what i have above all the code in my php code – Michael Scarpa Apr 07 '15 at 17:36
  • It's still not clear what you are trying to do. Spam the comments doesn't help. Also simplify your code and remove unimportant lines. – wenzul Apr 07 '15 at 17:38
  • ill try to make some edits – Michael Scarpa Apr 07 '15 at 17:42
  • possible duplicate of [Retrieving GET and POST data inside controller in Laravel 4](http://stackoverflow.com/questions/18761555/retrieving-get-and-post-data-inside-controller-in-laravel-4) – wenzul Apr 07 '15 at 18:20

1 Answers1

1

May you mean reading the $_POST parameters?

if ($api_key == $_POST['api_key'] and $api_secret == $_POST['api_secret']) {

wenzul
  • 3,948
  • 2
  • 21
  • 33