Skip to content

Instantly share code, notes, and snippets.

@erichannell
erichannell / testing_extract_api
Created February 27, 2015 10:59
benchmarking the Tableau Extract API
from random import randrange, random, choice
import dataextract as tde
import os
import string
import time
import csv
def write_to_extract(rows_to_write, name):
start = time.time()
@erichannell
erichannell / getting_twitter
Last active August 12, 2016 20:54
Grabbing things from Twitter as they fly by.
from TwitterSearch import *
import csv
def get_tweets(query, max = 2000):
# takes a search term (query) and a max number of tweets to find
# gets content from twitter and writes it to a csv bearing the name of your query
i = 0
search = query
{"nbformat_minor": 0, "cells": [{"execution_count": null, "cell_type": "code", "source": "print \"Hello, world!\" #ohai! this is a comment", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "name = \"Eric\" # creating a variable\nprint \"Hello\" + \" \" + name # adding strings", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "your_name = raw_input(\"Who are you? \")\nprint \"Hello\", your_name # , adds spaces", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "print your_name.lower() # string method\nprint your_name.upper()", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "i = 0\nprint i\ni = i + 1 # i += 1\nprint i", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We are working with Comma-separated value (CSV) files, so we'll need that library."
]
},
{
from textblob import Word
import re
def parse(text):
pattern = '''Synset\(\'(.*)\.n'''
return re.findall(pattern,text)[0]
def classify(word):
try:
word = Word(word)
@erichannell
erichannell / TDE_basics
Created October 13, 2015 18:05
Getting started with the Tableau Data Extract API
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Importing the **Extract API**"
]
},
{
@erichannell
erichannell / bicing
Last active May 4, 2017 15:15
Bikes in Barcelona
import pybikes
import csv
bike_system = "bicing"
bicing = pybikes.get(bike_system)
print bicing.meta
bicing.update()
@erichannell
erichannell / migrate.py
Created July 12, 2017 19:28
migrate users between servers
# -*- coding: utf-8 -*-
import tableauserverclient as TSC
# migrate from
site = ""
user = ""
pwd = ""
tableau_auth = TSC.TableauAuth(user, pwd, site_id=site)
server = TSC.Server('https://dub01.online.tableau.com')
@erichannell
erichannell / google maps converter
Created April 25, 2018 21:25
convert data from takeout.google.com from json to csv format
import pandas as pd
df_gps = pd.read_json('input.json')
# parse lat, lon, and timestamp from the dict inside the locations column
df_gps['lat'] = df_gps['locations'].map(lambda x: x['latitudeE7'])
df_gps['lon'] = df_gps['locations'].map(lambda x: x['longitudeE7'])
df_gps['timestamp_ms'] = df_gps['locations'].map(lambda x: x['timestampMs'])
# convert lat/lon to decimalized degrees and the timestamp to date-time
@erichannell
erichannell / google maps reverse-geocoder
Created April 25, 2018 21:26
convert lat and lon data from takeout.google.com into addresses
import reverse_geocoder as rg
import csv
with open("output.csv", 'w') as outf:
writer = csv.writer(outf)
writer.writerow(['index', 'lat', 'lon', 'datetime', 'country', 'location', 'area1', 'area2''])
with open("input.csv", 'r') as inf:
reader = csv.reader(inf)
reader.next()