Skip to content

Commit

Permalink
Using pyperclip and removing superuser
Browse files Browse the repository at this point in the history
-replaced the xclip with pyperclip
-moved the installation folder from system to the user home directory
-added icon to the notification
  • Loading branch information
pakosaan committed Apr 27, 2023
1 parent 12b4513 commit 265a065
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
9 changes: 7 additions & 2 deletions imgur
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ import json
import sys
import os
import aiohttp
import pyperclip
import subprocess

icon_path = os.path.expanduser("~/.local/share/icons/hicolor/256x256/apps/imgur.png")

async def upload_image(session, image_path):
async with session.post("https://api.imgur.com/3/upload", headers={"Authorization": f"Bearer {token}"}, data={"image": open(image_path, "rb")}) as response:
response_json = await response.json()
link = response_json["data"]["link"]
subprocess.run(["xclip", "-sel", "clip"], input=link, encoding='ascii')
# subprocess.run(["xclip", "-sel", "clip"], input=link, encoding='ascii')
pyperclip.copy(link)
print(f"Uploaded {image_path}, link copied to clipboard: {link}")

async def main():
async with aiohttp.ClientSession() as session:
tasks = [upload_image(session, image) for image in image_paths]
await asyncio.gather(*tasks)
subprocess.run(["notify-send", "imgur", "All images have been uploaded!"])
subprocess.run(["notify-send", "All Image uploaded", "-i", icon_path])


if __name__ == "__main__":
config_file_path = os.path.expanduser("~/.config/imgur/config")
Expand Down
4 changes: 2 additions & 2 deletions imgur.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ X-KDE-StartupNotify=false
X-KDE-Priority=TopLevel

[Desktop Action Upload2Imgur]
Exec=imgur %U
Exec=$HOME/.local/bin/imgur %U
Name=Upload to imgur.com
Name[nl]=Uploaden naar imgur.com
Icon=/usr/share/pixmaps/imgur.png
Icon=imgur
19 changes: 17 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
#!/bin/bash
# Install pyperclip
pip install --user pyperclip

# Set the installation paths
icon_path="$HOME/.local/share/icons/hicolor/256x256/apps"

# Create the directories if they don't exist
mkdir -p "$icon_path"

install -m 644 imgur.png "$icon_path"

install -m 644 imgur.desktop `kf5-config --path services | cut -f1 -d':'`
sudo install -m 644 imgur.png /usr/share/pixmaps/
sudo install -m 755 imgur /usr/bin/
install -m 755 imgur $HOME/.local/bin/
if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
source ~/.bashrc
fi



4 changes: 2 additions & 2 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
rm "`kf5-config --path services | cut -f1 -d':'`imgur.desktop"
sudo rm /usr/share/pixmaps/imgur.png
sudo rm /usr/bin/imgur
rm $HOME/.local/share/icons/hicolor/256x256/apps/imgur.png
rm $HOME/.local/bin/imgur

0 comments on commit 265a065

Please sign in to comment.