This commit is contained in:
notfire 2024-09-29 20:19:57 -04:00
commit 36bb90faf0
Signed by: notfire
GPG key ID: 01661E362467B090
3 changed files with 33 additions and 0 deletions

5
.env.example Normal file
View file

@ -0,0 +1,5 @@
EMOJI_INSTANCE_BASE_PROTO="https"
EMOJI_INSTANCE_BASE_URL="yourinstance.net"
EMOJI_AUTH_TOKEN="Bearer yourtoken"
EMOJI_FILE_TYPES='["png", "jpg", "gif"]'
EMOJI_SUFFIXES='["256"]'

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.env

View file

@ -0,0 +1,27 @@
import glob, requests, os, json
from dotenv import load_dotenv
load_dotenv()
instance_base_proto = os.getenv("EMOJI_INSTANCE_BASE_PROTO")
instance_base_url = os.getenv("EMOJI_INSTANCE_BASE_URL")
instance_full_url = instance_base_proto + "://" + instance_base_url + "/api/iceshrimp/emoji"
auth_token = os.getenv("EMOJI_AUTH_TOKEN")
image_types = json.loads(os.getenv("EMOJI_FILE_TYPES"))
suffixes = json.loads(os.getenv("EMOJI_SUFFIXES"))
json_data = {"authorization": auth_token}
amount_of_images = 0
image_num = 0
for type in image_types:
amount_of_images += len(glob.glob(f"**/*.{type}", recursive=True))
for image in glob.glob(f"**/*.{type}", recursive=True):
image_num += 1
for suffix in suffixes:
if ("_" + suffix) in image:
os.rename(image, image.replace(("_" + suffix), ""))
image = image.replace(("_" + suffix), "")
file = {"file": open(image, "rb")}
print("adding " + image + " (" + str(image_num) + "/" + str(amount_of_images) + ")")
add = requests.post(instance_full_url, files=file, headers=json_data)