This commit is contained in:
2024-12-13 17:17:41 -06:00
parent a6bcd8a5a9
commit 108647ded6
2 changed files with 95 additions and 4 deletions

View File

@@ -3,26 +3,35 @@
A collection of python scripts for Carpenter Media Group
- A script that generates a direct downloadable link from Google Drive. Works around the issue of the "no virus scan" notification.
- A simple python script to split a Zip file into smaller chunks.
Script will ask for the size, in Gigabytes, of the new files. And it will ask for the filename of the input file (can be in the same directory or you can enter a path to the file).
## Installation
Download script to a preferable location. I like to symlink it to a bin directory I have created.
Download cmg-commands directory either by checking it out with git or downloading using the download link (under the 'three dots' above.)
Then, cd into the directory and run the following command:
```bash
ln -s /path/to/split_zip_into_smaller_chunks.py ~/bin/split_zip_into_smaller_chunks
python install_scripts.py
```
## Usage
### zip splitter:
```bash
~/bin/split_zip_into_smaller_chunks
cmg-split-zip-smaller-chunks.py
Enter the maximum (in GB) zipped file size (2 is default): 1.6
Enter the path to the zipped file: enewscourier.com_archive_2016.zip
```
### Google Drive link creator:
```bash
cmg-get-drive-link.py
Enter the Google Drive Share URL: https://drive.google.com/file/d/1Cn6VxAdzhO5v1Km3iJhT8m-ZMcFIzbup/view?usp=drive_link
https://drive.usercontent.google.com/download?export=download&authuser=0&id=1Cn6VxAdzhO5v1Km3iJhT8m-ZMcFIzbup&confirm=t&uuid=8fe6734c-2491-4897-bd0a-46165e953d09
```
## License

82
install_scripts.py Normal file
View File

@@ -0,0 +1,82 @@
import os
import shutil
import sys
def find_files_starting_with(prefix):
# Get the list of all files and directories in the current working directory
items = os.listdir('.')
# Filter the list to include only files that start with the specified prefix
matching_files = [item for item in items if os.path.isfile(item) and item.startswith(prefix)]
return matching_files
def get_current_shell_name():
# Get the SHELL environment variable
current_shell = os.getenv('SHELL')
if current_shell:
# Extract the name of the shell (basename)
shell_name = os.path.basename(current_shell)
print(f"The current shell is: {shell_name}")
return shell_name
else:
print("Unable to determine the current shell.")
return None
def copy_files_to_bin(source_files, bin_path):
"""Copy specified files to the bin directory."""
for file_name in source_files:
source_file = os.path.join(os.getcwd(), file_name)
if os.path.exists(source_file) and os.path.isfile(source_file):
destination_file = os.path.join(bin_path, file_name)
shutil.copy2(source_file, destination_file)
print(f"Copied {source_file} to {destination_file}")
else:
print(f"File not found: {source_file}")
def ensure_bin_in_path(bin_path):
"""Ensure the bin directory is in the system's PATH environment variable."""
if bin_path in sys.path:
print(f"{bin_path} is already in the system path.")
else:
current_shell = get_current_shell_name()
if current_shell == 'zsh':
path_file = open(os.path.join(os.path.expanduser("~"), ".zshrc"), 'a')
elif current_shell == 'bash':
path_file = open(os.path.join(os.path.expanduser("~"), ".bashrc"), 'a')
print(f"Appending {bin_path} to system' PATH.")
path_file.write(f"export PATH=$PATH:{bin_path}")
sys.path.append(bin_path)
print(f"Added {bin_path} to the system path.")
def main():
# Define the prefix
prefix = "cmg-"
# Find all files starting with the given prefix
source_files = find_files_starting_with(prefix)
# source_files = ['cmg-get-drive-link.py', 'cmg-split-zip-smaller-chunks.py'] # Add your script names here
# Get home directory and create bin directory if it does not exist
home_dir = os.path.expanduser('~')
bin_path = os.path.join(home_dir, 'bin')
if not os.path.exists(bin_path):
os.makedirs(bin_path)
print(f"Created {bin_path}")
else:
print(f"{bin_path} already exists.")
# Copy files to the bin directory
copy_files_to_bin(source_files, bin_path)
# Ensure bin is in the system path
ensure_bin_in_path(bin_path)
if __name__ == "__main__":
main()