Example #1
0
def getPrice(fname):
	components = getComponentList(fname)
	componentCounter = dict(Counter(components))
	price = 0
	db = sqlite3.connect(LogReader.getConfigValue("PriceDB"))
	cur = db.cursor()
	query = "SELECT * FROM prices"

	cur.execute(query)
	db.commit()
	rows = cur.fetchall()
	names = [desc[0] for desc in cur.description]
	nameIndex = names.index("name")
	priceIndex = names.index("price")
	for i in range(len(rows)):
		rName = rows[i][nameIndex]
		if isfloat(rName):
			rName = str(int(float(rows[i][nameIndex])))
		for component in components:
			if tryMatch(component,rName.lower()):
				componentCounter[component] -= 1
				price += float(rows[i][priceIndex])

	for k,v in componentCounter.items():
		if v > 0:
			print "Price for {} not found.".format(k)

	return price
Example #2
0
def getSpecificPrice(name):
	db = sqlite3.connect(LogReader.getConfigValue("PriceDB"))
	cur = db.cursor()
	query = "SELECT * FROM prices"

	cur.execute(query)
	db.commit()
	rows = cur.fetchall()
	names = [desc[0] for desc in cur.description]
	nameIndex = names.index("name")
	score = [0,""]
	for row in rows:
		d = jwtools.stringScore(name,row[nameIndex])
		if d > score[0]:
			score[0] = d
			score[1] = row[nameIndex]

	print "Best match for {} : {} with {}".format(name,score[1],score[0])
Example #3
0
def getConfig(model,varName=None):
	try:
		configFile = file(LogReader.getConfigValue("EbayConfig"),"r")
		cValues = jwjson.loadJSON(configFile.read())
		configFile.close()
		#if cfgOverride.has_key(varName):
		#	return cfgOverride[varName]
		if cValues.has_key(model):
			if varName is None:
				return cValues[model]
			if cValues[model].has_key(varName):
				print(cValues[model][varName])
				if type(cValues[model][varName]) is str or type(cValues[model][varName]) is unicode:
					
					if cValues[model][varName][:2] == "./":
						realpath = os.path.dirname(os.path.realpath(sys.argv[0]))
						
						return realpath + cValues[model][varName][1:]

				return cValues[model][varName]

		if cValues.has_key("default"):
			if varName is None:
				return cValues["default"]
			if cValues["default"].has_key(varName):
				if type(cValues["default"][varName]) is str or type(cValues["default"][varName]) is unicode:
					
					if cValues["default"][varName][:2] == "./":
						realpath = os.path.dirname(os.path.realpath(sys.argv[0]))
						return realpath + cValues["default"][varName][1:]

				return cValues["default"][varName]

		print("Warning: Could not find any config for {}".format(varName))
		return None

	except Exception as e:
		print("Warning: Could not load config file!")
		print(e)
		return None