From bcaefd4a2e0d24bfc8eaf650994b909438db94a8 Mon Sep 17 00:00:00 2001 From: Igor Brigadir Date: Thu, 30 Jun 2022 11:57:10 +0100 Subject: [PATCH] append matching rules from stream when flattening --- twarc/expansions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/twarc/expansions.py b/twarc/expansions.py index 4e4c05b7..b628cd20 100644 --- a/twarc/expansions.py +++ b/twarc/expansions.py @@ -208,10 +208,13 @@ def expand_payload(payload): elif isinstance(data, dict): tweets = [expand_payload(response["data"])] - # Add the __twarc metadata to each tweet if it's a result set + # Add the __twarc metadata and matching rules to each tweet if it's a result set if "__twarc" in response: for tweet in tweets: tweet["__twarc"] = response["__twarc"] + if "matching_rules" in response: + for tweet in tweets: + tweet["matching_rules"] = response["matching_rules"] else: raise ValueError(f"missing data stanza in response: {response}")