Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P10934
changeprop_msg.py
Active
Public
Actions
Authored by
hnowlan
on Apr 7 2020, 1:36 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F31740384: raw.txt
Apr 7 2020, 1:36 PM
2020-04-07 13:36:00 (UTC+0)
Subscribers
None
#!/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
()
Event Timeline
hnowlan
created this paste.
Apr 7 2020, 1:36 PM
2020-04-07 13:36:00 (UTC+0)
hnowlan
mentioned this in
T248677: Finalise changeprop migration to k8s
.
Apr 7 2020, 2:52 PM
2020-04-07 14:52:52 (UTC+0)
Log In to Comment