<commit_before>from flask import Flask, request, abort
from auth import auth_slack

GROUP_DOMAIN = 'lambdafrela'
CONFIRMATION_TOKEN = '<PASSWORD>'

app = Flask(__name__)
slack = auth_slack()


@app.route('/callback/xE4sA', methods=['GET', 'POST'])
def callback():
	if not request.json or 'type' not in request.json:
		abort(400)

	if request.json['type'] == 'confirmation':
		return CONFIRMATION_TOKEN

	if request.json['type'] == 'wall_post_new':
		text = request.json['object']['text']
		slack.chat.post_message('#admin', text, as_user=True)
		return 'ok', 200

if __name__ == '__main__':
	app.run(host="0.0.0.0", port=5000)<commit_msg>sending message with attachment as json #4<commit_after>import json
import os

from flask import Flask, request, abort
from slacker import Slacker

''' getting enviroment variables '''

app = Flask(__name__)


def auth_slack():
	bot_secret = os.environ.get('SLACK_BOT_SECRET')
	# bot_secret = SLACK_BOT_SECRET
	api = Slacker(bot_secret)

	try:
		api.auth.test()
	except Exception as e:
		print('not authed\n', e)

	return api


def create_msg(post):
	text = post['text']
	footer = 'Lambda ФРЭЛА | Лямбда'
	ts = post['date']
	return json.dumps([{
		'fallback'   : '',
		'color'      : '#0093DA',
		'text'       : text,
		'ts'         : ts,
		'footer'     : footer,
		'footer_icon': 'http://lambda-it.ru/static/img/lambda_logo_mid.png',
	}]
	)


def send_message(channel, text='', attachments=None, as_user=True):
	slack.chat.post_message(channel=channel,
							text=text,
							attachments=attachments,
							as_user=as_user)


@app.route('/callback/xE4sA', methods=['GET', 'POST'])
def callback():
	if not request.json or 'type' not in request.json:
		abort(400)

	if request.json['type'] == 'confirmation':
		confirmation_token = os.environ.get('CONFIRMATION_TOKEN')
		return confirmation_token

	if request.json['type'] == 'wall_post_new':
		post = request.json['object']
		channel = os.environ.get('CHANNEL')
		text = os.environ.get('TEXT')
		send_message(channel=channel, text=text, attachments=create_msg(post))
		return 'ok', 200


slack = auth_slack()

if __name__ == '__main__':
	app.run(host="0.0.0.0", port=5000)
{'fraction_non_alphanumeric': 0.15626444752658344, 'fraction_numerical': 0.016181229773462782, 'mean_word_length': 4.577319587628866, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1573412', 'n_tokens_mistral': 857, 'n_tokens_neox': 797, 'n_words': 171}