#! /usr/bin/python # ------------------------------------------- # Copyright 2006-2007 Erik Lechak # ------------------------------------------- # quakes is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # quakes is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Foobar; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Echo client program import socket import sys import os import time import urllib HOST = 'localhost' # The remote host PORT = 3666 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST,PORT)) def showEarthQuakes(): eq_template=""" cd /w/v/d/things/earthquakes diagram eq%i{ ln /sphere_low sphere rotate %s 0 1 0 rotate %s 0 0 1 translate .99 0 0 scale %s %s %s } """ f = urllib.urlopen("http://neic.usgs.gov/neis/gis/bulletin.asc") #f = file("eq","r") data = f.readlines() #for d in data: print d data.pop(0) c=0 for d in data: try: d=d.split(",") #print d lat = -float(d[2]) long = d[3] long = (float(long)+180) mag = d[4] try: mag = float(mag) except: mag = 1.0 scale = str(mag/100) #print lat,long ,d s.send(eq_template % (c,long,lat, scale ,scale ,scale)); c+=1 except: pass def showLocation(name, lat, long, scale): lat = float(lat) long = (float(long)+180) #print lat, long loc_template=""" cd /w/v/d/things/locations diagram %s{ def click{ set . ( return location "%s") } bind "1 mouse press" click ln /sphere_low sphere rotate %f 0 1 0 rotate %f 0 0 1 translate 1 0 0 scale %s %s %s } """ s.send(loc_template % (name,name,long,lat, scale ,scale ,scale)) def polar(name, coords, size = 1, color="0 255 0"): if len(coords)==1: t= "points polar \n" elif len(coords) > 1: t="line_strip polar\n" else: return for c in coords: m,lat,long = c m =float(m) lat = float(lat) long = (float(long)+180) t += "%f %f %f\n" % (m,lat,long) #print lat, long loc_template=""" cd /w/v/d/things/locations diagram %s{ def click{ set . ( reply location "%s") } bind "1 mouse press" click shape s{ rgb %s %s point_size %i line_size %i smooth } } """ s.send(loc_template % (name,name, color,t, size,size)) f = file("world") data = f.readlines() data = "\n".join(data) f.close() s.send(data); hide=""" cd /w/v/d/sphere hide """ showEarthQuakes() #showLocation("Raleigh", 35.7833, -78.65, .02) #showLocation("Test", 0, 0, .02) #showLocation("Greenwich", 51.5, 0, .02) coord=[ (1.1 , 51.5, 0), (1.0 , 51.5, 5), (1.0 , 51.5, 20), (1.1 , 51.5, 35), ] #polar("GGG", coord, 1) polar("Greenwich", [[ 1.01, 51.5, 0 ]], 2, "255 255 255") polar("Raleigh", [[ 1.01, 35.7833, -78.65 ]], 2, "255 0 0") s.send("update\n"); #~ c=0 #~ while (c < 10000 ): #~ s.send("cd /w/v/d rotate -.5 0 1 0 update\n"); #~ c+=1; #~ time.sleep(.05) while 1: length,type = s.recv(16).split() #print "Len:%s Type:%s" % (length,type) data = s.recv(int(length)) #print type,data if (type == "event"): if data=="close": sys.exit() elif (type == "location"): print data else: print data s.close()