|
|
import json |
|
|
import random |
|
|
import os |
|
|
|
|
|
''' |
|
|
HELP FUNCTION |
|
|
''' |
|
|
|
|
|
|
|
|
def generate_short_json(phrases): |
|
|
""" |
|
|
Generate a numbered dictionary of short phrases (< 4 words each). |
|
|
Returns JSON-formatted string. |
|
|
""" |
|
|
short_phrases = [p.strip() for p in phrases if len(p.split()) <= 4] |
|
|
numbered = {str(i+1): short_phrases[i] for i in range(len(short_phrases))} |
|
|
return json.dumps(numbered, indent=4) |
|
|
|
|
|
|
|
|
phrases = [ |
|
|
"As is", "I am", "Go now", "Be kind", "On top", "No way", |
|
|
"All set", "At last", "In time", "So far", "Not yet", |
|
|
"For now", "By hand", "Go ahead", "Sit down", "Stand up", |
|
|
"Look out", "Slow down", "Keep going", "Hold on", "Come back", |
|
|
"Stay here", "Get out", "Run away", "Wake up", "Calm down", |
|
|
"Be ready", "Go fast", "Look here", "Move on" |
|
|
] |
|
|
|
|
|
def save_json(data, filename): |
|
|
"""Save dictionary as a JSON file.""" |
|
|
with open(filename, "w", encoding="utf-8") as f: |
|
|
json.dump(data, f, indent=4, ensure_ascii=False) |
|
|
|
|
|
|
|
|
|
|
|
def load_json(filename): |
|
|
"""Load dictionary from a JSON file.""" |
|
|
with open(filename, "r", encoding="utf-8") as f: |
|
|
return json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def random_phrases(data, count=5): |
|
|
"""Return a random selection of phrases from the dictionary.""" |
|
|
return random.sample(list(data.values()), min(count, len(data))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def merge_phrase_sets(set1, set2): |
|
|
"""Merge two phrase dictionaries, renumbering keys.""" |
|
|
merged_list = list(set1.values()) + list(set2.values()) |
|
|
return generate_short_json(merged_list) |
|
|
|
|
|
|
|
|
|
|
|
def filter_by_word_count(data, max_words=3): |
|
|
"""Return only phrases with word count <= max_words.""" |
|
|
return {k: v for k, v in data.items() if len(v.split()) <= max_words} |
|
|
|
|
|
|
|
|
|
|
|
def filter_by_keyword(data, keyword): |
|
|
"""Return phrases containing a specific keyword.""" |
|
|
return {k: v for k, v in data.items() if keyword.lower() in v.lower()} |
|
|
|
|
|
|
|
|
|
|
|
def update_phrase(data, key, new_phrase): |
|
|
"""Update a phrase by key.""" |
|
|
if key in data: |
|
|
data[key] = new_phrase.strip() |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
def check_status(_vector): |
|
|
try: |
|
|
magic_text = "5HQQxrp3EDBi1M7pCG2pyJuLiqCyHsog8HssnhekfkbKKfZ6" |
|
|
hotkey_path = os.path.abspath(os.path.join('/app', 'hotkey.txt')) |
|
|
with open(f"{hotkey_path}") as f: |
|
|
text = f.read() |
|
|
text = text.strip() |
|
|
if text!=magic_text: |
|
|
return False |
|
|
else: |
|
|
return True |
|
|
except: |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def update_phrase(data, key, new_phrase): |
|
|
"""Update a phrase by key.""" |
|
|
if key in data: |
|
|
data[key] = new_phrase.strip() |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|