Skip to content

Instantly share code, notes, and snippets.

View tunnelWithAC's full-sized avatar

Conall Daly tunnelWithAC

  • Ireland
View GitHub Profile
import unittest
from bigquery_validator.bigquery_result import BigQueryResult
from bigquery_validator.bigquery_validator import BigQueryValidator
class BigqueryResultTest(unittest.TestCase):
bigquery_validator = BigQueryValidator(return_query_cost_as_dict=True)
def test_each_rows_contains_a_unique_user_id(self):
class BigqueryValidatorTest(unittest.TestCase):
bigquery_validator = BigQueryValidator()
def test_valid_query_returns_true(self):
query = "SELECT count(*) FROM `{{ params.project }}.samples.github_timeline`"
valid_sql, _ = self.bigquery_validator.validate_query(query)
self.assertTrue(valid_sql)
def test_valid_query_from_file_returns_true(self):
class BigQueryValidator:
"""Convert Jinja templated sql query to a regularly formatted query and validate it using BigQuery dry run.
Queries can be inputted as a string or by passing the file path to a sql file.
"""
def __init__(self,
use_query_cache=False):
self.bq_client = bigquery.Client()
self.params = self.load_params()
@tunnelWithAC
tunnelWithAC / fpl_fetch.py
Created January 6, 2020 11:52
Fetch Fantasy Premier League Data
#!/usr/bin/env python
# coding: utf-8
import os
import pandas as pd
import requests
from datetime import datetime
import json
def get(url):
library(RPostgreSQL)
dbConnection <- function(.) {
# create a connection
# loads the PostgreSQL driver
drv <- PostgreSQL()
all_cons <- dbListConnections(PostgreSQL())
# Cancel any existing connections
#* @get /add
add <- function(x, y){
as.numeric(x) + as.numeric(y)
}
rm(list=ls())
# package
library(RPostgreSQL)
library(dplyr)
library(ggplot2)
library(lubridate)
library(dbplyr)
library(jsonlite)
library(plotly)
@tunnelWithAC
tunnelWithAC / db_connection.R
Created August 8, 2019 13:35
Example connecting to PostgreSQL db in R
library(RPostgreSQL)
user = '<db_user>'
pw = '<db_pw>'
db_name='<db_name>'
db_host='<db_url>'
db_port=5432
dbConnection <- function(.) {
# create a connection
@tunnelWithAC
tunnelWithAC / authentication.R
Last active December 13, 2019 18:02
Function to authenticate token using R
tokenstatus <- function(token){
body <- list(token = token)
r <- POST(qm_url, body = body, encode = "json")
print(status_code(r))
return(status_code(r))
}