Пример #1
0
    def insertBuffer(self, target):
        for line in target:
            color = Signal.parseSignal(line)[0]
            if not color:
                return;
            location = Signal.parseSignal(line)[1]
            theTime = str(Signal.parseSignal(line)[2])

            #SQL Date format: YYYY-MM-DD
            splitResult = self.currentDate.split("_")
            theDate = splitResult[2] + "-" + splitResult[1] + "-" + splitResult[0]
            query = "INSERT INTO " + self.currentDate + " VALUES ( " + "'" + color + "'" + " ," + "'" + location + "'" + " ," + "'" + theDate + "'" + " ," + "'" + theTime + "'" + ");"
            self.cursor.execute(query)
            # Commit your changes in the database
            self.db.commit()
Пример #2
0
	def quickAppendBuffer(self, target):
		date = time.strftime("%d_%m_%Y") #get current date
		if not self.isCurrentDate(date): #check if the date has changed
			self.setCurrentDate(date);
		#create file according to date, location and bin color
		filePathBlack = self.relfilePath + self.__currentDate + "_" + self.__locationID + "_" + "black" + self.__fileExtension;
		filePathGreen = self.relfilePath + self.__currentDate + "_" + self.__locationID + "_" + "green" + self.__fileExtension;
		filePathBlue = self.relfilePath + self.__currentDate + "_" + self.__locationID + "_" + "blue" + self.__fileExtension;
		filePathGrey = self.relfilePath + self.__currentDate + "_" + self.__locationID + "_" + "grey" + self.__fileExtension;
		if not os.path.isfile(filePathBlack): #create a new file if new date
			self.quickInit(filePathBlack);
		if not os.path.isfile(filePathGreen): #create a new file if new date
			self.quickInit(filePathGreen);
		if not os.path.isfile(filePathBlue): #create a new file if new date
			self.quickInit(filePathBlue);
		if not os.path.isfile(filePathGrey): #create a new file if new date
			self.quickInit(filePathGrey);
		currentFileBlack = open(filePathBlack, 'a');
		currentFileGreen = open(filePathGreen, 'a');
		currentFileBlue = open(filePathBlue, 'a');
		currentFileGrey = open(filePathGrey, 'a');
		for line in target:
			color = Signal.parseSignal(line)[0];
			if not color:
				return;
			if color == "black":
				print("TEST... Printing color: " + color + " to the filepath: " + filePathBlack);
				currentFileBlack.write(line + '\n');
			if color == "green":
				print("TEST... Printing color: " + color + " to the filepath: " + filePathGreen);
				currentFileGreen.write(line + '\n');
			if color == "blue":
				print("TEST... Printing color: " + color + " to the filepath: " + filePathBlue);
				currentFileGreen.write(line + '\n');
			if color == "grey":
				print("TEST... Printing color: " + color + " to the filepath: " + filePathGrey);
				currentFileGreen.write(line + '\n');
				
		currentFileBlack.close();
		currentFileGreen.close();
		currentFileBlue.close();
		currentFileGrey.close();
Пример #3
0
def test_parseSignal():
    dateTime = datetime.datetime.utcnow()
    testSignal = Signal.initializeSignal("green","Nest",dateTime)
    expectedSignal = ("green,Nest," + str(dateTime)).split(Signal.delim)
    assert Signal.parseSignal(testSignal) == expectedSignal