From 1a36475553c43c0753ab41537c4052635613fa19 Mon Sep 17 00:00:00 2001 From: huangchunbo <895953452@qq.com> Date: Wed, 24 Apr 2024 16:07:49 +0800 Subject: [PATCH] file path auto adaptation --- app/daily_hot_news.py | 8 ++++++-- app/slash_command.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/daily_hot_news.py b/app/daily_hot_news.py index ecd54465..b48d213a 100644 --- a/app/daily_hot_news.py +++ b/app/daily_hot_news.py @@ -4,10 +4,14 @@ import feedparser import html2text import concurrent.futures - +import os from app.gpt import get_answer_from_llama_web -with open("app/data/hot_news_rss.json", "r") as f: +current_file_path = os.path.abspath(__file__) +current_dir_path = os.path.dirname(current_file_path) +hot_news_file_path = os.path.join(current_dir_path, "data", "hot_news_rss.json") + +with open(hot_news_file_path, "r") as f: rss_urls = json.load(f) TODAY = today = date.today() diff --git a/app/slash_command.py b/app/slash_command.py index 0d75607c..3c2c7bfa 100644 --- a/app/slash_command.py +++ b/app/slash_command.py @@ -1,6 +1,12 @@ import json +import os -with open("app/data/prompt.json", "r") as f: + +current_file_path = os.path.abspath(__file__) +current_dir_path = os.path.dirname(current_file_path) +slash_propmt_file_path = os.path.join(current_dir_path, "data", "prompt.json") + +with open(slash_propmt_file_path, "r") as f: prompt_data = json.load(f) def register_slack_slash_commands(slack_app): @@ -256,4 +262,4 @@ def handle_command_gpt_as_regex_master(ack, say, command): text=f"<@{user_id}>, let's talk!", blocks=blocks, reply_broadcast=True - ) \ No newline at end of file + )