Skip to content

Instantly share code, notes, and snippets.

Christian Clauss cclauss

Block or report user

Report or block cclauss

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View read_and_write_ui_text.py
import ui
filename = 'name.txt'
def read_username(filename=filename):
username = None
try:
with open(filename) as in_file:
for line in in_file.readlines():
username = line.strip() or username
View CustomView.py
# http://omz-forums.appspot.com/pythonista/post/5808662551461888
# change the draw() method below to draw your plot
# using the ui.Path drawing commands documented at
# http://omz-software.com/pythonista/docs/ios/ui.html#path
import ui
class PlotView(ui.View):
def __init__(self, parent = None):
self.frame = (0, 0, 255, 255)
@cclauss
cclauss / watch_pythonista_forum.py
Last active Aug 29, 2015
Learning how to use feedparser... recent_entries() will print out info on all posts to the Pythonista forum in the past 24 hours. watch_feed() will print out info on the last post to the Pythonista forum. Sleeps for 15 minutes then check to see if there is a newer post. If so, prints out info on it and opens its URL in the webbrowser. Repeat.
View watch_pythonista_forum.py
#!/usr/bin/env python
'''
recent_entries() will print out info on all posts to the Pythonista forum in the past 24 hours.
watch_feed() will print out info on the last post to the Pythonista forum.
Sleeps for 15 minutes then check to see if there is a newer post.
If so, prints out info on it and opens its URL in the webbrowser. Repeat.
'''
@cclauss
cclauss / diagonal_line.py
Last active Jan 4, 2016
Use PIL to draw an image of a diagonal line and then make a Pythonista scene.Layer to display the image.
View diagonal_line.py
import Image, ImageDraw, scene
def diagonalLineImage(inLength = 200, inColors = ('blue', 'ivory')):
imageLength = inLength + 100 # the image can be larger than what you draw
theImage = Image.new('RGBA', (imageLength, imageLength), inColors[1])
draw = ImageDraw.Draw(theImage)
draw.line((0, 0, inLength, inLength), fill = inColors[0])
del draw
return theImage
@cclauss
cclauss / chicago_datasets.py
Last active Jan 4, 2016
Socrata Open Data datasets from the City of Chicago can be selected, cached locally, and printed out.
View chicago_datasets.py
Moved to GitHub repo: https://github.com/cclauss/Open_Data
@cclauss
cclauss / KeyboardHack.py
Last active Jan 3, 2016
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…
View KeyboardHack.py
# -*- 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 / get_street_address.py
Last active Jan 3, 2016
Use Pythonista's Location module to print the current street address
View get_street_address.py
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 / recent_tweets.py
Last active Oct 30, 2017
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.
View recent_tweets.py
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 / elapsedTime.py
Last active Jan 2, 2016
Useful for measuring elapsed time on computing, i/o, and user tasks.
View elapsedTime.py
# 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 / getColor.py
Last active Apr 11, 2018
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 …
View getColor.py
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'):
You can’t perform that action at this time.