www.wallcity.org | Zack Smith

Simple Little Warranty Parser


if anyone is interested I have a python prototype of @glarriza’s warranty ruby script that spits all keys out as a dict http://gist.github.com/1357622

I would have used his but I am writing something in python that needed this directly and I did not want to call an external command.

-Z

Fun with Schlage Link & Python

So I have a Schlage LiNK Wireless Keypad Entry Lever Lock Starter Kit System*. I am trying to take the whole thing apart call by call but until I am ready to post that I wanted a quick easy way to interface with the system in a semi cool way. Basically I wanted anyone who types the code in the door to hear “Welcome home” $First $last. So I decided that I could at least in the time being before I figure out Zwaves command classes, just check my email (Special notification Inbox) and parse the name from there. This works pretty well, I mark it as read so I don’t see it the second time around and then set it on a launchd job. Though really you could use this to run any command based on a special subject line, so its a quick easy example of something sorta cool. I have not had a chance to make a youtube video of it, but I will when its a little more sexy ( and I get the arduino hooked up to the metal skull servos, yes I am totally not joking that I have a metal skull that I am teaching to speak).

Grab the script here

#!/usr/bin/python
import imaplib
import string, random
import StringIO, rfc822
import email, sys
import os
from datetime import datetime, timedelta
import plistlib
SERVER = "mail.wallcity.org"

USER  = "home"
PASSWORD = "mypassword"

lastcheck = datetime.now ()
print lastcheck
# connect to server
server = imaplib.IMAP4_SSL(SERVER)

# login
server.login(USER, PASSWORD)
server.select()

#typ, data = server.search(None, 'ALL')
typ, data = server.search(None, '(FROM "alerts@schlagelink.com")','UNSEEN')
for num in data[0].split():
resp, data = server.fetch(num, "(RFC822)")
text = data[0][1]
file = StringIO.StringIO(text)
message = rfc822.Message(file)
subject = message['Subject']
if subject == 'Schlage LiNK Alert':
#body = server.fetch(num,"(UID BODY[TEXT])")
body = server.fetch(num,"(BODY[TEXT])")
imaptolken = body[1]
bodytolken = imaptolken[0]
textbody = bodytolken[1]
words = textbody.split()
first_name = words[8]
print words
last_name = words[9]
cmd = '/usr/bin/say' + ' ' + 'Welcome home ' + first_name + ' ' + last_name
# Turn the volume up
set_volume_command='/usr/bin/osascript -e \'set volume 10\''
os.system(set_volume_command)
os.system(cmd)
server.logout()

* Please note my Amazon Link

Here is an example of what these emails look like:

Auto Server Setup [ Python ]

My work is having me build some auto server setup stuff in python, here is the basic config dictionary for a single ethernet device:

excuse the weird formatting here, I am still working with wordpress to get this kind of stuff right.

