From d17c0d309eaad4f1269ba235ce95489e473457e6 Mon Sep 17 00:00:00 2001 From: Ada Isopods Date: Wed, 11 Dec 2024 22:47:34 -0700 Subject: Fix emoji find+replace Emojis will no longer be added where their names are part of a larger word, eg. category -> :cat:egory where :cat: is a valid emoji If posts_log.json is invalid program will now overwrite it instead of exploding and dying and getting it all over you about it --- import-misskey.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'import-misskey.py') diff --git a/import-misskey.py b/import-misskey.py index 29b63bb..e5acfd3 100644 --- a/import-misskey.py +++ b/import-misskey.py @@ -43,27 +43,24 @@ for note in export_json: text = re.sub(HTML, '', text) text = re.sub(SPACE, ' ', text) text = re.sub(CONTRACTION, r'\1\2', text) - if(config__.emojis == False): - text = re.sub(EMOJI, '', text) text = text.strip() print(f" - {text}") corpus.append(text) - if(config__.emojis == True): - noteemojis = EMOJI.findall(text) - if(noteemojis): - emojis = emojis + noteemojis + noteemojis = EMOJI.findall(text) + if(noteemojis): + emojis = emojis + noteemojis -if(config__.emojis == True): - print('[+] preserving emojis:') - emojis = list(set(emojis)) - s_emo = [] - for emo in emojis: - s_emo.append(emo.replace(":", "")) - print(s_emo) - with open("emojis.json", "w") as f: - json.dump(s_emo, f) + +print('[+] preserving emojis:') +emojis = list(set(emojis)) +s_emo = [] +for emo in emojis: + s_emo.append(emo.replace(":", "")) +print(s_emo) +with open("emojis.json", "w") as f: + json.dump(s_emo, f) print('[+] building markov chain') model = chain.Text("@@note@@".join(corpus), well_formed=False) -- cgit v1.2.3