#!/usr/bin/env python3 ## SPDX-FileCopyrightText: 2022 Tobias Diekershoff ## ## SPDX-License-Identifier: BSD-3-Clause """ Script to extract contact URLs from an exported OSADA profile JSON file. The extracted contact information is stored as CSV file that can be uploaded and imported into Friendica (Mastodon, etc. might work as well). -- Tobias Diekershoff (2022-10-27) """ import sys import json from os.path import exists if len(sys.argv) != 2: print('Please call this script with one or two parameters.') print('1st the input file, which is the JSON exported from Osada.') print('The output will be written to the STDOUT and can be redirected from there.') sys.exit(0) if not exists(sys.argv[1]): print('File "{}" not found.'.format(sys.argv[1])) sys.exit(1) CSVFilename = sys.argv[1].replace('.json', '.csv') f = open(CSVFilename, 'w') try: f.write('Account address, Show boosts, my_permissions\n') except: print('Could not write the file "{}" stopping the extraction.'.format(CSVFilename)) sys.exit(1) with open(sys.argv[1], "r") as json_data: osada = json.load(json_data) for item in osada['abook']: for config in item['abconfig']: if config['xchan'][:8] == 'https://': if config['k'] == 'my_perms': f.write('{}, true, "{}"\n'.format(config['xchan'], config['v'])) f.close()