default=61000, ) parser.add_argument( "--gpg-key", help="GnuPG Key id", ) parser.add_argument( "ifname", ) parser.add_argument( "file", type=argparse.FileType("r"), ) args = parser.parse_args() sensorSock = SensorSocketEthernet(args.ifname, args.port, args.no_ip) sensorXML = SensorXML(args.schema) sensorXML.parse(args.file.read()) sensorGPG = None dataStr = None if args.gpg_key is not None: gpg = SensorGnuPG(args.gpg_key) sensorLAN = SensorLAN(sensorSock, sensorXML, sensorGPG) sensorLAN.send()
from datetime import datetime from SensorLAN import SensorGnuPG, SensorXML parser = argparse.ArgumentParser() parser.add_argument("--schema", help="SensorLAN.xsd location") parser.add_argument("--SensorLANDisplay", action="store_true", default=False) parser.add_argument("--bind", help="Bind to address, default all addresses", default="") parser.add_argument("--port", type=int, help="UDP port, default 61000", default=61000) args = parser.parse_args() gpg = SensorGnuPG() xml = SensorXML(args.schema) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.bind((args.bind, args.port)) DBusProxy = None if args.SensorLANDisplay: import dbus import dbus.exceptions DBusProxy = dbus.SessionBus().get_object("org.gnome.Shell", "/org/gnome/Shell/Extensions/SensorLANDisplay") DBusSensorLANIface = dbus.Interface(DBusProxy, "org.gnome.Shell.Extensions.SensorLANDisplay") while True:
#args.table = res["tableId"] print u"Create fusion table:" print u" - (id STRING, name STRING, time DATETIME, value NUMBER)" print u" - share it with this email %s" % key["client_email"] sys.exit() elif args.table.startswith("delete-"): print u"Deleting table", args.table[7:] print fusiontables.table().delete(tableId=args.table[7:]).execute() sys.exit() if args.input is None: sys.exit() xml = SensorXML() d = xml.parse(args.input.read()) time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") query = u"" for s in d["Sensors"]: query += u"INSERT INTO %s (id, name, time, value) VALUES ('%s', '%s', '%s', '%s');" % ( args.table, s["id"], s["name"], time, s["value"], )
#!/usr/bin/python # vi: et sw=2 fileencoding=utf8 # import argparse from SensorLAN import SensorXML parser = argparse.ArgumentParser() parser.add_argument( "--schema", help="SensorLAN xsd schema", ) parser.add_argument( "file", type=argparse.FileType("rb"), ) args = parser.parse_args() xml = SensorXML(args.schema) xml.parse(args.file.read()) print "Valid"