diff --git a/Image Uploader/.gitignore b/Image Uploader/.gitignore new file mode 100644 index 0000000..30fe0fb --- /dev/null +++ b/Image Uploader/.gitignore @@ -0,0 +1 @@ +secret.env \ No newline at end of file diff --git a/Image Uploader/README.md b/Image Uploader/README.md new file mode 100644 index 0000000..61efce3 --- /dev/null +++ b/Image Uploader/README.md @@ -0,0 +1,23 @@ +# Image Upload Script + +## Overview + +This Python script allows users to upload images from their clipboard directly to Imgur by pressing a keyboard shortcut. It utilizes the Imgur API for image uploads and the `python-dotenv` package to manage environment variables securely. + +## Features + +- **Clipboard Image Capture**: Captures images from the clipboard. +- **Imgur API Integration**: Uploads images to Imgur using a simple API call. +- **Keyboard Shortcut**: Allows users to trigger the upload with a predefined keyboard shortcut (`Ctrl + Alt + S`). +- **Environment Variable Management**: Utilizes a `secret.env` file for managing sensitive data, such as the Imgur Client ID and add it under the name `IMGUR_CLIENT_ID`. + + +**Note**: You can add an image in your clipboard using `Win + Shift + S` +Also press Esc to end the program + +## Example Screenshot + +Here’s how the application looks when running: + +![Screenshot of the app](https://i.imgur.com/e35Pvyh.png) +![Screenshot of the app](https://i.imgur.com/ZfyHcsx.png) \ No newline at end of file diff --git a/Image Uploader/main.py b/Image Uploader/main.py new file mode 100644 index 0000000..edad516 --- /dev/null +++ b/Image Uploader/main.py @@ -0,0 +1,45 @@ +import os +import requests +import keyboard +from PIL import ImageGrab +import io +import base64 +from dotenv import load_dotenv + + +load_dotenv("secret.env") +# Set your Imgur API client ID here +CLIENT_ID = os.getenv("IMGUR_CLIENT_ID") + +def upload_to_imgur(image_data): + headers = {"Authorization": f"Client-ID {CLIENT_ID}"} + response = requests.post("https://api.imgur.com/3/image", headers=headers, data={"image": image_data}) + return response.json() + +def upload_image(): + try: + image = ImageGrab.grabclipboard() + if image is None: + print("No image found in the clipboard.") + return + + + with io.BytesIO() as output: + image.save(output, format='PNG') + image_data = base64.b64encode(output.getvalue()).decode() # converted to base64 + + # Upload the image to Imgur + response = upload_to_imgur(image_data) + + if response.get("success"): + print("Image uploaded successfully:", response["data"]["link"]) + else: + print("Failed to upload image:", response) + except Exception as e: + print(f"An error occurred: {e}") + + +keyboard.add_hotkey('ctrl+alt+s', upload_image) + +print("Listening for the shortcut... (Press ESC to stop)") +keyboard.wait('esc') diff --git a/Morse Code/README.md b/Morse Code/README.md new file mode 100644 index 0000000..bcb5326 --- /dev/null +++ b/Morse Code/README.md @@ -0,0 +1,24 @@ +# Morse Code Encoder/Decoder + +## Overview + +This project provides a simple Python program to encode text into Morse code and decode Morse code back into text. It includes exception handling for invalid characters and offers default values when no input is provided. + +## Features + +- **Encoding**: Convert plain text into Morse code. +- **Decoding**: Convert Morse code back into plain text. +- **Exception Handling**: Handles invalid characters gracefully. +- **Default Values**: If no input is provided, it uses default values ('SOS' for encoding and '... --- ...' for decoding). + +## Installation + +1. Ensure you have Python installed on your machine. +2. Download the `morse_code.py` file. + +## Usage + +Run the script directly from the command line: + +```bash +python morse_code.py diff --git a/Morse Code/main.py b/Morse Code/main.py new file mode 100644 index 0000000..fdcad69 --- /dev/null +++ b/Morse Code/main.py @@ -0,0 +1,46 @@ +class MorseCode: + # Morse code dictionary + morse_dict = { + 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', + 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', + 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', + 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', + 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', + 'Z': '--..', '1': '.----', '2': '..---', '3': '...--', + '4': '....-', '5': '.....', '6': '-....', '7': '--...', + '8': '---..', '9': '----.', '0': '-----', ' ': '/' + } + + @classmethod + def encode(cls, text=""): + """Encodes a given text into Morse code.""" + if not text: + text = "SOS" # Default value if no input is provided + try: + return ' '.join(cls.morse_dict[char.upper()] for char in text) + except KeyError as e: + print(f"Error: Character '{e.args[0]}' cannot be encoded in Morse code.") + return None + + @classmethod + def decode(cls, morse_code=""): + """Decodes a given Morse code into plain text.""" + if not morse_code: + morse_code = "... --- ..." # Default value if no input is provided + try: + reverse_dict = {v: k for k, v in cls.morse_dict.items()} + return ''.join(reverse_dict[code] for code in morse_code.split()) + except KeyError as e: + print(f"Error: Morse code '{e.args[0]}' cannot be decoded.") + return None + + +if __name__ == "__main__": + # Example usage + text = input("Enter text to encode (leave blank for default 'SOS'): ") + morse_code = MorseCode.encode(text) + print(f"Morse Code: {morse_code}") + + morse_input = input("Enter Morse code to decode (leave blank for default '... --- ...'): ") + decoded_text = MorseCode.decode(morse_input) + print(f"Decoded Text: {decoded_text}") diff --git a/README.md b/README.md index 94f4246..2c70c5f 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,8 @@ More information on contributing and the general code of conduct for discussion | Image Compress | [Image Compress](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Compress) | Takes an image and compresses it. | | Image Manipulation without libraries | [Image Manipulation without libraries](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Manipulation%20without%20libraries) | Manipulates images without using any external libraries. | | Image Text | [Image Text](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Text) | Extracts text from the image. | -| Image Text to PDF | [Image Text to PDF](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Text%20to%20PDF) | Adds an image and text to a PDF. +| Image Text to PDF | [Image Text to PDF](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Text%20to%20PDF) | Adds an image and text to a PDF. +| Image Uploader | [Image Uploader](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Uploader) | Uploads images to Imgur using a keyboard shortcut. | | Image Watermarker | [Image Watermarker](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20Watermarker) | Adds a watermark to an image. | Image to ASCII | [Image to ASCII](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20to%20ASCII) | Converts an image into ASCII art. | | Image to Gif | [Image to Gif](https://github.com/DhanushNehru/Python-Scripts/tree/master/Image%20to%20GIF) | Generate gif from images. @@ -91,6 +92,7 @@ More information on contributing and the general code of conduct for discussion | Mail Sender | [Mail Sender](https://github.com/DhanushNehru/Python-Scripts/tree/master/Mail%20Sender) | Sends an email. | | Merge Two Images | [Merge Two Images](https://github.com/DhanushNehru/Python-Scripts/tree/master/Merge%20Two%20Images) | Merges two images horizontally or vertically. | | Mouse mover | [Mouse mover](https://github.com/DhanushNehru/Python-Scripts/tree/master/Mouse%20Mover) | Moves your mouse every 15 seconds. | +| Morse Code | [Mose Code](https://github.com/DhanushNehru/Python-Scripts/tree/master/Morse%20Code) | Encodes and decodes Morse code. | | No Screensaver | [No Screensaver](https://github.com/DhanushNehru/Python-Scripts/tree/master/No%20Screensaver) | Prevents screensaver from turning on. | | OTP Verification | [OTP Verification](https://github.com/DhanushNehru/Python-Scripts/tree/master/OTP%20%20Verify) | An OTP Verification Checker. | | Password Generator | [Password Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Password%20Generator) | Generates a random password. |