Skip to content

Commit

Permalink
Usage of input instead of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterheerwegh committed Nov 18, 2020
1 parent 21cd522 commit 8114513
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ or if you don't have python installed, just use the binary from a release

## Usage
```
python screenbot.py 'slack_token' 'channel'
python screenbot.py
```
or
```
screenbot.exe 'slack_token' 'channel'
```

if you have the slack_token and channel set as an environment variables you dont have to give them as arguments:
```
python screenbot.py
screenbot.exe
```

If you want to save the slack token and channel, run the script/executable in administrator mode. This is because it needs access to set the token and channel as environment variables.
Expand Down
36 changes: 16 additions & 20 deletions screenbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,26 @@ def setenv_var(varname, value):
slack_token = ''
channel = ''

if len(sys.argv) == 1 :
if os.environ.get('SLACK_BOT_TOKEN') == None or os.environ.get('SLACK_CHANNEL') == None:
print("Slack token not found in environment variables, make sure the variable is called 'SLACK_BOT_TOKEN' and 'SLACK_CHANNEL'\nUsage: python screenbot.py 'slacktoken' 'channel'")
sys.exit()
save = input("Would you like to store/edit your token and/or channel? (y/N): ")
while True:
if str(save).lower() == 'y':
token = input("Slack bot token (leave empty if you don't want to change it): ")
if token != "":
setenv_var("SLACK_BOT_TOKEN", token)
chan = input("Slack channel (leave empty if you don't want to change it): ")
if chan != "":
setenv_var("SLACK_CHANNEL", chan)

slack_token = os.environ.get('SLACK_BOT_TOKEN')
channel = os.environ.get('SLACK_CHANNEL')
elif len(sys.argv) == 2:
if os.environ.get('SLACK_BOT_TOKEN') == None:
print("Slack token not found in environment variables, make sure the variable is called 'SLACK_BOT_TOKEN'\nUsage: python screenbot.py 'slacktoken' 'channel'")
sys.exit()
if os.environ.get('SLACK_BOT_TOKEN') == None or os.environ.get('SLACK_CHANNEL') == None:
print("Slack token not found in environment variables, make sure the variable is called 'SLACK_BOT_TOKEN' and 'SLACK_CHANNEL'\n")
else:
break

print("Using slack token from environment variables")
slack_token = os.environ.get('SLACK_BOT_TOKEN')
channel = sys.argv[1]
else:
x = input("Do you want to save these variables? (y/N): ")
if str(x).lower() == 'y':
setenv_var("SLACK_BOT_TOKEN", sys.argv[1])
setenv_var("SLACK_CHANNEL", sys.argv[2])
slack_token = sys.argv[1]
channel = sys.argv[2]
slack_token = os.environ.get('SLACK_BOT_TOKEN')
channel = os.environ.get('SLACK_CHANNEL')

print("Bot is ready")
print("Press the 'print screen' button to send a screenshot, press 'escape' to quit")

client = slack.WebClient(token=slack_token)

Expand Down

0 comments on commit 8114513

Please sign in to comment.