16 July 2012

No more skype4py, SkypeKit is here

App developers looking to leverage the Skype platform had a wonderful solution in Skype4Py, the open source python wrapper library. Skype4Py connected to the current Skype installation on the desktop enabling developers to make bots and applications.

Unfortunately, Skype4Py has not been in active development for quite sometime (the last checkin to the codebase was in 2009). At the time of this writing, Skype4Py was verified to be working on Windows 7, and is bound to work fine on OSX and *NIX but there is no saying how long it will continue to do so.

This leaves us with one alternative to continue developing applications and bots on the Skype platform, SkypeKit. In this post, we'll take a look at how get sign up for the skype developer program and also to download and use the skypekit for making a sample app to demonstrate the functionality.

Introduction:


Skypekit is, as their website says, a collection of software and APIs that allows internet-connected devices or applications to offer Skype voice and video calls. Skypekit is basically a headless Skype client that runs independently and without any user interface. Developer’s can make apps that will plug into Skypekit and make use of the intended text / audio / video functionality.

Getting in

While Skype4Py was free to download and use, Skype4Py will set you back 5$ each for the desktop and the embedded versions. Head to your projects page to join the Skype developer program by paying _US $5_.

There are 4 programs listed there

* Desktop API for Hardware
>This is for just the documentation and reference.
* SkypeKit for Desktop
>Members can read the documentation and also downlod the SDK, runtimes (OSX, *NIX and Windows)and keypairs and forum access.
* Desktop API for Software
>This is for just the documentation and reference.
* SkypeKit for Embedded
>Members can read the documentation and also downlod the SDK, runtimes (Embedded devices, android, iOS, etc.)and keypairs and forum access.

For this post, We will look at the Skype for Desktop program as we'll be concentrating on writing apps / bots using the Python language on OSX.

The SDK


Once you're done signing in, you need to download the SDK. You need to agree to the Skype Terms and conditions before the download starts.

The SDK is a multi-platform SDK that lets you develop apps for skype using C++, Java or Python as your language. The SDK also packs the API documentation _AND_ examples for these three languages.

The SDK downloads as a zipped file. Just fire up a terminal and extract the archive into a folder.

`$ tar -zxvf skypekit-sdk_sdk-4.2.1.97_1379776.tar.gz`

`$ cd skypekit-sdk_sdk-4.2.1.97_1379776`

Hunt through the folders to see what they contain… You will notice that the `bin` folder is virtually empty. It just has a bunch of `netlogger` executables. As of Skypekit SDK version 3.2, the runtime which was previously in the bin folder has been removed.

As mentioned previously, the documentation for each wrapper library is present in the `/interfaces/skype/{cpp_embedded|python|java}/documentation/index.html`.

The tutorial code for each of these wrapper libraries is also present in `/examples/{language}/tutorial` folder.

Moving on...

The Runtime


The Skype Runtime no longer exists in the bin folder. I just was informed this morning by Skype's Development Support team that in the latest release a generic runtime is included in the SDK download so you won't need to generate one anymore.

The Runtime is the headless Skype instance that you use to connect your app with the skype network. This application apes most of the desktop app functionality but since it does not have a User Interface, developers are free to customize the look and feel of their application and interact with runtime using the language specific wrappers provided.

According to Skype, this runtime can be used by anyone in your organization's account.

The Keypairs


The keypairs are the last piece of the puzzle in the Skypekit tool before we head into the code. Each application registered on the skype developer page is bound to a unique key-pair of `Base64-encoded X.509 certificates` that authorize the application to interact with the skype services.

Obtaining a key pair is pretty straight forward:

* Head into your project page and click on the **Distribution key pair** link. Speficy a label and the CAPTCHA text.

* Click on **Request key pair** and save your certificate. You will get a `.pem` file to download and use in your application.

A Sample application


Now that we've done with the setup of our SDK and the skype runtime, lets go look at some of the examples provided…

The pem file


For the sake of simplicity in this sample, the first thing to do is to drop your key (the `.pem` file) into the `/examples/python/tutorial` folder.

