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

Added a python script that uploads an image to imgur via keyboard shortcut. #314

Merged
merged 9 commits into from
Oct 13, 2024
1 change: 1 addition & 0 deletions Image Uploader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secret.env
23 changes: 23 additions & 0 deletions Image Uploader/README.md
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions Image Uploader/main.py
Original file line number Diff line number Diff line change
@@ -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')
24 changes: 24 additions & 0 deletions Morse Code/README.md
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions Morse Code/main.py
Original file line number Diff line number Diff line change
@@ -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}")
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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. |
Expand Down