Codes

Retrouvez ici mes différents scripts et morceaux de code.

FICHIERS :
				
#!/usr/bin/python2.7
#-*- coding: utf-8 -*-
import time
import threading

class Players(object):
	def __init__(self):
		self.players = []
		self.playersID = []

	def set(self, glaskTemp):
		if glaskTemp.id in self.playersID:
					(self.players[self.playersID.index(glaskTemp.id)]).update(glaskTemp.id, glaskTemp.isFilled, glaskTemp.isDrinking, glaskTemp.lastTime)
					#(self.players[self.playersID.index(glaskTemp.id)]).update(glaskTemp.id, glaskTemp.R, glaskTemp.G, glaskTemp.B, glaskTemp.isFilled, glaskTemp.isDrinking, glaskTemp.lastTime)
		else:
			self.players.append(glaskTemp)
			self.playersID.append(glaskTemp.id)

	def formatOut(self):
		r = ""
		for player in self.players:
			r = r + player.formatOut() + "\n"
		return r

	def get(self, id):
		if str(id) in self.playersID:
			return self.players[self.playersID.index(str(id))]
		else:
			return None

	def numOfPlayers(self):
		return len(self.playersID) 

	def isOnline(self, id):
		return str(id) in self.playersID


class Glask(object):
	def __init__(self, id, R, G, B, vibrate, isFilled, isDrinking, lastTime):
		self.id = id
		self.R = int(R)
		self.G = int(G)
		self.B = int(B)
		self.vibrate = vibrate
		self.isFilled = self.str2bool(isFilled)
		self.isDrinking = self.str2bool(isDrinking)
		self.lastTime = lastTime
		self.bestTime = lastTime
			
	def str2bool(self, v):
  		return v.lower() in ("yes", "true", "t", "1")

	def update(self, id, isFilled, isDrinking, lastTime):
		self.isFilled = isFilled
		self.isDrinking = isDrinking
		if int(lastTime) < int(self.bestTime):
			self.bestTime = int(lastTime)
		self.lastTime = lastTime

	def update2(self, id, R, G, B, isFilled, isDrinking, lastTime):
		self.R = R
		self.G = G
		self.B = B
		self.isFilled = isFilled
		self.isDrinking = isDrinking
		if int(lastTime) < int(self.bestTime):
			self.bestTime = int(lastTime)
		self.lastTime = lastTime

	def hello(self):
		print "Hello, I'm Glask"

	def vibrate(self):
		vibrate = 1

	def RGB(self, R, G, B):
		self.R = R
		self.G = G
		self.B = B

	def RGBtoRGB(self, R1, G1, B1, t, R2, G2, B2):
		self.R = R1
		self.G = G1
		self.B = B1
		t = threading.Timer(t/1000.0, self.RGB, [R2, B2, G2])
		t.start()

	def formatOut(self):
		return "#" + str(self.id) + ";" + str(self.R) + ";" + str(self.G) + ";" + str(self.B) + ";" + str(self.vibrate) + ";"