Open up `keypair.py` in your favourite editor and change

`keyFileName = '';` to `keyFileName = '.pem';`

Startup the skypekit runtime by heading into the folder where you extracted the runtime.

`$ cd mac-x86-skypekit_4.2.1.870_1793622/bin/mac-x86/`

`$ ./mac-x86-skypekit`

Once the runtime kicks in, you'll see it print some messages like so:

SkypeRuntime Copyright (C) 2003-2012 Skype Technologies S.A.
SkypeRuntime Version: 4.2/mac-x86-skypekit_4.2.1.870_1793622
Proprietary and confidential, do not share this application.

and will continue to wait for programs to connect to it.

Open another terminal instance and head into the `/examples/python/tutorial` folder.

Lets start with a simple login script thats provided.

`$ python login.py `

This is what you're going to be seeing:

****************************************************************************
SkypeKit Python Wrapper Tutorial: Account Login
****************************************************************************
Logging in with
Login sequence: CONNECTING_TO_P2P
Login sequence: CONNECTING_TO_SERVER
Login sequence: LOGGING_IN
Login sequence: INITIALIZING
Login sequence: LOGGED_IN
You should now be able to see this account as online from other Skype instances.
Press ENTER to log out

You will also notice that the runtime has emitted some messages during the same process indicating that there has been communication.

In the same manner, to place a call to another skype user, the example code provided does so:

`$ python call.py `

And there comes to end the post on SkypeKit.

For further documentation and support, head to the forums on the Skype developer page.

The API reference for using python on skypekit is available here.

Have fun making great apps!!!

And thanks to

Super affordable standing workstation built from IKEA parts - less than $50

I've been reading a lot about the health and productivity benefits of working at a standing desk for months now and today finally decided to head down to IKEA and grab the parts to build one. The inspiration came from an article about how to build a $22 IKEA standing desk. This seemed the most sensible way to go about getting what I wanted.



From IKEA
  • (2) Lack side tables - $19.98
  • (1) Ekby Viktor 11" shelf - $5.99
  • (2) Ekby Valter shelf brackets - $8

From Home Depot
  • (4) 5/16" x 3" hex bolts - $1.24
  • (8) 1/4" washers - $0.88
  • (4) 1/4" hex nuts - $0.24

The only difference from the article I read was that I used the bolts to attach the brackets since the table legs are hollow and I didn't attach the shelf to the brackets. Total was a touch over $60 with tax and gas to get there and back ($40 if you live close to an IKEA). I love this setup and the only thing I'm gonna change is to drop the bracket down about an inch and a half somehow to get the keyboard surface at a more comfortable level. I also found that I needed to put something about 1/4" thick under my keyboard to get it to be comfortable to type on; having the keyboard at an angle was hard on my wrists.

26 May 2012

Find out where files were downloaded from with Python and xattr

Ever forget where you downloaded a file from? On OS X you can use HFS extended attributes to figure it out. Linux and Windows also support extended attributes but I don't know much about their implementations.

To find out where we downloaded a particular file from we can execute this command:
% xattr -p com.apple.metadata:kMDItemWhereFroms

The results will look like:
nya:~/Downloads % xattr -p com.apple.metadata:kMDItemWhereFroms CentOS-5.8-i386-netinstall.iso
62 70 6C 69 73 74 30 30 A2 01 02 5F 10 4C 68 74
74 70 3A 2F 2F 79 75 6D 2E 73 69 6E 67 6C 65 68
6F 70 2E 63 6F 6D 2F 43 65 6E 74 4F 53 2F 35 2E
38 2F 69 73 6F 73 2F 69 33 38 36 2F 43 65 6E 74
4F 53 2D 35 2E 38 2D 69 33 38 36 2D 6E 65 74 69
6E 73 74 61 6C 6C 2E 69 73 6F 5F 10 2E 68 74 74
70 3A 2F 2F 79 75 6D 2E 73 69 6E 67 6C 65 68 6F
70 2E 63 6F 6D 2F 43 65 6E 74 4F 53 2F 35 2E 38
2F 69 73 6F 73 2F 69 33 38 36 2F 08 0B 5A 00 00
00 00 00 00 01 01 00 00 00 00 00 00 00 03 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 8B

