示例#1
0
def destilator(data):
    global url
    
    try:
    	if (data["vrstaZahtjeva"] == "1" or data["vrstaZahtjeva"] == "2"):
		print data["mbo"]	
		content = hzzoHtmlGetter().getHtml(data["mbo"])
		htmltext = open("htmlhzzo", "w")
		htmltext.write(content)
		htmltext.close()
        	data = scraping(content, data)
        	if data["errorCode"] != 0:
            		return data
		sql = sqlWork()
		sql.updateData(mbo=data["mbo"], kategorija=data["kategorija"], areacode=data["podrucni"], osnova=data["osnova"])
		sql.commitData()
        	return data
    	elif (ubazi(data["mbo"])):
        	content = hzzoHtmlGetter().getHtml(data["mbo"])
        	podatak = scraping(content, data)
		sql = sqlWork()
		sql.updateData(mbo=podatak["mbo"], kategorija=podatak["kategorija"], areacode=podatak["podrucni"],osnova=podatak["osnova"])
		sql.commitData()
        	return podatak
    	else:
		data_baza = sqlWork().returnData("select kategorija, podrucni, osnova, zadnjiUpdate from testTable where mbo = %s" % data["mbo"])            
		data_baza = data_baza[0]
        	data["kategorija"] = data_baza[0]
        	data["podrucni"] = data_baza[1]
        	data["osnova"] = data_baza[2]
        	data["izvor"] = "1"
        	data["updateTime"] = data_baza[3]
        	return data

    except Exception as inst:
        dataObrada(data)
        #log :: progreska u obradi podataka
        #print("Pogreska na serveru! MBO:" + poruka)
        print  "ispis data"
        print str(inst)
        data["errorCode"] = "1"
        if data["vrstaZahtjeva"] == "2":
            return data["errorCode"]
        return data
示例#2
0
def ubazi(mbo):
    data = sqlWork().returnData("select mbo, kategorija from testTable where mbo = %s" % mbo)
    try:    
	data = data[0]
    except:
	pass
    try:
        if (data == "[]" or data[1] == "Null"):
            return True
    except:
        return True
    return False
示例#3
0
def updater_thread():
	updater_con = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	updater_con.bind((serverIP, updaterPort))
	rjecnik = {"mbo": "143520838", "kategorija": "A", "podrucni": "004", "osnova": "00112", "brojPristupa": "0", "errorCode": "0", "updateTime": "14", "vrstaZahtjeva": "2", "izvor":"0"}
	sql3 = "select mbo from testTable where length(podrucni) is not 5 limit 1;"
	sql2 = "select mbo from testTable where length(kategorija) is not 1 limit 1;"
	sql1 = "select mbo from testTable where osnova = 0 or podrucni = 0 limit 1;"
	sql4 = "select mbo from testTable where kategorija = 'A' or kategorija = 'F' order by zadnjiUpdate limit 1;"
	
	data = sqlWork().returnData(sql1)
	if data != []:
		data = data[0][0]
		rjecnik["mbo"] = str(data)
		updater_con.sendto(json.dumps(rjecnik), (serverIP, serverPort))
		data, addr = updater_con.recvfrom(2048)

	data = sqlWork().returnData(sql2)
	if data != []:
		data = data[0][0]
		rjecnik["mbo"] = str(data)
		updater_con.sendto(json.dumps(rjecnik), (serverIP, serverPort))
		data, addr = updater_con.recvfrom(2048)

	data = sqlWork().returnData(sql3)
	if data != []:
		data = data[0][0]
		rjecnik["mbo"] = str(data)
		updater_con.sendto(json.dumps(rjecnik), (serverIP, serverPort))
		data, addr = updater_con.recvfrom(2048)
	data = sqlWork().returnData(sql4)

	if data != []:
		data = data[0][0]
		rjecnik["mbo"] = str(data)
		updater_con.sendto(json.dumps(rjecnik), (serverIP, serverPort))
		data, addr = updater_con.recvfrom(2048)



	timer(60)
示例#4
0
def dataObrada(data):
    try:
	sql = sqlWork()
        podaci = sql.returnData("select kategorija, mbo, counter from testTable where mbo = %s" % data["mbo"])
        if (podaci != []):
	    sql.updateData(mbo=data[mbo], counter=podaci[0][2])
	    sql.commitData()
        else:
            #provjera na netu
	    sql.insertData(mbo=data["mbo"], kategorija=data["kategorija"], osnova=data["osnova"], areacode=data["podrucni"])
	    sql.commitData()
    except:
        pass