From 72431280e89697283f586e4773588ab5074bbf4b Mon Sep 17 00:00:00 2001 From: Murat Onur Yildirim Date: Mon, 3 Oct 2022 19:11:56 +0200 Subject: [PATCH 1/2] create readme.md --- scripts/pickle_converter/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 scripts/pickle_converter/readme.md diff --git a/scripts/pickle_converter/readme.md b/scripts/pickle_converter/readme.md new file mode 100644 index 0000000..aed92e1 --- /dev/null +++ b/scripts/pickle_converter/readme.md @@ -0,0 +1,6 @@ +# .pickle to .txt or .json +This script converts .pickle files to .txt or .json files. + +## Usage +* Dependency: + * *None* From 8745afc08bd307b609d78553cf294a4721d934ae Mon Sep 17 00:00:00 2001 From: Murat Onur Yildirim Date: Mon, 3 Oct 2022 19:12:13 +0200 Subject: [PATCH 2/2] create script.py --- scripts/pickle_converter/script.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/pickle_converter/script.py diff --git a/scripts/pickle_converter/script.py b/scripts/pickle_converter/script.py new file mode 100644 index 0000000..4b23236 --- /dev/null +++ b/scripts/pickle_converter/script.py @@ -0,0 +1,20 @@ +import pickle +import pprint +import json + + +def convert_pickle(pickle_file="sample.pickle", target_file='txt'): + obj = pickle.load(open(pickle_file, "rb")) + + if target_file == 'txt': + with open("out.txt", "a") as f: + pprint.pprint(obj, stream=f) + + elif target_file == 'json': + json_obj = json.loads(json.dumps(obj, default=str)) + + with open('out.json', 'w', encoding='utf-8') as outfile: + json.dump(json_obj, outfile, ensure_ascii=False, indent=2) + + else: + print("please enter a valid doc type: 'txt', 'json'")