Attribute values are usually returned by the -p flag as strings; however, when the value contains nulls the information will be returned in hex instead. This info isn't terribly useful so let's hop over into the Python REPL and take a look.

>>> import xattr
>>> xattr.getxattr('CentOS-5.8-i386-netinstall.iso', 'com.apple.metadata:kMDItemWhereFroms')
'bplist00\xa2\x01\x02_\x10Lhttp://yum.singlehop.com/CentOS/5.8/isos/i386/CentOS-5.8-i386-netinstall.iso_\x10.http://yum.singlehop.com/CentOS/5.8/isos/i386/\x08\x0bZ\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8b'

27 April 2012

OS X Lion upgrade awesome but broke my python dev environment

OS X Lion brought some substantial improvements but required pretty much my entire development environment to be rebuilt.  Python got upgraded to 2.7 and required all of my modules to be reinstalled.  Apache wouldn't start because mod_fastcgi isn't provided for Lion.  XCode had to have the new version reinstalled and then the command line tools package installed to get gcc back.  I wish I would have known this before upgrading so that I was prepared.  It's well worth the upgrade and the inconveniences that come with it but just beware that your system will definitely require some additional setup after upgrading.

23 April 2012

Google Chrome Performance Issues on OS X Snow Leopard

Lately I've been using Opera because Chrome had gotten ungodly slow leaving me scratching my head since it used to be blazing fast.  Developing with a sluggish browser was a real pain in the ass but I finally got it back up to it's old speeds again; apparently when you run it in the developer mode used for extension development it's slow as hell.  I disabled some extensions that I no longer use and disabled developer mode and it's back to being awesome again.

16 February 2012

Screw Skype4Py - Pony Up $5 and Get The SkypeKit for Python

My Skype4py post gets a lot of views even though it's minimally useful.  Skype4Py seems to have problems with 64-bit Python and really hasn't been actively maintained.

You're really better off spending the $5 to gain access to the Python SkypeKit SDK if you want to develop apps using Skype.  Read the API reference and the examples of how to place calls, send messages, etc and then register for an account ($5 one-time fee).

SkypeKit Python SDK reference
Register for Skype Developer Program

07 February 2012

NEW - Checkout the Activestate Python Cookbook Recipes in my sidebar

I recently added a widget with recipes from Activestate's Python Cookbook site that I find really helpful.  It's one of the first places that I go when I need to do something that I've never done before (after Github of course).  Check them out as they're updated regularly (pulls from their RSS feed).

24 December 2011

Hipchat: The IM App That I've Been Waiting For ...

I've been waiting for years to have an IM app that I could use with the other developers on my team(s) to communicate about projects and integrate updates from source control and bug tracking.  I'm not too keen on using proprietary apps or subscription-based apps in most situations but Hipchat has far exceeded my expectations in the few weeks that I've been using it.

Besides having a slick interface and the features that I need it uses XMPP/Jabber and has both desktop and web versions of the app (written using Adobe Air).  One of the features that I really like is when someone uses your username with an @ symbol preceding it and you're offline you'll receive an email with the message.

We've been using this primarily to have a record of our debates, conversations, and to have an ongoing record of important tidbits, URLs, git commits, etc.  It also has been helpful for having a log of our planning discussions which we can use when bringing new developers onboard to let them sort of get into our heads and see how the app developed to its current state.

Go checkout Hipchat and signup for their free 30-day trial.

17 December 2011

Making The New Amazon Product API Easy to Work With

I'm working on a new startup idea that I think will really rock the niche it's in and have been using the Amazon Product API a bunch.  They updated the API recently and now require you to send your associate id along with the query.

I've tried several xml parsing libraries and several Amazon libraries and have decided that the current combination of BeautifulSoup and bottlenose are what I enjoy working with the most.  I've been able to bang out tools for myself using this combo very quickly and have actually had fun building each one of them for a change.

