diff --git a/README.md b/README.md index c9de4ae9..d370ad3f 100644 --- a/README.md +++ b/README.md @@ -129,22 +129,14 @@ The only Slack reaction gif's you'll ever need. # Automated Upload -## Slack via Selenium +## Slack via `emojipacks` -**Note:** This [appears to have broken with a recent change to the Slack upload form](https://github.com/jmhobbs/cultofthepartyparrot.com/issues/259). If you can help fix it, that would be appreciated! See [#259](https://github.com/jmhobbs/cultofthepartyparrot.com/issues/259) +First, you need to clone this repo and run the build script with `npm run build` or `yarn build`. -You'll need Python 3, Google Chrome and chromedriver (`brew install chromedriver`) -installed to run this: +It will generate a `dist/` folder containing the website build files; we only need the `dist/parrotparty.yaml`. Copy the file path. - 1. `python3 -m venv .venv` - 2. `pip install -r requirements.txt` - 3. `python upload_parrots.py --team YOUR_TEAM --username YOUR_EMAIL --password YOUR_PASS` - - The following are optional args you can append to 3. above: - 1. `--google` Use this if your Slack team uses Google signin - 2. `--guests` Use this to invite all the party guests +Then, run `emojipacks` (`npm i -g emojipacks` if you don't have it yet): you'll be asked to enter your Slack credentials plus _the path of the yaml file_. That's all! Enjoy your parrots. - __Notice__: The uploader won't re-write already existing parrots if they match by name. ## Discord via Mr. Parrot diff --git a/package.json b/package.json index 5ae497ef..eb0219e4 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "1.1.0", "description": "PARTY OR DIE", "scripts": { - "test": "gulp test" + "test": "gulp test", + "build": "gulp build" }, "repository": { "type": "git", diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a39a83e1..00000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -selenium==3.5.0 diff --git a/upload_parrots.py b/upload_parrots.py deleted file mode 100644 index 7430051b..00000000 --- a/upload_parrots.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python -import sys -import glob -import argparse -import os -import time - -from selenium import webdriver - -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC - - -class ParrotUploader(): - browser = None - loggged_in = False - - def __init__(self, slack_team): - self.browser = webdriver.Chrome() - self.slack_team = slack_team - - def login(self, username, password, google): - if self.loggged_in: - return - - self.browser.get('https://{}.slack.com/signin'.format(self.slack_team)) - - if google: - signin_button = self.browser.find_element_by_partial_link_text("Sign in with Google") - signin_button.click() - - username_field = WebDriverWait(self.browser, 30).until(EC.presence_of_element_located((By.ID, "identifierId"))) - username_field.send_keys(username) - username_next = self.browser.find_element_by_id("identifierNext") - username_next.click() - - password_field = WebDriverWait(self.browser, 30).until(EC.presence_of_element_located((By.NAME, "password"))) - password_field.send_keys(password) - password_next = self.browser.find_element_by_id("passwordNext") - password_next.click() - else: - username_field = self.browser.find_element(value="email") - password_field = self.browser.find_element(value='password') - - username_field.send_keys(username) - password_field.send_keys(password) - username_field.submit() - - self.loggged_in = True - - def upload(self, parrot_path): - if not self.loggged_in: - raise ValueError("you must first login before uploading") - emoji_url = 'https://{}.slack.com/customize/emoji'.format(self.slack_team) - if emoji_url not in self.browser.current_url: - self.browser.get(emoji_url) - - emoji_table = WebDriverWait( - self.browser, 30).until(EC.presence_of_element_located( - (By.ID, "custom_emoji"))) - parrot_name = os.path.basename(parrot_path).split('.')[0] - if ":{}:".format(parrot_name) in emoji_table.text: - print("emoji :{}: already exists".format(parrot_name)) - return - emoji_name = self.browser.find_element(value='emojiname') - emoji_name.clear() - emoji_name.send_keys(parrot_name) - - emoji_file = self.browser.find_element(value='emojiimg') - emoji_file .send_keys(parrot_path) - emoji_file.submit() - print("emoji :{}: uploaded".format(parrot_name)) - - def cleanup(self): - if self.browser: - self.browser.quit() - - -def main(): - parser = argparse.ArgumentParser( - description='Use a browser to automatically upload all party parrots into a Slack account') - parser.add_argument('--team', dest='slack_team', - help='The slack team in which to upload') - parser.add_argument('--username', - help='The slack username with which to upload') - parser.add_argument('--password', - help='The slack password with which to login') - parser.add_argument('--google', action='store_true', - help='Only add this arg if you use Google signin for your Slack team') - parser.add_argument('--guests', action='store_true', - help='Also upload guests to the party') - - args = parser.parse_args() - - uploader = ParrotUploader(slack_team=args.slack_team) - dir_path = os.path.dirname(os.path.realpath(__file__)) - all_the_parrots = glob.glob(os.path.join(dir_path, 'parrots/hd/*.gif')) - all_the_parrots += glob.glob(os.path.join(dir_path, 'parrots/*.gif')) - if (args.guests): - all_the_parrots += glob.glob(os.path.join(dir_path, 'guests/hd/*.gif')) - all_the_parrots += glob.glob(os.path.join(dir_path, 'guests/*.gif')) - - try: - uploader.login(args.username, args.password, args.google) - for parrot in all_the_parrots: - uploader.upload(parrot) - finally: - uploader.cleanup() - -if __name__ == '__main__': - sys.exit(main())