From 3dd9c28e31b8babeb2a187fbae994d9717ded168 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 3 Apr 2023 02:35:26 +0000 Subject: [PATCH] Add snake_to_camel helper --- snscrape/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/snscrape/utils.py b/snscrape/utils.py index b184058..3150924 100644 --- a/snscrape/utils.py +++ b/snscrape/utils.py @@ -2,3 +2,15 @@ def dict_map(input, keyMap): '''Return a new dict from an input dict and a {'input_key': 'output_key'} mapping''' return {outputKey: input[inputKey] for inputKey, outputKey in keyMap.items() if inputKey in input} + + +def snake_to_camel(**kwargs): + '''Return a new dict from kwargs with snake_case keys replaced by camelCase''' + + out = {} + for key, value in kwargs.items(): + keyParts = key.split('_') + for i in range(1, len(keyParts)): + keyParts[i] = keyParts[i][:1].upper() + keyParts[i][1:] + out[''.join(keyParts)] = value + return out