import bottlenose
from BeautifulSoup import BeautifulSoup

# Replace these values with your correct info
AWS_KEY = 'key_goes_here'
SECRET_KEY = 'secret_goes_here'
ASSOCIATE_ID = 'your_associate_id_goes_here'

# Create a bottlenose object and initialize with our credentials
amazon = bottlenose.Amazon(AWS_KEY, SECRET_KEY)

# Query Amazon's Product API to perform an item lookup via the ASIN, returns the large response # group containing a ton of info, note that we must send the associate id now
response = amazon.ItemLookup(ItemId="B0018AFK38", ResponseGroup="Large", AssociateTag=ASSOCIATE_ID)

# Create a BS object from the XML response
soup = BeautifulSoup(response)

# A sample of the data that can be retrieved
print soup.find('itemid').string
print soup.find('formattedprice').string
print soup.find('detailpageurl').string
print soup.find('sku').string
print soup.find('content').string
print soup.find('title').string
print soup.find('department').string
print soup.find('smallimage').url.string
print soup.find('mediumimage').url.string
print soup.find('largeimage').url.string

30 November 2011

If anyone cares what I'm up to ...

I've been using Python off and on for the past few months and really haven't had much time for blogging and such.  I'm about midway through a project that's basically a link scanner that handles large volumes of links asynch using beanstalkd and the beanstalkc python library.  Beanstalk is a great fit for basic asynch queueing needs.

Today I also started working in django again (just modifying an existing site for someone).  It's nice to come back to django after a few months tearing my hair out in RoR land but still can't touch microframeworks for most of what I do.

28 November 2011

The Perfect Solution for Programmers on the Go - Verizon Wireless Mifi LTE 4G Hotspot

I've been fast approaching burnout and had to do something right away to stave it off; freelance programming and consulting is my main source of income.  My solution has been to start working outside in parks.  Fresh air and lots of sunlight seems to help me beat the office blues and remain productive.

The key to me being able to work outside and on the go has been my mifi mobile LTE hotspotthat I bought at the Verizon store in the Metro Center mall here in Phoenix.  $50 is a small price to pay for the ultimate in mobility and speed.

I've been able to get speeds comparable to my 15mbps DSL service I have at home in most areas.  The battery life is pretty good (about 4.5 hours in actual use).  I also was able to get a $50 mail-in rebate that basically got me the device for free.  Monthly service for 5gb of data is only $50.

This would be a great addition to your toolbox if you're trying to live the 4HWW lifestyle or just want some extra freedom in where/when you can work on your code.  I would also buy this as a gift for any of my techie friends; they'd love having one I'm sure!

21 September 2011

My Five Favorite Python Library Finds on Github This Week

  1. https://github.com/edsu/microdata - (python library for extracting html5 microdata)

    I've been working with HTML5 a lot especially when dealing with Wordpress blogs and was interested in what's available for HTML5 in Python.

  2. https://github.com/pneff/wsgiservice - (Python WSGI framework to create REST web services)

    Over the last few weeks I've had the (mis)fortune of having to develop a public API for a company using PHP and the Slim framework.  Slim isn't bad but PHP is getting long in the teeth and it's just not nearly as fun to develop in as Python and Ruby.  wsgiservice looks like a good choice (from out of many) for building RESTful APIs.

  3. https://github.com/mcfunley/etsy-python - (Python access to the Etsy API)

    Esty's awesome.  Python's awesome.  Putting the two together and making a cool site or tool of some sort seems like a good idea and this module can certainly help.

  4. https://github.com/liamks/pyitunes - (Python Itunes Library parser)

    iTunes is hated my many but I love it and this library (although not maintained as well as it could be) allows access to my music collection.  I use it for fixing meta tags on my audio files.

  5. https://github.com/solex/python-odesk - (Python bindings for oDesk API )

    I work full-time on oDesk these days as a developer and am building some custom tools to make finding new jobs easier and to make visualizing some of my key statistics easier.  For instance, oDesk doesn't give you an earnings to date readout and I would like that.  I would also like to be able to filter jobs out so that I'm never shown jobs below my minimum price point.

