Skip to content

Instantly share code, notes, and snippets.

View cclauss's full-sized avatar

Christian Clauss cclauss

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / backgroundSwap.py
Last active December 26, 2015 09:49
Create three background images in scene.setup() then in scene.draw() use the x coordinate of the user's drag location to determine which background image to display
'''
create three background images in scene.setup() then in
scene.draw() use the x coordinate of the user's drag
location to determine which background image to display
'''
import scene
from PIL import Image, ImageDraw, ImageFont
theMessage = 'Drag the grey circle left and right to switch between the background images.'
@cclauss
cclauss / beazleyCodeDownload.py
Last active December 24, 2015 20:29
David Beazley is one of the best trainers on Python topics. This script downloads several code bases from David's website (http://www.dabeaz.com) to a local directory.
# beazleyCodeDownload.py
#
# copy source code from http://www.dabeaz.com
# into local directory David_Beazley
import bs4, os, requests
codeBases = ('coroutines', 'generators', 'pydata',
'python3io', 'usenix2009/concurrent')
baseURLFmt = 'http://www.dabeaz.com/{}/'
@cclauss
cclauss / listApp.py
Last active December 23, 2015 15:39
Simple app that read in a list from a file and allows the user add to, remove from, and view the list. viewList() is fairly redundant and could be removed.
# Current version at https://gist.github.com/cclauss/6656495
import console
addPrompt = """Item to be added to the list?
or [M] to return to the main menu:"""
removePrompt = """Item to be removed from the list?
or [M] to return to the main menu:"""
def writeListToFile(inFileName, inList):
@cclauss
cclauss / soupFromURL.py
Last active December 23, 2015 14:29
Create a BeautifulSoup by reading in a webpage.
#!/usr/bin/env python
# create a BeautifulSoup by reading in a webpage
# Current varsion at https://gist.github.com/cclauss/6648735
# usage:
# from soupFromURL import soupFromURL
# theSoup = soupFromURL('http://www.python.org')
import bs4
useRequests = False # "Python HTTP: When in doubt, or when
try: # not in doubt, use Requests. Beautiful,
@cclauss
cclauss / textFullScreen.py
Last active December 23, 2015 13:29
Display the clipboard text at full screen resolution... Show a message to your friends... Show the taxi driver your desired address... Have fun.
# Display the current clipboard text in full screen mode
import clipboard, console, scene
clipText = clipboard.get()
if not clipText:
clipText = """Hang up your cellphone and drive your car!!!"""
zclipText = """Please take me home..."""
class MyScene(scene.Scene):
def setup(self):
(imageName, imageSize) = self.getImageNameAndSize()