我需要在python上做任何想法

时间:2013-02-08 05:19:10

标签: php python xml

我需要在python上做任何帮助,这段代码从xml文件检查调制解调器状态,如果不正常则激活服务

XML示例

<SMSCStatus>
        <Name>HUAWEI Mobile Connect - 3G Modem</Name>
        <Status>ERROR</Status>
        <StatusDetail>
                Modem Failure -- Unable to access modem, ensure that it is powered on and passes diagnostic tests.
        </StatusDetail>
        <MessagesToday>0</MessagesToday>
        <MessagesLast7Days>0</MessagesLast7Days>
        <MessagesLast30Days>0</MessagesLast30Days>
</SMSCStatus>
<?php

$xml = simplexml_load_file("xmlfile");
$status1 = $xml->SMSCStatus->Status;

if ($status1 == "OK")
        {
        $fp = fopen("status.txt", "w");
        fwrite($fp, "2");
        fclose($fp);
        }
  else
        {
        $statusr = json_encode(array(
                'server' => 'TOO FAIL'
        ));
        echo exec('net start "NowSMS"');
        }

?>

1 个答案:

答案 0 :(得分:1)

在python中,使用this代替simplexml_load_file,将subprocess模块替换为exec。