10 September 2011

Working with YouTube API from Python - A Primer

Grabbing data from YouTube with Python is really simple and you can build a ton of apps using this information. It's nothing more than making an HTTP GET request to the proper gdata URL. Then we just take the response in JSON format, decode it, and then can work with it like any other Python dictionary.
#!/usr/bin/env python
import requests
import json

resp = requests.get("http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=jsonc")
if(resp.status_code == 200):
	data = json.loads(resp.content)
	for item in data['data']['items']:
		print "Video Title: %s" % (item['title'])
		print "Video Category: %s" % (item['category'])
		print "Video ID: %s" % (item['id'])
		print "Video Rating: %f" % (item['rating'])
		print "Embed URL: %s" % (item['player']['default'])
		print
else:
	print "There was a problem retrieving the data"
The results look something like this:
Video Title: Minecraft - Dwarf Hole (Diggy Diggy Hole) Fan Song and Animation
Video Category: Shows
Video ID: fR7EAdPUqvQ
Video Rating: 4.862668
Embed URL: http://www.youtube.com/watch?v=fR7EAdPUqvQ&feature=youtube_gdata_player

Video Title: FAT KID FALLS
Video Category: Entertainment
Video ID: dCd8ojAdUbA
Video Rating: 4.671462
Embed URL: http://www.youtube.com/watch?v=dCd8ojAdUbA&feature=youtube_gdata_player

Video Title: Incredible Shade Illusion!
Video Category: Tech
Video ID: z9Sen1HTu5o
Video Rating: 4.793279
Embed URL: http://www.youtube.com/watch?v=z9Sen1HTu5o&feature=youtube_gdata_player

Video Title: David Guetta feat. Sia - Titanium
Video Category: Music
Video ID: Mb6mS6Yj_UA
Video Rating: 4.845408
Embed URL: http://www.youtube.com/watch?v=Mb6mS6Yj_UA&feature=youtube_gdata_player

Video Title: 50 Cal Machine Gun VS. 250 Watermelons
Video Category: Entertainment
Video ID: XyoAP10uKTk
Video Rating: 4.921269
Embed URL: http://www.youtube.com/watch?v=XyoAP10uKTk&feature=youtube_gdata_player

[ ... cut for space ... ]

Requests - Easiest, Most Enjoyable Way to Make HTTP Requests in Python

