How to filter characters for comparison of strings in Python

i am very new to coding and I am not familiar with python, could you guys give me maybe a small example of how you would solve this problem. Basically this new device i will be working on has a 2D code(its sort of a barcode kkind of thing) and when i scan the code witha 2D scanner a string like this shows up on my notepad for example: 58183#99AF0M000F9EF3F800 the last 12 characters are the MAC address and the first 5 characters are the order number.

i need to compare that(58183#99AF0M000F9EF3F800) with the MAC address value i get from the XML page. here is the terminal output for more reference:

####################################################################################################
Current device information:
Order-number:  58184 Software-version:  1.0.0 ( Build : 1 ) Hardware version:  1.00 MAC address:  00:0F:9E:F4:1A:80
desired-Order-number: 58183 desired-Softwareversion: 1.0.0 ( Build : 1 ) desired-hardwareversion: 1.00  pc-praefix: 7A2F7
PASS
PS C:UsersAswinPython Project> 

The MAC address from the XML page has looks like this “00:0F:9E:F4:1A:80” and the 2D scancode looks like this “58183#99AF0M000F9EF3F800”. how can i take the last 12 characters of this scan code and compare it with the mac address from the XML page to see if they match.

Any example of code blocks would be much appreciated guys.

try:
    preflash = urllib.request.urlopen("http://10.10.10.2", timeout=3).getcode()
    print("Web page status code:", preflash, "FAIL")  
    sys.exit(0)
    
except urllib.error.URLError:
    correct = urllib.request.urlopen("http://192.168.100.5", timeout=10).getcode()
    print("Web page status code:", correct)
    print("IP address: 192.168.100.5 is reachable")
    

print(100*"#")

# Declare url String    
url_str = 'http://192.168.100.2/globals.xml'

# open webpage and read values
xml_str = urllib.request.urlopen(url_str).read()

# Parses XML doc to String for Terminal output
xmldoc = minidom.parseString(xml_str)

# prints the order_number from the xmldoc
order_number = xmldoc.getElementsByTagName('order_number')
ord_nmr = order_number[0].firstChild.nodeValue

# prints the firmware_version from the xmldoc
firmware_version = xmldoc.getElementsByTagName('firmware_version')
frm_ver = firmware_version[0].firstChild.nodeValue

# prints the hardware_version from the xmldoc
hardware_version = xmldoc.getElementsByTagName('hardware_version')
hrd_ver = hardware_version[0].firstChild.nodeValue
v = hrd_ver.split()[-1]

# prints the mac_address from the xmldoc
mac_address = xmldoc.getElementsByTagName('mac_address')
mac_addr = mac_address[0].firstChild.nodeValue

print("Current device information: ")
print("Order-number: ",ord_nmr, "Software-version: ",frm_ver, "Hardware version: ",v, "MAC address: ",mac_addr)

d_ordernum = "58183"
d_hw_version = "1.00"
d_sf_version = "1.0.0 ( Build : 1 )"
pc_praefix = "7A2F7"

print("desired-Order-number: 58183 desired-Softwareversion: 1.0.0 ( Build : 1 ) desired-hardwareversion: 1.00  pc-praefix: 7A2F7")

if d_sf_version == frm_ver:
    print("PASS")
else:
    print("FAIL")

Answer

You could take the string from the scan code and slice it

scan_code_cropped = scancode_string[11:]

This will get you the last 12 characters of the scan code.

Now to get the MAC address in a format to be able to compare it to the scan code, split it on the basis of “:”

list_of_chars = mac_address_string.split(":")

this will get you the character list, which can be concatenated using

mac_address_string_joined = ''.join(list_of_chars) 

and finally to compare the two strings

if scan_code_cropped == mac_address_string_joined:
    print("Mac address & Scan code matched !")

If needed in a function format, here you go:

def match_scan_with_mac(scancode_string, mac_address_string):

    # get the last 12 characters of the scan code
    scan_code_cropped = scancode_string[11:]
    
    # get the mac address without the ":"
    list_of_chars = mac_address_string.split(":")
    mac_address_string_joined = ''.join(list_of_chars) 

    # compare the MAC address and the scan string
    if scan_code_cropped == mac_address_string_joined:
        print("Mac address & Scan code matched !")
        return True

    return False