summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/corpix/uarand/scripts/extract-user-agents
blob: 3c6b8af86c82cc3903ebf0bf765c5808e58ea18b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
import sys
import xml.etree.ElementTree as XML
from argparse import ArgumentParser


if __name__ == "__main__":
    p = ArgumentParser(
        description=(
            "Expects XML from "
            "http://techpatterns.com/downloads/firefox/useragentswitcher.xml "
            "to be passed into STDIN and outputs user agents from this XML."
        )
    )
    p.parse_args()

    sys.stderr.write("Reading stdin...\n")
    doc = XML.iterparse(sys.stdin)
    for _, node in doc:
        ua = node.get("useragent")
        if ua != "" and ua is not None:
            print(ua)