-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeoMapIP.py
More file actions
103 lines (84 loc) · 3.25 KB
/
geoMapIP.py
File metadata and controls
103 lines (84 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
import jsonrpc
import socket
#rpc = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportSocket(addr="/tmp/testservice", sock_type=socket.AF_UNIX))
rpc = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportSocket(addr=("127.0.0.1",11111)))
#print "Hi, "+rpc.bridge.getPeerName(rpc.bridge.getOwnId())
import sys
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import random
import pygeoip
gi = pygeoip.GeoIP('/opt/geolite/GeoLiteCity.dat', pygeoip.MEMORY_CACHE)
class MainWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(MainWidget, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays /embpyqt/python/the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QtGui.QPushButton('Plot')
self.button.clicked.connect(self.plot)
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
def plot(self):
''' plot some random stuff '''
# random data
'''data = [random.random() for i in range(2)]
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.hold(False)
# plot data
ax.plot(data, '*-')'''
m = Basemap(projection='robin',lon_0=0,resolution='c')#,latlon=True)
m.bluemarble(scale=0.2)
for friend in rpc.bridge.getFriendList():
print ''
pd = rpc.bridge.getPeerDetails(friend)
print pd['name']
print pd['extAddr']
ld = gi.record_by_addr(pd['extAddr'])
print ld
if ld:
print ld['latitude'],ld['longitude']
x, y = m(ld['longitude'],ld['latitude'])
#m.scatter(x, y,30,marker='o',color='k')
plt.plot(x, y,'ro')
plt.text(x,y,pd['name'],fontsize=9,
ha='center',va='top',color='r',
bbox = dict(boxstyle="square",ec='None',fc=(1,1,1,0.5)))
#plt.text(x,y,pd['name'],fontsize=14,fontweight='bold',
# ha='center',va='center',color='r')
# refresh canvas
self.canvas.draw()
class Window(QtGui.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
layout = QtGui.QVBoxLayout()
layout.addWidget(MainWidget())
self.setLayout(layout)
def setParent(incoming):
incoming.addWidget(MainWidget())
print "hmm"
#a=MainWidget()
#a.show()
if __name__ == '__main__':
print "running as main"
app = QtGui.QApplication(sys.argv)
main = Window()
#main.addWidget(Window)
main.show()
sys.exit(app.exec_())