def test_compound_types(self): xml = """ <wddxPacket version='1.0'> <data> <struct> <var name='pi'><number>3.1415926</number></var> <var name='answer'><number>42</number></var> <var name='not_at_all'><null /></var> <var name='cities'> <array length='3'> <string>Auckland</string> <string>Wellington</string> <string>Christchurch</string> </array> </var> </struct> </data> </wddxPacket> """ data = wddx.loads(xml) expected = [{ 'answer': 42, 'cities': ['Auckland', 'Wellington', 'Christchurch'], 'not_at_all': None, 'pi': 3.1415926, }] self.assertEqual(data, expected)
def test_basic_types(self): xml = """ <wddxPacket version='1.0'> <data> <number>3.1415926</number> <null /> <string>Hello, world</string> <number>42</number> <dateTime>1998-06-12T04:32:12</dateTime> <boolean value='true'/> <boolean value='false'/> </data> </wddxPacket> """ data = wddx.loads(xml) expected = [ 3.1415926, None, 'Hello, world', 42, datetime.datetime(1998, 6, 12, 4, 32, 12), True, False, ] self.assertEqual(data, expected)
def test_single_string(self): xml = """ <wddxPacket version='1.0'> <header comment='PHP packet'/> <data> <string>PHP to WDDX packet example</string> </data> </wddxPacket> """ data = wddx.loads(xml) self.assertEqual(data, ['PHP to WDDX packet example',])
def get_employee_data(): """ Request hr data from banner :return: employee list from banner with vacant positions removed """ BANNER_API_KEY = os.getenv("BANNER_API_KEY") BANNER_URL = os.getenv("BANNER_URL") params = { "method": "getTransitEmployees", "setApiDept": "24E", "setApiKey": BANNER_API_KEY, } # get data in wddx format res = requests.get(BANNER_URL, params=params) # use module to parse wddx tags # and read data as list (which is actually a JSON string) json_raw = wddx.loads(res.text) # remove weird leading slashes from data contents json_clean = json_raw[0].replace("//", "") records_hr_unfiltered = json.loads(json_clean) return drop_empty_positions(records_hr_unfiltered)
def parse_response(content): items = wddx.loads(content) return items[0]
from cronFile import * #variables for run_cmd(cmd) cmd = "sudo cat /proc/cpuinfo | grep Serial | awk '{print $3}'" #variables for doPost function callmethod = "provision" #processedString = re.sub(r'<.*?>+',r'', returnString) droneid = run_cmd(cmd) droneid = droneid.strip() #print droneid returnString = doPost(droneid, callmethod) hostname = wddx.loads(returnString) fun1 = 1 fun2 = 1 fun3 = 1 if hostname[0] != "0" and hostname[0] != "me000drone01": fun1 = hostnameFile(hostname[0]) else: syslog.syslog(syslog.LOG_ERR, "Hostname is not found") pass if fun1 == 1: fun2 = crontabFile() else: syslog.syslog(syslog.LOG_ERR, "Hostname Process failed")