Skip to content

Instantly share code, notes, and snippets.

View cclauss's full-sized avatar

Christian Clauss cclauss

View GitHub Profile
@cclauss
cclauss / earthQuakesSimple.py
Last active December 26, 2015 15:49
earthQuakes - A starter experiment with Socrata Open Data
import json, requests
minMagnitude = str(5)
theURL = 'https://soda.demo.socrata.com/resource/earthquakes.json?%24where=magnitude%20%3E%20' + minMagnitude
fmt = '{datetime} {earthquake_id} {version} {magnitude} {depth:>6} {location[latitude]:>8} {location[longitude]:>8} {region}'
for theQuake in json.loads(requests.get(theURL).text):
print(fmt.format(**theQuake))
print('=' * 75)
@cclauss
cclauss / earthQuakes.py
Last active December 26, 2015 16:19
earthQuakes - A starter experiment with Socrata Open Data
#!/usr/bin/env python
import json, requests, pprint
minMagnitude = 5.5
rootURL = 'https://soda.demo.socrata.com/resource/'
theURL = rootURL + 'earthquakes.json?$where=magnitude>' + str(minMagnitude)
fmt = '{datetime} {earthquake_id} {version} {magnitude} {depth:>6} {location[latitude]:>8} {location[longitude]:>8} {region}'
def soda2FieldDictFromHeaders(inRequestsHeader):
@cclauss
cclauss / austinDataset.py
Last active December 27, 2015 20:49
Socrata Open Data datasets are cached locally and printed out. Datasets published by City of Austin @ http://data.austin.gov
#!/usr/bin/env python
"""
Socrata Open Data datasets are cached locally and printed out.
Datasets published by City of Austin @ http://data.AustinTexas.gov
"""
import collections, contextlib, datetime, json, os.path, time
import urllib2
@cclauss
cclauss / austinWaterQuality.py
Created November 10, 2013 17:58
austinWaterQuality
#!/usr/bin/env python
"""
Socrata Open Data datasets are cached locally and printed out.
Datasets published by City of Austin @ http://data.AustinTexas.gov
"""
import collections, contextlib, datetime, json, os.path, time
import urllib2
@cclauss
cclauss / getColor.py
Last active August 8, 2023 14:43
Creates a dict of 752 Pythonista scene.Colors from the tkinter color palette. This allow you to get colors like: 'light goldenrod yellow', 'light steel blue', 'SlateGray4', 'etc. I would recommend using this code to find the colors that work for your app and then hardcoding them into you app. Loading all 752 colors every time your app runs will …
import bs4, collections, console, requests, scene
tkColorDict = collections.OrderedDict() # key = tkinter color name
def loadTkColorDict(): # will automaticly be called by getColor() if needed
tkColorURL = 'http://www.tcl.tk/man/tcl8.6/TkCmd/colors.htm'
print('Loading tkinter colors from: ' + tkColorURL)
tkColorSoup = bs4.BeautifulSoup(requests.get(tkColorURL).text).tbody
print('Soup is ready. Creating color table...')
for tableRow in tkColorSoup.find_all('tr'):
@cclauss
cclauss / elapsedTime.py
Last active November 22, 2019 22:30
Useful for measuring elapsed time on computing, i/o, and user tasks.
# an improved version at https://github.com/cclauss/Ten-lines-or-less/blob/master/elapsed_time.py
import math, time
def elapsedTime(start_time):
dt = time.time() - start_time
minutes = dt / 60
seconds = dt % 60
centiseconds = math.modf(dt)[0] * 100
return '%02d:%02d.%02d' % (minutes, seconds, centiseconds)
@cclauss
cclauss / recent_tweets.py
Last active October 30, 2017 07:42
Given a Twitter application access_token and a Twitter screen_name... print out that user's most recent Tweets using the Twitter v1.1 REST API.
import json, requests, sys #, pprint
'''
https://github.com/taherh/twitter_application_auth/blob/master/get_bearer_token.py
Use get_bearer_token.py (works on Pythonista) to get your Twitter access_token.
> You will need to create a new application on https://dev.twitter.com
> Enter below the Twitter access_token you get from running get_bearer_token.py
'''
@cclauss
cclauss / get_street_address.py
Last active January 3, 2016 06:39
Use Pythonista's Location module to print the current street address
import location, webbrowser #, time
def getLocation():
location.start_updates()
# time.sleep(1)
currLoc = location.get_location()
location.stop_updates() # stop GPS hardware ASAP to save battery
return currLoc
def getStreetAddress(loc = getLocation()):
@cclauss
cclauss / KeyboardHack.py
Last active January 3, 2016 07:09
KeyboardHack -- Just a proof of concept to prove that an on screen keyboard could be created in a Pythonista scene.Scene. Four keyboards are defined but only the first is implemented. Shift key not implemented. No number keys. Hard coded to iPad screen resolution, etc. Someone should make it an open source project on GitHub and curate changes (p…
# -*- coding: utf-8 -*-
import scene
keyboard_layouts = (
'''
q w e r t y u i o p del
a s d f g h j k l return
z x c v b n m , . shift
.?123 space .?123
@cclauss
cclauss / chicago_datasets.py
Last active January 4, 2016 21:09
Socrata Open Data datasets from the City of Chicago can be selected, cached locally, and printed out.
Moved to GitHub repo: https://github.com/cclauss/Open_Data