Name | redashsync JSON |
Version |
0.0.8
JSON |
| download |
home_page | |
Summary | A tool integrating Redash with Slack |
upload_time | 2023-07-01 06:19:54 |
maintainer | |
docs_url | None |
author | Yun |
requires_python | >=3.11 |
license | |
keywords |
redash
slack
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
*redashsync* is a tool integrating Redash with Slack. It gets data from Redash and send it to Slack channel.
# Install
```
pip install redashsync
```
# How to get necessary keys
## Redash API Key and Query ID
<img src="https://github.com/yunseokjeon/redashsync/blob/master/doc/images/1.png?raw=true">
Click *Show API Key* and You would get below address.
http://localhost/api/queries/2/results.json?api_key=2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk
Your API Key : 2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk
Your Query ID : 2
## Slack Bot Token and Setting
https://api.slack.com/apps
<img src="https://github.com/yunseokjeon/redashsync/blob/master/doc/images/2.png?raw=true">
Create New App.
<img src="https://github.com/yunseokjeon/redashsync/blob/master/doc/images/3.png?raw=true">
Get Your Bot Token.
<img src="https://github.com/yunseokjeon/redashsync/blob/master/doc/images/4.png?raw=true">
Add an OAuth Scope. 1) chat:write 2) files:write
<img src="https://github.com/yunseokjeon/redashsync/blob/master/doc/images/5.png?raw=true">
Invite your slack bot.
# Your YAML
Follow the format below to complete your yaml file.
```yaml
# ./resource/sample.yml
slack_configs:
slack:
token: <YOUR_SLACK_BOT_TOKEN> # "xoxb-***-***-***"
username: <YOUR_USER_NAME> # "redash-echo"
redash_configs:
url: <YOUR_HOST> # "http://localhost"
user_email: <YOUR_EMAIL> # "myname@example.com"
query_api_key: <YOUR_QUERY_API_KEY> # "2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk"
```
# Use
## Send messages regularly
```Python
from redashsync.redash.data import Redash
from redashsync.slack.messages import Slack
from redashsync.config.yaml import Config
from datetime import datetime
from cron_converter import Cron
config = Config("./resource/sample.yml")
redashHost = config.getRedashHost()
redashQueryKey = config.getQueryApiKey()
redashQueryId = config.getQueryId()
slackBotToken = config.getSlackBotToken()
redash = Redash(redashHost)
slack = Slack(slackBotToken)
cron = Cron()
cron.from_string("*/1 * * * *") # Send every 1 minute
referenceTime = datetime.now()
schedule = cron.schedule(referenceTime)
expectedTime = schedule.next().isoformat()
while True:
if(expectedTime == datetime.now().isoformat()[0:19]):
print(expectedTime)
expectedTime = schedule.next().isoformat()
response = redash.getQueriesFromRedash(redashQueryId, redashQueryKey)
result = redash.getColumnData(response, ['Open', 'Close'])
# result : [ [123, 456], [789, 987], ... ]
template = "*시가* : %s \n*종가* : %s \n"
# 2 is inside array's length.
result = redash.getMarkdown(template, result[0:5], 2)
# "#redash-echo" is channel name.
slack.sendMessage("#redash-echo", result)
```
## Send a graph image
```Python
from redashsync.redash.data import Redash
from redashsync.slack.messages import Slack
from redashsync.config.yaml import Config
from datetime import datetime
from cron_converter import Cron
config = Config("./resource/sample.yml")
redashHost = config.getRedashHost()
redashQueryKey = config.getQueryApiKey()
redashQueryId = config.getQueryId()
slackBotToken = config.getSlackBotToken()
redash = Redash(redashHost)
slack = Slack(slackBotToken)
# Histogram
response = redash.getQueriesFromRedash(redashQueryId, redashQueryKey)
result = redash.getColumnData(response, ['Open', 'Close'])
# If you want to name image one.png and locate it at ./resource
redash.visualizeHistplotAndSave(result, "./resource/one.png")
slack.sendFile("./resource/one.png", "#redash-echo", "Title", "comment")
```
Raw data
{
"_id": null,
"home_page": "",
"name": "redashsync",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "",
"keywords": "Redash,Slack",
"author": "Yun",
"author_email": "ysjhmtb@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7d/27/5cafe235744f9b48c169e610cb96ea53f8f954f178b813ee036886f93074/redashsync-0.0.8.tar.gz",
"platform": null,
"description": "*redashsync* is a tool integrating Redash with Slack. It gets data from Redash and send it to Slack channel.\n\n# Install\n\n```\npip install redashsync\n```\n\n# How to get necessary keys\n\n## Redash API Key and Query ID\n\n<img src=\"https://github.com/yunseokjeon/redashsync/blob/master/doc/images/1.png?raw=true\">\n\nClick *Show API Key* and You would get below address.\n\nhttp://localhost/api/queries/2/results.json?api_key=2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk\n\nYour API Key : 2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk\n\nYour Query ID : 2\n\n## Slack Bot Token and Setting\n\nhttps://api.slack.com/apps\n\n<img src=\"https://github.com/yunseokjeon/redashsync/blob/master/doc/images/2.png?raw=true\">\n\nCreate New App.\n\n<img src=\"https://github.com/yunseokjeon/redashsync/blob/master/doc/images/3.png?raw=true\">\n\nGet Your Bot Token.\n\n<img src=\"https://github.com/yunseokjeon/redashsync/blob/master/doc/images/4.png?raw=true\">\n\nAdd an OAuth Scope. 1) chat:write 2) files:write\n\n<img src=\"https://github.com/yunseokjeon/redashsync/blob/master/doc/images/5.png?raw=true\">\n\nInvite your slack bot.\n\n# Your YAML\n\nFollow the format below to complete your yaml file.\n\n```yaml\n# ./resource/sample.yml\n\nslack_configs:\n slack:\n token: <YOUR_SLACK_BOT_TOKEN> # \"xoxb-***-***-***\"\n username: <YOUR_USER_NAME> # \"redash-echo\"\n\nredash_configs:\n url: <YOUR_HOST> # \"http://localhost\"\n user_email: <YOUR_EMAIL> # \"myname@example.com\"\n query_api_key: <YOUR_QUERY_API_KEY> # \"2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk\"\n```\n\n# Use\n\n## Send messages regularly\n\n```Python\nfrom redashsync.redash.data import Redash\nfrom redashsync.slack.messages import Slack\nfrom redashsync.config.yaml import Config\nfrom datetime import datetime\nfrom cron_converter import Cron\n\nconfig = Config(\"./resource/sample.yml\")\nredashHost = config.getRedashHost()\nredashQueryKey = config.getQueryApiKey()\nredashQueryId = config.getQueryId()\nslackBotToken = config.getSlackBotToken()\n\nredash = Redash(redashHost)\nslack = Slack(slackBotToken)\n\ncron = Cron()\ncron.from_string(\"*/1 * * * *\") # Send every 1 minute\nreferenceTime = datetime.now()\nschedule = cron.schedule(referenceTime)\nexpectedTime = schedule.next().isoformat()\n\nwhile True:\n if(expectedTime == datetime.now().isoformat()[0:19]):\n print(expectedTime)\n expectedTime = schedule.next().isoformat()\n\n response = redash.getQueriesFromRedash(redashQueryId, redashQueryKey)\n result = redash.getColumnData(response, ['Open', 'Close'])\n # result : [ [123, 456], [789, 987], ... ]\n \n template = \"*\uc2dc\uac00* : %s \\n*\uc885\uac00* : %s \\n\"\n \n # 2 is inside array's length.\n result = redash.getMarkdown(template, result[0:5], 2)\n\n # \"#redash-echo\" is channel name.\n slack.sendMessage(\"#redash-echo\", result)\n```\n\n## Send a graph image\n\n```Python\nfrom redashsync.redash.data import Redash\nfrom redashsync.slack.messages import Slack\nfrom redashsync.config.yaml import Config\nfrom datetime import datetime\nfrom cron_converter import Cron\n\nconfig = Config(\"./resource/sample.yml\")\nredashHost = config.getRedashHost()\nredashQueryKey = config.getQueryApiKey()\nredashQueryId = config.getQueryId()\nslackBotToken = config.getSlackBotToken()\n\nredash = Redash(redashHost)\nslack = Slack(slackBotToken)\n\n# Histogram\nresponse = redash.getQueriesFromRedash(redashQueryId, redashQueryKey)\nresult = redash.getColumnData(response, ['Open', 'Close'])\n\n# If you want to name image one.png and locate it at ./resource \nredash.visualizeHistplotAndSave(result, \"./resource/one.png\")\nslack.sendFile(\"./resource/one.png\", \"#redash-echo\", \"Title\", \"comment\")\n```\n\n\n\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A tool integrating Redash with Slack",
"version": "0.0.8",
"project_urls": null,
"split_keywords": [
"redash",
"slack"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "14c86ffa64b10647075acb86447157f34063c14e611dc4045f24405501ac393d",
"md5": "3ac53ca24d6389c0743ca697f21402da",
"sha256": "109d3c86a7eb1e1481c1376df37b959abebcb17a21e61b40fc7ae147f15f4995"
},
"downloads": -1,
"filename": "redashsync-0.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3ac53ca24d6389c0743ca697f21402da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 6399,
"upload_time": "2023-07-01T06:19:52",
"upload_time_iso_8601": "2023-07-01T06:19:52.544254Z",
"url": "https://files.pythonhosted.org/packages/14/c8/6ffa64b10647075acb86447157f34063c14e611dc4045f24405501ac393d/redashsync-0.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7d275cafe235744f9b48c169e610cb96ea53f8f954f178b813ee036886f93074",
"md5": "0e7f1d82858173fa8aad9f74176dccb9",
"sha256": "ea0561b2b281cacb3c8f8149ee614f2350174a1f9543498434304ce9e8cadc14"
},
"downloads": -1,
"filename": "redashsync-0.0.8.tar.gz",
"has_sig": false,
"md5_digest": "0e7f1d82858173fa8aad9f74176dccb9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 5904,
"upload_time": "2023-07-01T06:19:54",
"upload_time_iso_8601": "2023-07-01T06:19:54.291835Z",
"url": "https://files.pythonhosted.org/packages/7d/27/5cafe235744f9b48c169e610cb96ea53f8f954f178b813ee036886f93074/redashsync-0.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-01 06:19:54",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "redashsync"
}