config = dict(
adminUser = dict(
fullName = "<span style="color: #ff6060;">admin</span>",                   <span style="color: #8080ff;"># string</span>
<!--more-->
password = "<span style="color: #ff6060;">password</span>",                <span style="color: #8080ff;"># string</span>
shortName = "<span style="color: #ff6060;">admin</span>",          <span style="color: #8080ff;"># string</span>
),
bindToExternalDirectory = False,<span style="color: #8080ff;"># bool</span>
bonjourName = "<span style="color: #ff6060;">www.local</span>",             <span style="color: #8080ff;"># string</span>
computerName = "<span style="color: #ff6060;">Web Server</span>",   <span style="color: #8080ff;"># string</span>
configureSACLs = False,                 <span style="color: #8080ff;"># bool</span>
enableRemoteManagement = True,  <span style="color: #8080ff;"># bool</span>
enableSSH = True,                               <span style="color: #8080ff;"># bool</span>
hideRemoteChoosePathPage = True,<span style="color: #8080ff;"># bool</span>
hostName = "<span style="color: #ff6060;">www.wallcity.org</span>", <span style="color: #8080ff;"># string</span></code>

<code><span style="color: #8080ff;"># Begin Keyboard Dictionary</span>
keyboard = dict(
BundleID = "<span style="color: #ff6060;">com.apple.keyboardlayout.all</span>",    <span style="color: #8080ff;"># string</span>
LocalizedName = "<span style="color: #ff6060;">U.S.</span>",                                               <span style="color: #8080ff;"># string</span>
ResID = 0, <span style="color: #8080ff;"># int</span>
ResName = "<span style="color: #ff6060;">U.S.</span>",                                                     <span style="color: #8080ff;"># string</span>
ScriptID = 0,                                                           <span style="color: #8080ff;"># int</span>
preferred = True,                                                       <span style="color: #8080ff;"># bool</span>
preferredIndex = 1,                                                     <span style="color: #8080ff;"># int</span>
sourceID = "<span style="color: #ff6060;">com.apple.keylayout.US</span>",          <span style="color: #8080ff;"># string</span>
), <span style="color: #8080ff;"># End Keyboard Dictionary</span></code>

<code> </code>

<code><span style="color: #8080ff;"># Begin LDAP Master Dictionary</span>
ldapMaster = dict(
adminUser = dict(
UID = "<span style="color: #ff6060;">1000</span>",                                                        <span style="color: #8080ff;"># string</span>
fullName = "<span style="color: #ff6060;">Directory Administrator</span>",        <span style="color: #8080ff;"># string</span>
shortName = "<span style="color: #ff6060;">diradmin</span>",                                      <span style="color: #8080ff;"># string</span>
),
configure = False,                                                      <span style="color: #8080ff;"># bool</span>
), <span style="color: #8080ff;"># End LDAP Master Dictionary</span></code>

<code><span style="color: #8080ff;"># Begin License Dictionary</span>
license = dict(                 <span style="color: #8080ff;"># dict</span>
organization = "<span style="color: #ff6060;">Apple Developer Connection</span>",                          <span style="color: #8080ff;"># string</span>
registeredTo = "<span style="color: #ff6060;">Developer Seeding</span>", <span style="color: #8080ff;"># string </span>
serialNumber = "<span style="color: #ff6060;">XSVR-106-000-N-XXX-XXX-XXX-XXX-XXX-XXX-X</span>",    <span style="color: #8080ff;"># string</span>
), <span style="color: #8080ff;"># End License Dictionary</span></code>

<code><span style="color: #8080ff;"># Begin Minimal DNS</span>
minimalDNS = dict(
configure = False, <span style="color: #8080ff;"># bool</span>
), <span style="color: #8080ff;"># End Minimal DNS</span></code>

<code><span style="color: #8080ff;"># Begin Network Services</span>
networkServices = [             <span style="color: #8080ff;"># array</span>
dict(
activeLink = True, <span style="color: #8080ff;"># bool</span>
bsdName = "<span style="color: #ff6060;">en0</span>", <span style="color: #8080ff;"># string</span>
dns = dict( <span style="color: #8080ff;"># dict</span>
addressesFromUser = [ "<span style="color: #ff6060;">192.168.53.249</span>" ],  <span style="color: #8080ff;"># array</span>
searchDomainsFromUser = [ "<span style="color: #ff6060;">wallcity.org</span>" ],        <span style="color: #8080ff;"># array</span>
),
enabled = True, <span style="color: #8080ff;"># bool</span>
ipv4 = dict( <span style="color: #8080ff;"># dict</span>
address = "<span style="color: #ff6060;">192.168.53.165</span>",                               <span style="color: #8080ff;"># string</span>
configMethod = "<span style="color: #ff6060;">Manual</span>",                          <span style="color: #8080ff;"># string</span>
router = "<span style="color: #ff6060;">192.168.53.2</span>",                          <span style="color: #8080ff;"># string</span>
subnetMask = "<span style="color: #ff6060;">255.255.255.0</span>",                     <span style="color: #8080ff;"># string</span>
),
ipv6 = dict(), <span style="color: #8080ff;"># dict</span>
localizedName = "<span style="color: #ff6060;">Ethernet</span>",                                         <span style="color: #8080ff;"># string</span>
maximumMTU = 9000, <span style="color: #8080ff;"># int</span>
mediaConfigMethod = "<span style="color: #ff6060;">Automatic</span>",                            <span style="color: #8080ff;"># string</span>
mediaOptions = [], <span style="color: #8080ff;"># dict</span>
mediaSubType = "<span style="color: #ff6060;">autoselect</span>",                                        <span style="color: #8080ff;"># string</span>
minimumMTU = 72, <span style="color: #8080ff;"># int</span>
mtu = 1500, <span style="color: #8080ff;"># int</span>
type = "<span style="color: #ff6060;">Ethernet</span>", <span style="color: #8080ff;"># string</span>
userDefinedName = "<span style="color: #ff6060;">Ethernet</span>",                                       <span style="color: #8080ff;"># string</span>
),
], <span style="color: #8080ff;"># End Network Services</span></code>

<code> </code>

<code>ntpServer = "<span style="color: #ff6060;">time.apple.com</span>",                  <span style="color: #8080ff;"># string</span>
timeZoneCityID = 5746545,                               <span style="color: #8080ff;"># int</span>
timeZoneName = "<span style="color: #ff6060;">America/Los_Angeles</span>",  <span style="color: #8080ff;"># string</span>
)</code>