post-process external dvms, if option is set

This commit is contained in:
Believethehype
2023-12-01 12:12:46 +01:00
parent e51d8c7de3
commit 56cdddce2c
6 changed files with 65 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ from types import NoneType
import emoji
import requests
from nostr_sdk import Tag, PublicKey, EventId
from pyupload.uploader import CatboxUploader
import pandas
@@ -14,6 +15,12 @@ Post process results to either given output format or a Nostr readable plain tex
'''
class PostProcessFunctionType:
NONE = 0
LIST_TO_USERS = 1
LIST_TO_EVENTS = 2
def post_process_result(anno, original_event):
print("Post-processing...")
if isinstance(anno, pandas.DataFrame): # if input is an anno we parse it to required output format
@@ -33,7 +40,7 @@ def post_process_result(anno, original_event):
if output_format == "text/plain":
result = pandas_to_plaintext(anno)
result = replace_broken_words(
str(result).replace("\"", "").replace('[', "").replace(']',
str(result).replace("\"", "").replace('[', "").replace(']',
"").lstrip(None))
return result
@@ -78,7 +85,7 @@ def post_process_result(anno, original_event):
result = pandas_to_plaintext(anno)
print(result)
result = str(result).replace("\"", "").replace('[', "").replace(']',
"").lstrip(None)
"").lstrip(None)
return result
elif isinstance(anno, NoneType):
return "An error occurred"
@@ -87,6 +94,26 @@ def post_process_result(anno, original_event):
return result
def post_process_list_to_events(result):
result_list = json.loads(result)
result_str = ""
for tag in result_list:
p_tag = Tag.parse(tag)
result_str = result_str + "nostr:" + EventId.from_hex(
p_tag.as_vec()[1]).to_bech32() + "\n"
return result_str
def post_process_list_to_users(result):
result_list = json.loads(result)
result_str = ""
for tag in result_list:
p_tag = Tag.parse(tag)
result_str = result_str + "nostr:" + PublicKey.from_hex(
p_tag.as_vec()[1]).to_bech32() + "\n"
return result_str
def pandas_to_plaintext(anno):
result = ""
for each_row in anno['name']:
@@ -96,7 +123,6 @@ def pandas_to_plaintext(anno):
return result
'''
Convenience function to replace words like Noster with Nostr
'''