Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Last active Jan 29, 2021
Embed
What would you like to do?
#!/usr/local/bin/python3
from datetime import date
import os, requests
start = date(2020, 12, 31)
today = date.today()
delta = today - start
if (delta.days < 101):
print("Today is day {}".format(delta.days))
token = os.getenv('SLACK_AUTH_TOKEN')
channel = os.getenv('SLACK_CHANNEL_ID')
url = 'https://slack.com/api/conversations.setTopic'
payload = {'channel':channel, 'topic': "Day: {}".format(delta.days)}
headers = {'Authorization': "Bearer {}".format(token)}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text.encode('utf8'))
else:
print('100 Days of Code sprint has ended')

User Token Scopes

Scopes that access user data and act on behalf of users that authorize them.

OAuth Scope Description
channels:write Manage a user's public channels and create new ones on a user's behalf
groups:write Manage a user's private channels and create new ones on a user's behalf
im:write Start direct messages with people on a user's behalf
mpim:write Start group direct messages with people on a user's behalf

Testing

conversations.setTopic

# TODO: Convert this into a function XD
from datetime import date
from datetime import timedelta as delta
length = delta(days = 100)
today = date.today()
# Sprints are 100 days long and start on 1/1, 5/1, and 9/1
sprints = {
1:{'start':date(today.year, 1, 1), 'end':date(today.year, 1, 1) + length},
2:{'start':date(today.year, 5, 1), 'end':date(today.year, 5, 1) + length},
3:{'start':date(today.year, 9, 1), 'end':date(today.year, 9, 1) + length},
4:{'start':date(today.year+1, 1, 1)}
}
print(today)
for sprint in sprints:
if sprints[sprint]['start'] <= today <= sprints[sprint]['end']:
current = today - sprints[sprint]['start'] + delta(days = 1)
remaining = sprints[sprint]['end'] - today - delta(days = 1)
print("Sprint {}: Day {}, {} days remaining".format(sprint, current.days, remaining.days))
break
print("No sprint in progress")
for sprint in range(1,4):
if sprints[sprint]['end'] <= today <= sprints[sprint+1]['start']:
next_sprint = sprints[sprint+1]['start'] - today
print("Next sprint starts in {} days".format(next_sprint.days))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment