Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import socket
- import os
- import threading
- import mysql.connector
- import time
- import datetime
- Dconn = mysql.connector.connect(user='root', password='peiman64',host='localhost',database='prisoner',charset='utf8',autocommit=True)
- cursor = Dconn.cursor(buffered=True)
- cursor2 = Dconn.cursor(buffered=True)
- print('databased stablished.')
- def sendData(server,port,sig) :
- # now = datetime.datetime.now()
- print(format(server)+':'+format(port)+' - '+format(sig[0]))
- cursor2.execute("select * from raw join devices on devices.dvid=raw.device where raw.rdid='"+format(sig[1])+"' limit 1;")
- sendSig = cursor2.fetchone()
- print(sendSig)
- clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- result = clientsocket.connect((server,port))
- timezonedata = datetime.datetime.fromtimestamp(int(sendSig[12]+14400))
- sistr='$MGV002,'+sendSig[18]+',12345,S,'+timezonedata.strftime("%d%m%y")+','+timezonedata.strftime("%H%M%S")+',A,'+format(sendSig[2])+',N,0'+format(sendSig[3])+',E,0,'+format(sendSig[5])+',00,1.95,'+format(sendSig[4])+',0,,,432,$
- print(sistr)
- clientsocket.send(sistr)
- while True:
- data = clientsocket.recv(1024)
- print ("Received response:" + str(data))
- break
- # if data.decode('utf8')=='#AL#1###rn':
- sqlobject = "UPDATE `row_sent` SET `result`='succes',`send_date`=NOW() WHERE `rsid`='"+format(sig[0])+"' limit 1;"
- try:
- for result in cursor.execute(sqlobject,multi = True):
- pass
- except mysql.connector.Error as err:
- print("Something went wrong: {}".format(err))
- clientsocket.close()
- while True:
- cursor.execute("select * from row_sent where result='pending' limit 1;")
- if cursor.rowcount>0 :
- waitedSig = cursor.fetchone()
- cursor.execute("select * from servers where `status`='active';")
- if cursor.rowcount>0 :
- fields=cursor.fetchall()
- for field in fields:
- t = threading.Thread(target=sendData , args=((field[3]),(field[4]),(waitedSig),))
- t.start()
- time.sleep(0.5)
- else:
- time.sleep(1)
- print('he...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement