mirror of
https://github.com/apache/superset.git
synced 2026-04-25 11:04:48 +00:00
feat(alert/report): chart as csv format attachment for email and slack (#13828)
* add ui for setting report format * refactor default notification format * init csv data alert report * add report format to report_schedule model * add ALERTS_ATTACH_REPORTS feature flag * fix lint * update check image tag * fix migrations Co-authored-by: samtfm <sam@preset.io>
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import re
|
||||
from typing import Any
|
||||
import urllib.request
|
||||
from typing import Any, Dict, Optional
|
||||
from urllib.error import URLError
|
||||
|
||||
import pandas as pd
|
||||
|
||||
@@ -65,3 +67,20 @@ def df_to_escaped_csv(df: pd.DataFrame, **kwargs: Any) -> Any:
|
||||
df = df.applymap(escape_values)
|
||||
|
||||
return df.to_csv(**kwargs)
|
||||
|
||||
|
||||
def get_chart_csv_data(
|
||||
chart_url: str, auth_cookies: Optional[Dict[str, str]] = None
|
||||
) -> Optional[bytes]:
|
||||
content = None
|
||||
if auth_cookies:
|
||||
opener = urllib.request.build_opener()
|
||||
cookie_str = ";".join([f"{key}={val}" for key, val in auth_cookies.items()])
|
||||
opener.addheaders.append(("Cookie", cookie_str))
|
||||
response = opener.open(chart_url)
|
||||
content = response.read()
|
||||
if response.getcode() != 200:
|
||||
raise URLError(response.getcode())
|
||||
if content:
|
||||
return content
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user