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
|
// Comment puis-je vérifier que cet import fonctionne
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
import time
import _mysql
import pprint
class SendContent(Protocol):
def connectionMade(self):
print 'Accepted connection'
def dataReceived(self, data):
date = time.time()
values = data.split(',');
if len(values) != 4:
print 'Error: Bad Data'
print "je ne "
db = None;
try:
db = _mysql.connect('localhost', 'user','pw','gpsDB')
db.query("INSERT INTO tracker (date, speed, lat, lng, course)" +
"VALUES ('" + str(date) + "', '" + str(values[0]) + "', '" +
str(values[1]) + "', '" + str(values[2]) + "', '" + str(values[3]) + "')")
print "---------------------"
print "| Data Logged |"
print "---------------------"
print "Speed: " + values[0]
print "Latitude: " + values[1]
print "Longitude: " + values[2]
print "Course: " + values[3]
except _mysql.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
finally:
if db:
db.close()
class SendContentFactory(Factory):
protocol = SendContent
reactor.listenTCP(81, SendContentFactory())
reactor.run()
print "end" |
Partager