import re def extract_nf_data(text,pattern): match = re.search(pattern, text) if match: return match.groups() else: return 'not found' text = _json.message_body pattern_keys = r"ccm=(\d+)&nf=(\d+)&cod=([\w\d]+)" pattern_provider=r"Razão Social: (.*)\n" ccm,nf,cod=extract_nf_data(text,pattern_keys) provider=extract_nf_data(text,pattern_provider)[0] response = {'ccm':ccm,'nf':nf,'cod':cod,'provider':provider} return response
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter