mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
50 lines
1.2 KiB
Python
Executable file
50 lines
1.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
from configparser import ConfigParser
|
|
import requests
|
|
|
|
sys.path.insert(
|
|
1, os.path.join(os.path.dirname(os.path.dirname(__file__)), "script-resources")
|
|
)
|
|
|
|
import common_script_utils # noqa F401
|
|
|
|
|
|
if os.name == "posix":
|
|
config_path = Path.home() / ".config" / "dotfiles" / "copy-crosscode-emoji-url.ini"
|
|
else:
|
|
common_script_utils.platform_not_supported_error()
|
|
config = ConfigParser(interpolation=None)
|
|
config.read(config_path)
|
|
|
|
|
|
data = []
|
|
|
|
|
|
def emote_downloader_and_iterator():
|
|
global data
|
|
|
|
response = requests.get(
|
|
config["default"]["ccbot_emote_registry_dump_url"], timeout=3
|
|
)
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
|
assert data["version"] == 1
|
|
|
|
for emote in data["list"]:
|
|
yield "{emote[ref]} [{emote[guild_name]}]".format(emote=emote)
|
|
|
|
|
|
chosen_index = common_script_utils.run_chooser(
|
|
emote_downloader_and_iterator(), prompt="emote", async_read=True
|
|
)
|
|
chosen_emote = data["list"][chosen_index]
|
|
common_script_utils.set_clipboard(chosen_emote["url"])
|
|
common_script_utils.send_notification(
|
|
os.path.basename(__file__),
|
|
"copied URL of {} to clipboard!".format(chosen_emote["ref"]),
|
|
)
|