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

add better support for certain files + maybe some logic reworks #61

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
max-line-length = 120
extend-ignore = E402
per-file-ignores =
library/TextConverter.py: W605
exclude =
.git,
__pycache__,
venv,
build,
dist,
*.spec,
.github,
.vscode
56 changes: 37 additions & 19 deletions library/TextConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import barcode
from barcode.writer import ImageWriter
import math
import numpy as np # Add this import at the top of the file
import numpy as np


class TextConverter:
Expand Down Expand Up @@ -123,7 +123,8 @@ def caesar_cipher(self, text, shift):
if char.isalpha():
shift_amount = 65 if char.isupper() else 97
encrypted.append(
chr((ord(char) - shift_amount + shift) % 26 + shift_amount))
chr((ord(char
) - shift_amount + shift) % 26 + shift_amount))
else:
encrypted.append(char)
return ''.join(encrypted)
Expand All @@ -135,8 +136,11 @@ def border_text(self, text):
return text2art(text, font='block')

def zalgo_text(self, text):
zalgo_chars = ['̍', '̎', '̄', '̅', '̿', '̑', '̆', '̐', '͒', '͗', '͑', '̇', '̈', '̊', '͂', '̓', '̈', '͊', '͋', '͌', '̃', '̂', '̌', '͐',
'̀', '́', '̋', '̏', '̒', '̓', '̔', '̽', '̉', 'ͣ', 'ͤ', 'ͥ', 'ͦ', 'ͧ', 'ͨ', 'ͩ', 'ͪ', 'ͫ', 'ͬ', 'ͭ', 'ͮ', 'ͯ', '̾', '͛', '͆', '̚']
zalgo_chars = ['̍', '̎', '̄', '̅', '̿', '̑', '̆', '̐', '͒', '͗', '͑',
'̇', '̈', '̊', '͂', '̓', '̈', '͊', '͋', '͌', '̃', '̂',
'̌', '͐', '̀', '́', '̋', '̏', '̒', '̓', '̔', '̽', '̉',
'ͣ', 'ͤ', 'ͥ', 'ͦ', 'ͧ', 'ͨ', 'ͩ', 'ͪ', 'ͫ', 'ͬ', 'ͭ',
'ͮ', 'ͯ', '̾', '͛', '͆', '̚']
return ''.join(random.choice(zalgo_chars) + char for char in text)

def morse_code(self, text):
Expand All @@ -154,7 +158,8 @@ def morse_code(self, text):
'-': '-....-', '(': '-.--.', ')': '-.--.-',
' ': '/'
}
return ' '.join(MORSE_CODE_DICT.get(char.upper(), char) for char in text)
return ' '.join(MORSE_CODE_DICT.get(char.upper(
), char) for char in text)

def binary_text(self, text):
return ' '.join(format(ord(char), '08b') for char in text)
Expand Down Expand Up @@ -187,7 +192,8 @@ def generate_code(self, text, code_type, filename=None):

