Created
January 26, 2023 10:39
-
-
Save hanfei1991/6a6dae16f1f3fc5d778450da7f874e10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from yaml import load, dump, FullLoader | |
import sys | |
file_name = sys.argv[1] | |
def process_ua(data): | |
for node in data: | |
if 'family_replacement' not in node: | |
node['family_replacement'] = '$1' | |
if 'v1_replacement' not in node: | |
node['v1_replacement'] = '$2' | |
if 'v2_replacement' not in node: | |
node['v2_replacement'] = '$3' | |
with open('ua.yaml', 'w') as stream: | |
dump(data, stream) | |
def process_os(data): | |
for node in data: | |
if 'os_replacement' not in node: | |
node['os_replacement'] = '$1' | |
if 'os_v1_replacement' not in node: | |
node['os_v1_replacement'] = '$2' | |
if 'os_v2_replacement' not in node: | |
node['os_v2_replacement'] = '$3' | |
if 'os_v3_replacement' not in node: | |
node['os_v3_replacement'] = '$4' | |
if 'os_v4_replacement' not in node: | |
node['os_v4_replacement'] = '$5' | |
with open('os.yaml', 'w') as stream: | |
dump(data, stream) | |
def process_device(data): | |
for node in data: | |
if 'device_replacement' not in node: | |
node['device_replacement'] = '$1' | |
#if 'brand_replacement' not in node: | |
# node['brand_replacement'] = '$2' | |
if 'model_replacement' not in node: | |
node['model_replacement'] = '$1' | |
with open('device.yaml', 'w') as stream: | |
dump(data, stream) | |
with open(file_name, 'r') as file: | |
data = file.read() | |
yml = load(data, Loader=FullLoader) | |
process_ua(yml['user_agent_parsers']) | |
process_os(yml['os_parsers']) | |
process_device(yml['device_parsers']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't processed
regex_flag
key ofdevice_parsers
, example, here.You need to add the following code, like here: