Page MenuHomePhabricator
Paste P10934

changeprop_msg.py
ActivePublic

Authored by hnowlan on Apr 7 2020, 1:36 PM.
#!/usr/bin/env python3
import argparse
import datetime
import json
import uuid
BASE_MSG = {
"$schema":"/resource_change/1.0.0",
"meta": {
"stream":"resource_change"
}
}
DEFAULT_DOMAIN = "en.wikipedia.org"
MSG_TYPES = {
"mw_purge": { "tags": ["purge"] },
"null_edit": { "tags": ["null_edit"] }
}
def parse_args() -> argparse.Namespace:
""" Parse command line arguments """
parser = argparse.ArgumentParser(
description='Generate test messages for kafka topics consumed by changeprop')
parser.add_argument("--domain", "-d", dest="domain", action="store",
default=DEFAULT_DOMAIN,
help="Domain to set in metadata")
parser.add_argument("rule", action="store",
help="The rule to generate",
choices=MSG_TYPES.keys())
parser.add_argument("--uri", dest="uri", action="store", required=True,
help="The URL to execute the query against")
args = parser.parse_args()
return args
def main():
args = parse_args()
test_message = BASE_MSG
test_message["meta"]["id"] = str(uuid.uuid1())
test_message["meta"]["dt"] = datetime.datetime.now().isoformat()
test_message["meta"]["domain"] = args.domain
test_message["meta"]["uri"] = args.uri
test_message.update(MSG_TYPES[args.rule])
print(test_message)
if __name__ == "__main__":
main()