Beispiel #1
0
  def testSum(self):
    cars = []
    aDictionary = { "Producator":"Mercedes","Caroserie":"Sedan","Model":"C180",
                    "AnProductie":1999,"VolumMotor":1800,"Pret":8000,
                    "Carburant":"Benzina","Link":"http://www.google.ro" }
    car = CarObject(aDictionary)
    cars.append(car)

    aDictionary = { "Producator":"BMW","Caroserie":"Sedan","Model":"M3",
                    "AnProductie":1999,"VolumMotor":1800,"Pret":8000,
                    "Carburant":"Diesel","Link":"http://www.google.ro" }
    car = CarObject(dictionary)
    cars.append(car)

    print JSONBuilder.getJSON(cars)
Beispiel #2
0
  def run(self):
    self._running = True
    while self._running:
      try:
        restQuery = self._socket.recv(1024)
        print restQuery
      except Exception as exc:
        print self._socket.getsockname(), exc
        break

      # Database connection
      db = DatabaseManager(DatabaseConfig.host)

      # Get SQL Query from REST
      sqlQuery = DatabaseManager.getSQLqueryFromREST(restQuery)

      # Get the result from SQL Server
      carObjects = db.SelectFromDatabase(sqlQuery)

      # Build a JSON String from the result
      jsonString = JSONBuilder.getJSON(carObjects)

      #Send to the server the result
      self._socket.send(jsonString)

    self._socket.close()