Skip to content

Instantly share code, notes, and snippets.

View susodapop's full-sized avatar

Jesse susodapop

View GitHub Profile
@susodapop
susodapop / redash_csv_to_query.py
Created August 16, 2019 12:57
Use this snippet to convert an input CSV file into a query for Redash. This is nifty if you can't host your CSV. This only works with up to 500 rows of data, so it's a bit of an edge case.
import csv
import re
import string
with open('MOCK_DATA.csv', newline='\n', encoding="cp437") as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
headers = spamreader.__next__();
pat = re.compile = r"'"
repl = r"''"
@susodapop
susodapop / cloner.py
Last active February 26, 2020 22:23 — forked from arikfr/redash.py
Edited to allow dashboard clone that forks the underlying queries
from redash import Redash
# Enter your user API key, Redash URL, and the URL slug for your target dashboard
API_KEY = ''
REDASH_URL = 'https://app.redash.io/<your organization slug>'
DASHBOARD_SLUG = ''
redash = Redash(REDASH_URL, API_KEY)
dash = redash.fork_dashboard_and_queries(DASHBOARD_SLUG)
from datetime import datetime, timedelta
from collections import namedtuple
def get_frontend_vals():
ranges = calculate_ranges()
singles = calculate_singletons()
valkeys = [k for k in ranges.keys()] + [k for k in singles.keys()]
@susodapop
susodapop / quick_date_ranges.py
Last active December 2, 2020 23:34 — forked from arikfr/trigger_refresh.py
Trigger refresh of Redash queries based on query tag
from datetime import datetime, timedelta
from collections import namedtuple
def get_frontend_vals():
ranges = calculate_ranges()
singles = calculate_singletons()
valkeys = [k for k in ranges.keys()] + [k for k in singles.keys()]
{
"data": [
{
"cost": "$51.00",
"vendor_account_identifier": "9999-9999-9999",
"vendor_account_name": "acct1"
},
{
"cost": "$50.00",
"vendor_account_identifier": "9999-9999-9998",
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 22 columns, instead of 1. in line 4.
Year,Population1,"Violentcrime2","Violent crime rate ","Murder andnonnegligent manslaughter","Murder and nonnegligent manslaughter rate ","Rape(revised definition3)","Rape(revised definition) rate3","Rape(legacy definition4)","Rape(legacy definition) rate4",Robbery,"Robbery rate ","Aggravated assault","Aggravated assault rate ","Property crime","Property crime rate ",Burglary,"Burglary rate ","Larceny-theft","Larceny-theft rate ","Motor vehicle theft","Motor vehicle theft rate "
1997,"267,783,607","1,636,096",611.0,"18,208",6.8,,,"96,153",35.9,"498,534",186.2,"1,023,201",382.1,"11,558,475","4,316.3","2,460,526",918.8,"7,743,760","2,891.8","1,354,189",505.7
1998,"270,248,003","1,533,887",567.6,"16,974",6.3,,,"93,144",34.5,"447,186",165.5,"976,583",361.4,"10,951,827","4,052.5","2,332,735",863.2,"7,376,311","2,729.5","1,242,781",459.9
1999,"272,690,813","1,426,044",523.0,"15,522",5.7,,,"89,411",32.8,"409,371",150.1,"911,740",334.3,"10,208,334","3,743.6","2,100,739",770.4,"6,955,520","2,550.7","1,152,075",422.5
2
# This query runner is licensed under the BSD 2-Clause "Simplified" License
#
# Copyright (c) 2013-2021, Arik Fraimovich.
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.

Redash SSH Tunnel API

SaaS Redash traffic always arrives from our public IP address: 52.71.84.157. We recommend directly whitelisting this address through your firewall. Alternatively, you can set up an SSH tunnel using the API described below.

Overview

@susodapop
susodapop / redash_create_and_run_query.py
Last active April 5, 2021 22:37
Simple example of creating a query and fetching its results with app.redash.io
import json, time
from redash_toolbelt import Redash
URL = "https://app.redash.io/<org slug>"
KEY = "<your api key>"
DS_ID = 1234 # enter an integer data source ID here
client = Redash(URL, KEY)
# new queries need query text, a name, and a target data source id
"""
Author: Jesse Whitehouse
I used mkdocs to write static documentation for my Flask web application.
I write the docs in markdown and run `mkdocks build`, which outputs a full
static website into the /site directory.
In production, my webserver servers /site statically. But in development
mode I want to still see the docs for testing purposes. So I wrote this
View.