if code_type == 'qr':
qr = qrcode.QRCode(
version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
version=1, error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10, border=4)
qr.add_data(text)
qr.make(fit=True)
img = qr.make_image(fill='black', back_color='white')
Expand All @@ -204,28 +210,38 @@ def text_to_emoticons(self, text):
'hello': '👋', 'world': '🌍', 'love': '❤️', 'happy': '😊', 'sad': '😢',
'laugh': '😂', 'smile': '😃', 'angry': '😠', 'cool': '😎', 'sun': '☀️',
'moon': '🌙', 'star': '⭐', 'food': '🍔', 'drink': '🍹', 'music': '🎵',
'book': '📚', 'computer': '💻', 'phone': '📱', 'car': '🚗', 'house': '🏠',
'book': '📚', 'computer': '💻', 'phone': '📱', 'car': '🚗',
'house': '🏠',
'tree': '🌳', 'flower': '🌸', 'dog': '🐶', 'cat': '🐱', 'bird': '🐦',
'fish': '🐠', 'heart': '❤️', 'fire': '🔥', 'water': '💧', 'earth': '🌎',
'fish': '🐠', 'heart': '❤️', 'fire': '🔥', 'water': '💧',
'earth': '🌎',
'air': '💨', 'time': '⏰', 'money': '💰', 'work': '💼', 'sleep': '😴',
'party': '🎉', 'gift': '🎁', 'camera': '📷', 'movie': '🎬', 'music': '🎵',
'party': '🎉', 'gift': '🎁', 'camera': '📷', 'movie': '🎬',
'music': '🎵',
'sport': '⚽', 'win': '🏆', 'yes': '👍', 'no': '👎', 'ok': '👌',
'hello': '👋', 'bye': '👋', 'please': '🙏', 'thanks': '🙏', 'sorry': '😔',
'hello': '👋', 'bye': '👋', 'please': '🙏', 'thanks': '🙏',
'sorry': '😔',
'wow': '😮', 'omg': '😱', 'lol': '😂', 'idea': '💡', 'question': '❓',
'answer': '✅', 'warning': '⚠️', 'stop': '🛑', 'go': '🚦', 'fast': '⚡',
'answer': '✅', 'warning': '⚠️', 'stop': '🛑', 'go': '🚦',
'fast': '⚡',
'slow': '🐌', 'up': '⬆️', 'down': '⬇️', 'left': '⬅️', 'right': '➡️',
'back': '🔙', 'soon': '🔜', 'new': '🆕', 'free': '🆓', 'hot': '🔥',
'cold': '❄️', 'big': '🐘', 'small': '🐜', 'loud': '📢', 'quiet': '🤫',
'good': '👍', 'bad': '👎', 'sick': '🤒', 'healthy': '💪', 'smart': '🧠',
'crazy': '🤪', 'king': '👑', 'queen': '👸', 'baby': '👶', 'ghost': '👻',
'alien': '👽', 'robot': '🤖', 'rainbow': '🌈', 'unicorn': '🦄', 'pizza': '🍕',
'alien': '👽', 'robot': '🤖', 'rainbow': '🌈', 'unicorn': '🦄',
'pizza': '🍕',
'beer': '🍺', 'wine': '🍷', 'coffee': '☕', 'tea': '🍵', 'cake': '🎂',
'balloon': '🎈', 'rocket': '🚀', 'airplane': '✈️', 'train': '🚂', 'boat': '⛵',
'beach': '🏖️', 'mountain': '⛰️', 'camping': '⛺', 'fire': '🔥', 'snow': '❄️',
'rain': '🌧️', 'wind': '💨', 'cloud': '☁️', 'thunder': '⚡', 'rainbow': '🌈'
'balloon': '🎈', 'rocket': '🚀', 'airplane': '✈️', 'train': '🚂',
'boat': '⛵',
'beach': '🏖️', 'mountain': '⛰️', 'camping': '⛺', 'fire': '🔥',
'snow': '❄️',
'rain': '🌧️', 'wind': '💨', 'cloud': '☁️', 'thunder': '⚡',
'rainbow': '🌈'
}
words = text.split()
return ' '.join(emoticon_dict.get(word.lower(), word) for word in words)
return ' '.join(emoticon_dict.get(word.lower(
), word) for word in words)

def nerd_mode(self, text):
word_count = len(text.split())
Expand Down Expand Up @@ -268,7 +284,7 @@ def morse_code_audio(self, text):
'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--',
'Z': '--..',

'0': '-----', '1': '.----', '2': '..---', '3': '...--',
'4': '....-', '5': '.....', '6': '-....', '7': '--...',
'8': '---..', '9': '----.',
Expand All @@ -281,7 +297,8 @@ def morse_code_audio(self, text):

def generate_sine_wave(freq, duration, volume=1.0, sample_rate=44100):
num_samples = int(sample_rate * duration)
samples = [int(volume * 32767 * math.sin(2 * math.pi * freq * t / sample_rate))
samples = [int(volume * 32767 * math.sin(
2 * math.pi * freq * t / sample_rate))
for t in range(num_samples)]
return samples

Expand All @@ -306,7 +323,8 @@ def generate_sine_wave(freq, duration, volume=1.0, sample_rate=44100):
morse_audio.extend(medium_gap)

# Create a temporary WAV file
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as temp_wav:
with tempfile.NamedTemporaryFile(suffix='.wav',
delete=False) as temp_wav:
temp_wav_path = temp_wav.name
with wave.open(temp_wav_path, 'w') as wav_file:
wav_file.setnchannels(1)
Expand Down
13 changes: 13 additions & 0 deletions library/file_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys


def read_file(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
return file.read().strip()
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
sys.exit(1)
except IOError:
print(f"Error: Unable to read file '{file_path}'.")
sys.exit(1)
13 changes: 1 addition & 12 deletions versions/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@
import pyperclip
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from library.TextConverter import TextConverter


def read_file(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
return file.read().strip()
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
sys.exit(1)
except IOError:
print(f"Error: Unable to read file '{file_path}'.")
sys.exit(1)
from library.file_utils import read_file


def main():
Expand Down
Loading