-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.py
More file actions
33 lines (25 loc) · 810 Bytes
/
add.py
File metadata and controls
33 lines (25 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import sys
import time
from pathlib import Path
import mimetypes
import os
from dotenv import load_dotenv
def main():
load_dotenv()
TOKEN = os.getenv('SLACK_PRIVATE_TOKEN')
WORKSPACE = os.getenv('SLACK_WORKSPACE_NAME')
for line in iter(sys.stdin.readline, ""):
p = Path(line.rstrip())
name = p.stem
mime_type = mimetypes.guess_type(p)[0]
img_data = open(p, 'rb').read()
data = {"name": (None, name, ""), "mode": (None, "data", ""), "token": (
None, TOKEN, ""), "image": (p.name, img_data, mime_type)}
print(name)
response = requests.post(
f'https://{WORKSPACE}.slack.com/api/emoji.add', files=data)
print(response.json())
time.sleep(3)
if __name__ == '__main__':
main()