Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the path to the tranlsations.json #244

Merged
merged 1 commit into from
Apr 18, 2023
Merged

Conversation

bestmgmt
Copy link
Contributor

the translations.json is located inside the parent directory so this change will fix it.

the translations.json is located inside the parent directory so this change will fix it.
@AlexHTW
Copy link
Contributor

AlexHTW commented Apr 16, 2023

How are you starting the bot that is not working with the current version?

@bestmgmt
Copy link
Contributor Author

bestmgmt commented Apr 16, 2023

Hi @AlexHTW

I hope you are doing well.

I just upgraded from 0.2.3 to 0.2.4 using rsync -av --progress in Ubuntu 22.04, and after running the bot using python3 bot/main.py, it showed an error related to not being able to read "translations.json" in /bot/openai_helper.py file.

So, I had to tell the script that translations.json is located in the parent directory of /bot/ and not in the same directory.

@AlexHTW
Copy link
Contributor

AlexHTW commented Apr 16, 2023

Hey, @bestmgmt. Thanks! Hope you'de doing well, too!

I understand. I asked because for me it works using python3 bot/main.py and docker compose up and I wasn't sure if changing the path might break it for others. But I guess using __file__ will work for all options(?).

What about the path for usage_logs in usage_tracker.py. I suppose for you the folder is created inside the bot folder?
Maybe that needs your logic aswell then... although that will then require all the people who have their usage_logs inside the bot folder now to manually move it to root... better not to touch it then 😂

Anyway, your solution seems good to me for the translations, maybe someone more knowledgeable on this topic can give their opinion on this. I am currently not able to test this for all situations, hopefully tonight.

@AlexHTW
Copy link
Contributor

AlexHTW commented Apr 16, 2023

works for me using python3 bot/main.py and docker compose up 👍

@bestmgmt
Copy link
Contributor Author

FYI, I am using Supervisor instead of Docker. It is much more powerful and managing the updates is way easier compared to Docker since you did not implement any auto updaters such as WatchTower ( https://github.com/containrrr/watchtower )

You can either move the translations.json file under the bot/ folder or modify that code snippet mentioned there. I used general approach using import so built-in classes, so it can function in any OS.

By the way, as I mentioned, the code was working fine in the 0.2.3 release, however, it was broken after the latest one, 0.2.4.

I suspect your code was not properly updated to the latest release due the steps required to manually update Docker containers/images, otherwise there is no way your Python code can autonomously find the translations.json, located in the parent directory, using the current code:

with open('translations.json', 'r', encoding='utf-8') as f:
    translations = json.load(f)

Instead, you have to either define where it is located:

import os 

parent_dir_path = os.path.join(os.path.dirname(__file__), os.pardir)
translations_file_path = os.path.join(parent_dir_path, 'translations.json')

with open(translations_file_path, 'r', encoding='utf-8') as f:
    translations = json.load(f)

or, simply move the transations.json under the main bot/ directory.

@AlexHTW
Copy link
Contributor

AlexHTW commented Apr 17, 2023

Hey @bestmgmt

I suspect your code was not properly updated to the latest release due the steps required to manually update Docker containers/images,

No, I am always using the latest main branch, not using the released docker images.

otherwise there is no way your Python code can autonomously find the translations.json, located in the parent directory, using the current code.

When the bot is started with python3 bot/main.py it sets the working directory as the root directory and resolves the relative path of translations.json correctly. Apparently that is not the case for all setups, such as yours, so your solution is more robust.
Thanks for the improvement and discussion.

@n3d1117
Copy link
Owner

n3d1117 commented Apr 18, 2023

Thanks @bestmgmt!

@n3d1117 n3d1117 merged commit 245156e into n3d1117:main Apr 18, 2023
fisuri pushed a commit to fisuri/chatgpt-telegram-bot that referenced this pull request Apr 19, 2023
Fixing the path to the tranlsations.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants