Can someone help me translate php to python [closed]

  php, python-3.x

Can someone help me translate PHP code because idk any HTML JAVA AND PHP.I just know Python.
It an api and I want to get order status.What is $this.
I want to use it in python so it easier for my customer to check order status via chat in shopee.
I already got my shopee API access
And Over flow dont give me permission to post this beacause mostly code so ignore this

<?php
class Api {
    // API URL
    public $api_url = 'http://todak.my/api/v1'; 

    // Your API key
    public $api_key = ''; 

    /**
     *
     * Add Order
     *
     */
    public function add_order($data) { 
        $post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
        $result = $this->connect($post);
        return json_decode($result);
    }

    /**
     *
     * Order status
     *
     */
    public function status($order_id) { 
        $result = $this->connect(array(
            'key'    => $this->api_key,
            'action' => 'status',
            'order'  => $order_id
        ));
        return json_decode($result);
    }

    /**
     *
     * Order multi status
     *
     */

    public function multi_status($order_ids) { 
        $result = $this->connect(array(
            'key'        => $this->api_key,
            'action'     => 'status',
            'orders'     => implode(",", (array)$order_ids)
        ));
        return json_decode($result);
    }


    /**
     *
     * All services
     *
     */
    public function services() { 
        $result = $this->connect(array(
            'key'     => $this->api_key,
            'action'  => 'services',
        ));
        return json_decode($result);
    }

    /**
     *
     * Balance
     *
     */
    public function balance() { 
        $result = $this->connect(array(
            'key'     => $this->api_key,
            'action'  => 'balance',
        ));
        return json_decode($result);
    }

    /**
     *
     * Connect to panel
     *
     */
    private function connect($post) {
        $_post = Array();

        if (is_array($post)) {
          foreach ($post as $name => $value) {
            $_post[] = $name.'='.urlencode($value);
          }
        }

        if (is_array($post)) {
          $url_complete = join('&', $_post);
        }
        $url = $this->api_url."?".$url_complete;

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'API (compatible; MSIE 5.01; Windows NT 5.0)');
        $result = curl_exec($ch);
        if (curl_errno($ch) != 0 && empty($result)) {
          $result = false;
        }
        curl_close($ch);
        return $result;
    }

}

// Examples
$api = new Api();

# return all services
$services = $api->services(); 

# return user balance
$balance = $api->balance(); 

// add order
$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100)); # Default

$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'comments' => "good picngreat photon:)n;)")); # Custom Comments

$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'runs' => 10, 'interval' => 60)); # Drip-feed

# return status, charge, remains, start count, order_id
$status = $api->status(23); 

# return orders status, charge, remains, start count, order_id
$statuses = $api->multi_status([12, 2, 13]); 

Source: Python-3x Questions

LEAVE A COMMENT