Skip to content

Commit

Permalink
Merge pull request smashwilson#9 from vmarkovtsev/master
Browse files Browse the repository at this point in the history
Improve the script
  • Loading branch information
kvarga authored Sep 25, 2016
2 parents 7b69a64 + 95e7e3d commit f61f661
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
beautifulsoup4==4.3.2
requests==2.5.3
beautifulsoup4>=4.4, <5.0
requests>=2.5.3, <3.0
10 changes: 7 additions & 3 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from bs4 import BeautifulSoup

team_name = os.getenv('SLACK_TEAM')
if not team_name:
team_name = input("Please enter the team name: ")
cookie = os.getenv('SLACK_COOKIE')
if not cookie:
cookie = input("Please enter the \"emoji\" cookie: ")

url = "https://{}.slack.com/customize/emoji".format(team_name)
headers = {
Expand All @@ -27,7 +31,7 @@ def main():
print("Processing {}.".format(filename))
emoji_name = os.path.splitext(os.path.basename(filename))[0]
if emoji_name in existing_emojis:
print("Skipping {}. Emoji already exists").format(emoji_name)
print("Skipping {}. Emoji already exists".format(emoji_name))
skipped += 1
else:
upload_emoji(emoji_name, filename)
Expand Down Expand Up @@ -60,10 +64,10 @@ def upload_emoji(emoji_name, filename):
r = requests.post(url, headers=headers, data=data, files=files, allow_redirects=False)
r.raise_for_status()
# Slack returns 200 OK even if upload fails, so check for status of 'alert_error' info box
if 'alert_error' in r.content:
if b'alert_error' in r.content:
soup = BeautifulSoup(r.text, "html.parser")
crumb = soup.find("p", attrs={"class": "alert_error"})
raise Exception("Error with uploading %s: %s" % (emoji_name, crumb.text))
print("Error with uploading %s: %s" % (emoji_name, crumb.text))

if __name__ == '__main__':
main()

0 comments on commit f61f661

Please sign in to comment.