Skip to content

Instantly share code, notes, and snippets.

View jattoabdul's full-sized avatar
👑
ruling the world

Jatto Abdulqahhar jattoabdul

👑
ruling the world
View GitHub Profile
def show_tasks(self, date=None):
if date in ['today', 'tomorrow', 'yesterday']:
day_date_param = self.__convert_to_date(date)
task_cells = list(filter(lambda x: datetime.strptime(self.__num_suffix(x['Next Check-In']), '%d %B %Y').date() == day_date_param, self.sheet))
if task_cells:
self.__perform_send_action(task_cells)
else:
return {'text': 'No task assigned to be checked in {}, try another date'.format(date)}
else:
date_param = date.replace('-', ' ')
def __perform_send_action(self, task_cells):
recipient = self.user_info['user']['id']
for index, row in enumerate(task_cells):
text_detail = (
'*Task #{} for {}:* \n\n'
'*Hey {},* Today is the check-in day for your writeup titled\n'
'`{}`.\n\n'
'Whats the status of the article?\n'
'PS: Please reply to this thread, the managers will review and reply you ASAP').format(
str(index + 1), row['Next Check-In'], row['Name'],
from flask_api import FlaskAPI
from config.env import app_env
from app.utils.slackhelper import SlackHelper
from flask import request, jsonify
from app.actions import Actions
from re import match
allowed_commands = [
'show-task'
def notify_channel(self):
print('Worker is running...')
while True:
# curent_time = datetime.now()
# current_hour = curent_time.hour
# current_minute = curent_time.minute
# if current_hour - 8 > 0:
# sleep_time = 24 - current_hour + 8 - (current_minute / 60)
# elif current_hour - 8 < 0:
# sleep_time = 8 - current_hour - (current_minute / 60)
def notify_channel(self):
print('Worker is running..., waiting till 8:00')
while True:
curent_time = datetime.now()
current_hour = curent_time.hour
current_minute = curent_time.minute
if current_hour - 8 > 0:
sleep_time = 24 - current_hour + 8 - (current_minute / 60)
elif current_hour - 8 < 0:
sleep_time = 8 - current_hour - (current_minute / 60)
@jattoabdul
jattoabdul / part_2_worker.py
Created July 11, 2018 09:28
Worker Entry file for my tutorial series on "How to Build A Task Notification Bot for Slack with Python"
from app.actions import Actions
from app.utils.slackhelper import SlackHelper
# Main function
def main():
slackhelper = SlackHelper()
actions = Actions(slackhelper)
actions.notify_channel()
@jattoabdul
jattoabdul / part1_app__init__.py
Last active July 10, 2018 18:02
Application entry point and main route
from flask_api import FlaskAPI
from config.env import app_env
from app.utils.slackhelper import SlackHelper
# from flask import request, jsonify
# from re import match
# from app.actions import Actions
def create_app(config_name):
app = FlaskAPI(__name__, instance_relative_config=False)
from config import get_env
from app import create_app
app = create_app(get_env('APP_ENV'))
if __name__ == '__main__':
app.run()
@jattoabdul
jattoabdul / slackhelper.py
Created July 10, 2018 17:56
Slack API helpers for our application using SlackClient as a python wrapper.
from slackclient import SlackClient
from config import get_env
class SlackHelper:
def __init__(self):
self.slack_token = get_env('SLACK_TOKEN')
self.slack_client = SlackClient(self.slack_token)
self.slack_channel = get_env('SLACK_CHANNEL')
@jattoabdul
jattoabdul / gappshelper.py
Created July 10, 2018 17:54
Google Sheet API helper for our application using gspread as a python wrapper.
import gspread
from os import path
from config import get_env
from oauth2client.service_account import ServiceAccountCredentials
class GappsHelper:
def __init__(self):
# setup for google sheet - Google Drive API Instance