Theodore Baschak

BOFH. Open Source Guru. Founder/Operator of Hextet Systems, AS395089 and Network Architect for Daemon Defense Systems, AS55101.

Learning Python: Part 2

Sun, 06 Apr 2014 02:34:52 -0500 » Nerd Projects, Programming

I’ve moved up in time/history to the 1980’s with Python – INI files!

I’ve modified one of my python scripts to now use ConfigParser to read in a .cfg file.

unifi-readcfg-sample.pylink
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('etc/unifi.cfg')
username = parser.get('unifi', 'username')
password = parser.get('unifi', 'password')

The simplicity, built in functionality to do tons, easy extensibility, and the readability make Python a fabulous language!

In my previous Learning Python blog post, I mentioned I was working with unifi-api, this is the output from that code:

home.py.txtlink
| => bin/home.py
AP NAME MAC LAST SEEN 0:00:00 ago
Theo-2.4G 00:27:22:54:fd:4e 2014-02-19 20:53:14 1085:11:47 ago
Theo-AC 24:a4:3c:10:5f:2c 2014-04-06 03:05:11 0:00:10 ago
CLIENT NAME MAC AP CHAN RSSI RX TX
android-b161ffe99389bd76 18:00:2d:90:89:d9 Theo-AC 1 49 6 72
BLACKBERRY-AD35 80:60:07:c8:47:d7 Theo-AC 1 42 11 24
TheoZ10 40:6f:2a:16:a0:4d Theo-AC 1 38 11 24
Joey-Mousepad 20:c9:d0:d3:6c:89 Theo-AC 36 38 450 450
Meagans-iPod f4:1b:a1:25:c0:20 Theo-AC 36 32 24 135
MouseTop 00:21:5d:66:79:48 Theo-AC 36 29 150 216
Nintendo 3DS 9c:e6:35:71:fd:a4 Theo-AC 1 14 11 11
© Theodore Baschak - https://github.com/tbaschak - Powered by Jekyll.
Powered by Les.net.
CiscoDude.net is a personal website. Opinions expressed are not necessarily those of his employer.