Size: 160
Comment:
|
← Revision 5 as of 2008-05-13 18:59:50
Size: 223
Comment: mysql-python
|
Deletions are marked like this. | Additions are marked like this. |
Line 4: | Line 4: |
Dependencies: http://wnmap.sf.net | Dependencies: http://wnmap.sf.net [[http://sourceforge.net/projects/mysql-python/|mysql-python]] |
Line 6: | Line 6: |
{{attachment:MapLink.py}} | {{attachment:NodeMap.py}} |
Node Map Macro
Examples: NodeAmnesia
Download: NodeMap.py
Dependencies: http://wnmap.sf.net mysql-python
1 """
2 MoinMoin macro to display node status via MySQL query
3
4 by Jason McArthur <jason@personaltelco.net>
5
6 """
7 from MoinMoin import config, wikiutil
8
9 import re
10 def execute(macro, text):
11 import MySQLdb
12 import htmlentitydefs
13 gkey = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RQUexDMtc4eREioiWSpX_Y7fpoKghQhUCefr4eJwudYofs3YH9eyyZ3_g'
14 pHost = 'localhost'
15 pUser = 'wnmap'
16 pPass = ''
17 pDb = 'wnmap'
18 if text is None:
19 pPage = "SELECT status, streetAddress, nodeName, lat, lng, line3 FROM nodes WHERE nodeName='%s'" % macro.formatter.page.page_name
20 else:
21 pPage = "SELECT status, streetAddress, nodeName, lat, lng, line3 FROM nodes WHERE nodeName='%s'" % text
22
23 db = MySQLdb.connect (host = pHost,user = pUser,db = pDb)
24 c = db.cursor()
25 c.execute(pPage)
26 result = c.fetchone()
27 a = str(result[0])
28 b = str(result[1])
29 c = str(result[2])
30 d = str(result[3])
31 e = str(result[4])
32 db.close()
33 if a == '2':
34 return u'<div id="gmap"><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)
35 if a == '1':
36 return u'<div id="gmap"><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)
37 if a == '0':
38 return u'<div id="gmap"><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)
39 if a == '':
40 return
41