Import notes from following csv

main
Bob Mottram 2022-11-07 18:38:20 +00:00
parent a6d90d0ae6
commit 5a9ef67775
2 changed files with 19 additions and 1 deletions

View File

@ -10,6 +10,7 @@ __module_group__ = "Core"
import os
import time
import random
from utils import acct_dir
from utils import is_account_dir
from utils import get_nickname_from_actor
from utils import get_domain_from_actor
@ -58,9 +59,13 @@ def _update_import_following(base_dir: str,
domain = handle.split('@')[1]
for line in lines:
orig_line = line
notes = None
line = line.strip()
if ',' in line:
line = line.split(',')[0].strip()
fields = line.split(',')
line = fields[0].strip()
if len(fields) >= 3:
notes = fields[2]
if line.startswith('#'):
continue
following_nickname = get_nickname_from_actor(line)
@ -74,6 +79,17 @@ def _update_import_following(base_dir: str,
# don't follow yourself
continue
following_handle = following_nickname + '@' + following_domain
if notes:
person_notes_filename = \
acct_dir(base_dir, nickname, domain) + \
'/notes/' + following_handle + '.txt'
try:
with open(person_notes_filename, 'w+',
encoding='utf-8') as fp_notes:
fp_notes.write(notes)
except OSError:
print('EX: Unable to import notes for ' +
following_handle)
if is_following_actor(base_dir,
nickname, domain, following_handle):
# remove the followed handle from the import list

View File

@ -122,6 +122,8 @@ def csv_following_list(following_filename: str,
with open(person_notes_filename, 'r',
encoding='utf-8') as fp_notes:
person_notes = fp_notes.read()
person_notes = person_notes.replace(',', ' ')
person_notes = person_notes.replace(' ', ' ')
following_list_csv += person_notes
msg = 'Account address,Show boosts,Notes\n' + following_list_csv
return msg