I've been working for the last week designing and implementing an API for in-house use at a company in Georgia. The API is being built with PHP5 and a micro-framework called Slim. I would have preferred to build it in web.py but because ultimately this decision was left to the owners who are responsible for maintaining it's being done in PHP (a language that they're familiar with).

One of the sore spots has been testing the API as we put it together. In the end it will be used by the developers that they hired to write mobile phone applications. I settled on using a Python script for testing the API but quickly tired of writing the HTTP request code using httplib2 and urllib2. I set out for a better HTTP Request library and quickly found Requests; an elegant and dead-simple library that makes writing code to work with HTTP Requests actually enjoyable.

>>> import requests
>>> r = requests.get("http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=jsonc")
>>> r.status_code
200
>>> print r.content
{"apiVersion":"2.1","data":{"updated":"2011-09-09T19:54:17.000-07:00","totalItems":99,"startIndex":1,"itemsPerPage":25,"items":[{"id":"X9YMU0WeBwU","uploaded":"2011-08-17T00:52:31.000Z","updated":"2011-09-11T01:09:51.000Z","uploader":"LadyGagaVEVO","category":"Music","title":"Lady Gaga - Yoü And I (Official Video)","description":"Music video by Lady Gaga performing Yoü And I (Official Video). Lady Gaga's \"Yoü And I\" video received 1,054,214 video views on YouTube prior to the official VEVO video release.  © 2011 Interscope Records","tags":["You","and","new","video","song","official","Laurieann","Gibson","haus","of","gaga","Mother","Monster"],"thumbnail":{"sqDefault":"http://i.ytimg.com/vi/X9YMU0WeBwU/default.jpg","hqDefault

[ ... cut for space ... ]
I think I will also go back through and rewrite a bunch of my YQL code to use Requests instead for it's HTTP request needs. This should be a standard part of your Python toolbox for sure.

21 July 2011

Skype4Py Mac Problems - Attach() Causes Segmentation Fault

I was looking forward to covering Skype4py some more today but when I fired up TextMate to do some coding I noticed that some of my existing scripts no longer worked with the new version of Skype that I have (5.1.0.968).

My current setup is:
  • OS X 10.6.8 (Snow Leopard)
  • Python 2.6.1
  • Skype4Py 1.0.32.0
  • Skype 5.1.0.968

After doing a few searches I noticed that a bunch of other people are having issues on their Macs with Skype4Py as well; with most encountering segmentation faults when they try to execute the Attach() method on the Skype4Py.Skype() instance. It's unclear what exactly is causing the seg fault but all indicators point at the library not being updated to reflect changes that were made to Skype (probably after the reverse-engineered Skype protocol details hit the internet).

Quite simply here's what happens when you try a simple test script using Skype4Py:
# test.py
import Skype4Py

s = Skype4Py.Skype()
s.Attach()
nya:skype tzayad$ python test.py 
Segmentation fault

03 July 2011

Make Your Life as a PHP Developer Twice as Easy With phpsh

I know that this blog is supposed to be mainly about Python but this was just something that I felt needed to be shared regardless. Many of us Python programmers either programmed in PHP at one time or we still do on presently. I use a combination of Ruby, Python, and PHP in my daily work depending on what my clients existing codebase looks like and expect that many of you are no different.

One of the features that I love the most about Python is it's powerful REPL. I love that I can pop over into the console and start testing/fleshing out an idea on the spot. I love being able to test new libraries this way as well which saves me tons of time.

The developers at Facebook have brought PHP developers a powerful REPL now ala-Python to round out a solid toolbox that PHP developers already have. The project is called phpsh and is written in Python.

To give it a go, just clone their git repo to your machine and install the tool via setuptools.

$ git clone git://github.com/facebook/phpsh.git
$ cd phpsh
$ sudo python setup.py install
$ phpsh
Starting php
Install pcntl to enable forking on every command.
type 'h' or 'help' to see instructions & features
php>

Every PHP developer out there that's not aware of this tool is seriously wasting hours upon hours of their time with each project they complete without phpsh. Clone the git repo right now and start enjoying the benefits of an REPL like Python and Ruby developers have enjoyed for the longest time.

23 June 2011

How to Make Finding Freelance Development Jobs Way Easier

I get a lot of my freelance work from the Computer Gigs section of Craigslist for my local town (Phoenix) and others in the US. It's become tedious to check the sites each day and filter through the myriad of jobs that are local-only or that don't fit my criteria. So I imported all of the RSS feeds for the Computer Gigs section of each US city into my Google Reader account and started filtering away. This has made things way easier and efficient.

If you're like me and don't wanna spend time unnecessarily on setting this up today's your lucky day. After I imported the feeds, renamed them all to something more meaningful and place them into a folder aptly named "Craigslist Computer Gigs" I exported the feed list to an OPML file which I'm making available to the world. Import the file into your Google Reader or other RSS feed reader and you can be cruising the CPG section of all US cities in no time.

Download the subscription list

20 June 2011

Just Forked My First Project on Github

I've been wanting to contribute to some FOSS projects for quite some time now but never got around to doing it. I was looking to write a webservice today that would allow a C# application I had to request domain information from my webservice which uses the namecheap.com API.

I noticed a ruby library on github that allowed for the checking of domain availability and which looked like a good platform to start building my codebase on so I forked it and began adding functionality to it. A few hours later I setup git and pushed my first changes to my forked repo. Man it felt good!

Hopefully someone finds the additional Namecheap.com API calls that I'm implementing to be useful. You can find my fork of the namecheap library here.

19 June 2011

Claiming My Blog on Technorati

DZone and Reddit bring me decent amounts of traffic but I figured I should submit to Technorati as well.

DSPTC3UHYKGU