Skip to content

Commit

Permalink
move.
Browse files Browse the repository at this point in the history
  • Loading branch information
montaguethomas committed Jun 11, 2024
1 parent a2d2e4d commit 3589b71
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,6 @@ def _fetch_api_token(session):
return raw_input("Please enter the api_token (\"xoxs-12345-abcdefg....\") from the page: ").strip()


def main():
args = _argparse()
session = _session(args)
existing_emojis = get_current_emoji_list(session)
uploaded = 0
skipped = 0

def process_file(filename):
nonlocal skipped
nonlocal uploaded
print("Processing {}.".format(filename))
emoji_name = "{}{}{}".format(
args.prefix.strip(),
os.path.splitext(os.path.basename(filename))[0],
args.suffix.strip()
)
if emoji_name in existing_emojis:
print("Skipping {}. Emoji already exists".format(emoji_name))
skipped += 1
else:
upload_emoji(session, emoji_name, filename)
print("{} upload complete.".format(filename))
uploaded += 1

for slackmoji_file in args.slackmoji_files:
if os.path.isdir(slackmoji_file):
for file in os.listdir(slackmoji_file):
filename = os.path.join(slackmoji_file, file)
process_file(filename)
else:
process_file(slackmoji_file)
print("\nUploaded {} emojis. ({} already existed)".format(uploaded, skipped))


def get_current_emoji_list(session):
page = 1
result = []
Expand Down Expand Up @@ -200,5 +166,39 @@ def upload_emoji(session, emoji_name, filename):
break


def main():
args = _argparse()
session = _session(args)
existing_emojis = get_current_emoji_list(session)
uploaded = 0
skipped = 0

def process_file(filename):
nonlocal skipped
nonlocal uploaded
print("Processing {}.".format(filename))
emoji_name = "{}{}{}".format(
args.prefix.strip(),
os.path.splitext(os.path.basename(filename))[0],
args.suffix.strip()
)
if emoji_name in existing_emojis:
print("Skipping {}. Emoji already exists".format(emoji_name))
skipped += 1
else:
upload_emoji(session, emoji_name, filename)
print("{} upload complete.".format(filename))
uploaded += 1

for slackmoji_file in args.slackmoji_files:
if os.path.isdir(slackmoji_file):
for file in os.listdir(slackmoji_file):
filename = os.path.join(slackmoji_file, file)
process_file(filename)
else:
process_file(slackmoji_file)
print("\nUploaded {} emojis. ({} already existed)".format(uploaded, skipped))


if __name__ == "__main__":
main()

0 comments on commit 3589b71

Please sign in to comment.