""" MoinMoin macro to display node status via MySQL query Jason McArthur <jason@personaltelco.net> (hack) """ from MoinMoin import config, wikiutil import re def execute(macro, text): import MySQLdb gkey = '' pHost = '' pUser = '' pPass = '' pDb = 'wnmap' pPage = "SELECT status, streetAddress, nodeName, lat, lng FROM nodes WHERE nodeName='%s'" % macro.formatter.page.page_name db = MySQLdb.connect (host = pHost,user = pUser,db = pDb) c = db.cursor() c.execute(pPage) result = c.fetchone() a = str(result[0]) b = str(result[1]) c = str(result[2]) d = str(result[3]) e = str(result[4]) db.close() if a == '2': return u'<div style="display: block;line-height: 1.2;text-align: left;height: 350px;"><a href="http://map.personaltelco.net/?select=%s"><img align="left" src="http://maps.google.com/staticmap?zoom=15&size=360x360&maptype=mobile&markers=%s,%s,green&key=%s"></a><form target="_blank" method="get" action="http://maps.google.com/maps"><label for="inputSaddr"> Start Address:<br></label> <input class="text" id="inputSaddr" name="saddr" style="width: 200px; height: 15px;" type="text"><br> <input value="Get Directions" class="label" type="submit"><input value="%s" name="daddr" type="hidden"></form><br><br><br> <strong>Coordinates:</strong><br> %s %s<br><br><br> <img src="http://map.personaltelco.net/images/green-dot-s.png">Active<br> <img src="http://map.personaltelco.net/images/red-dot-s.png">Down/Potential node<br> <img src="http://map.personaltelco.net/images/blue-dot-s.png">Inactive</div><br>' % (c, d, e, gkey, b, d, e) if a == '1': return u'<div style="display: block;line-height: 1.2;text-align: left;height: 350px;"><a href="http://map.personaltelco.net/?select=%s"><img align="left" src="http://maps.google.com/staticmap?zoom=15&size=360x360&maptype=mobile&markers=%s,%s,red&key=%s"></a><form target="_blank" method="get" action="http://maps.google.com/maps"><label for="inputSaddr"> Start Address:<br></label> <input class="text" id="inputSaddr" name="saddr" style="width: 200px; height: 15px;" type="text"><br> <input value="Get Directions" class="label" type="submit"><input value="%s" name="daddr" type="hidden"></form><br><br><br> <strong>Coordinates:</strong><br> %s %s<br><br><br> <img src="http://map.personaltelco.net/images/green-dot-s.png">Active<br> <img src="http://map.personaltelco.net/images/red-dot-s.png">Down/Potential node<br> <img src="http://map.personaltelco.net/images/blue-dot-s.png">Inactive</div>' % (c, d, e, gkey, b, d, e) if a == '0': return u'<div style="display: block;line-height: 1.2;text-align: left;height: 350px;"><a href="http://map.personaltelco.net/?select=%s"><img align="left" src="http://maps.google.com/staticmap?zoom=15&size=360x360&maptype=mobile&markers=%s,%s,blue&key=%s"></a><form target="_blank" method="get" action="http://maps.google.com/maps"><label for="inputSaddr"> Start Address:<br></label> <input class="text" id="inputSaddr" name="saddr" style="width: 200px; height: 15px;" type="text"><br> <input value="Get Directions" class="label" type="submit"><input value="%s" name="daddr" type="hidden"></form><br><br><br> <strong>Coordinates:</strong><br> %s %s<br><br><br> <img src="http://map.personaltelco.net/images/green-dot-s.png">Active<br> <img src="http://map.personaltelco.net/images/red-dot-s.png">Down/Potential node<br> <img src="http://map.personaltelco.net/images/blue-dot-s.png">Inactive</div>' % (c, d, e, gkey, b, d, e) if a == '': return