Skip to content

Conversation

@jimzord12
Copy link

Hello, I used your code for a personal project, however I needed my code base in a single file therefore extended your code. I added the ability to export as pdf, because ChatGPT can not read .txt for some reason.

I not very good with python, not even seasoned dev, so please double check all by changes, if you wish to add them ofc.

Ty for the code

Copy link
Owner

@ableinc ableinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution to this project! I've left some comments. Once addressed and all looks well, I'll merge it.

@@ -1,5 +1,9 @@
GIT_PROJECT_DIRECTORY=
GIT_PROJECT_DIRECTORY=C:\Users\jimzord12\Codebases\GitHub\serve-tech
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove your local machine path

The user should be able to copy this file to .env and change a minimal as possible. Providing your local machine path does not provide extra clarity or use.

import os
import hashlib
import sys
load_env()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this back to the file

load_env(env_path=r'.\example.env')

def is_text_file(file_path):
text_file_extensions = ['.txt', '.md', '.go', '.py', '.java', '.html', '.css', '.js', '.mod', '.sum'] # Add more as needed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is configurable, add it to the .env.example file.

.env.example file:

FILE_EXTENSIONS=".txt,.md,.go,.py,.java,.html,.css,.js,.mod,.sum"

this file

text_file_extensions = os.environ['FILE_EXTENSIONS'].split(',')

with open(output_file, 'w', encoding='utf-8') as outfile:
for root, dirs, files in os.walk(source_directory):
for filename in files:
if filename.endswith('.txt'):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've defined is_text_file() method above, which accepts various file extensions, but you've hardcoded .txt here. Please make this dynamic - either by introducing a similar method that checks the extension or using the in built-in and a list

Example with in built-in:

filename = os.path.basename(filename)  # example.txt
file_extension = filename.split('.')[1]  # .txt, .md, etc

combined_text.append(separator_line)
combined_text.append(f"{filename.center(len(separator_line))}\n")
combined_text.append(separator_line)
combined_text.append(content + '\n')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if content already has a newline character? This will not work well with what you've written on line 41:

for subline in line.split('\n')

text = c.beginText(40, 800) # Starting position
for line in combined_text:
# Split the combined text into lines
for subline in line.split('\n'):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be best to split by the separator line you've added on lines 27 and 30. Splitting by newline character when reading content from a file can give unexpected results.

@@ -1 +1,6 @@
pydotenvs==0.2.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pydotenvs should not be removed. Please reintroduce.

```
4. Run program

4. In the "is_text_file" function, you MUST add the extensions of the file you want to be converted.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following my comment about this, change this text

def write_txt(txt_data: str, file_name: str, md5_hash: str) -> None:
full_path = os.path.join(save_directory, file_name + f'_{md5_hash}.txt')
with open(full_path, mode='w') as data:
with open(full_path, mode='w', encoding='utf-8') as data:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition. Always good to enforce encodings.

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.

2 participants