initial commit of the extraction script
This commit is contained in:
parent
9a2c8e1a1e
commit
f998594403
1 changed files with 46 additions and 0 deletions
46
osada-profile-to-csv.py
Normal file
46
osada-profile-to-csv.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
## SPDX-FileCopyrightText: 2022 Tobias Diekershoff <tobias.diekershoff@gmx.net>
|
||||
##
|
||||
## 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()
|
Loading…
Add table
Reference in a new issue