-
Notifications
You must be signed in to change notification settings - Fork 0
/
recdata.py
executable file
·37 lines (35 loc) · 1.2 KB
/
recdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
# -*- coding: UTF8 -*-
import xmlrpclib
import MySQLdb
import datetime,time
try:
server = xmlrpclib.ServerProxy("http://10.50.1.2:10018")
except:
pass
fichier=open("items.txt","r")
conn = MySQLdb.connect('localhost','root','root', 'opc')
curs = conn.cursor()
curs.execute("select now()")
datet= str(curs.fetchone()[0])
for line in fichier:
(serveur,item)=line.split(";")
item=item.replace(chr(13),'').replace(chr(10),'')
print serveur
print item
try:
res = server.opcserver.valeur(serveur,item)
timestamp=datetime.datetime.fromtimestamp(time.mktime(time.strptime(res['ITEM TIMESTAMP'],"%m/%d/%y %H:%M:%S"))).strftime('%Y-%m-%d %H:%M:%S')
except:
res={}
timestamp=str(datetime.datetime.fromtimestamp(time.time()))
res['ITEM QUALITY']='Bad'
print "Pas de reponse"
pass
if res['ITEM QUALITY'] == 'Bad':
res['ITEM VALUE']=None
requete ="insert into valeurs (dateenreg,timestamp,serveur,item,valeur,etat) values ('"+datet+"','"+timestamp+"','"+serveur+"','"+item+"','"+str(res['ITEM VALUE'])+"','"+res['ITEM QUALITY']+"')"
curs.execute(requete)
curs.execute("commit")
curs.close()
conn.close()