<commit_before>#!/usr/bin/env python

import MySQLdb
import datetime
import urllib2
import os
  
servername = "localhost"
username = "pi"
password = "password"
dbname = "pi_heating_db"

t = datetime.datetime.now().strftime('%s')

cnx = MySQLdb.connect(host=servername, user=username, passwd=password, db=dbname)
cursorread = cnx.cursor()

query = ("SELECT * FROM sensors")

cursorread.execute(query)
  
results =cursorread.fetchall()
cursorread.close()
  
for i in results:
  sensor_ip = i[3]
  sensor_ref = i[1]
  sensor_id = i[0]
    
  sensor_url = "http://"+sensor_ip+":8080/value.php?id="+sensor_ref

  #print sensor_url
  
  try:
    data = float( urllib2.urlopen(sensor_url).read() )  
  except:
    data = 'na'
    
  print data
  print sensor_id
  
  if( data != 'na' ):
    print "database"
    #print sensor_id
    
    sql = "UPDATE sensors SET value='"+string(data)+"' WHERE id='"+sensor_id+"';"
    
    print sql<commit_msg>Update poll-sensors.py<commit_after>#!/usr/bin/env python

import MySQLdb
import datetime
import urllib2
import os
  
servername = "localhost"
username = "pi"
password = "password"
dbname = "pi_heating_db"

t = datetime.datetime.now().strftime('%s')

cnx = MySQLdb.connect(host=servername, user=username, passwd=password, db=dbname)
cursorread = cnx.cursor()

query = ("SELECT * FROM sensors")

cursorread.execute(query)
  
results =cursorread.fetchall()
cursorread.close()
  
for i in results:
  sensor_ip = i[3]
  sensor_ref = i[1]
  sensor_id = i[0]
    
  sensor_url = "http://"+sensor_ip+":8080/value.php?id="+sensor_ref

  #print sensor_url
  
  try:
    data = float( urllib2.urlopen(sensor_url).read() )  
  except:
    data = 'na'
    
  print data
  print sensor_id
  
  if( data != 'na' ):
    print "database"
    #print sensor_id
    
    sql = "UPDATE sensors SET value='"+str(data)+"' WHERE id='"+sensor_id+"';"
    
    print sql
{'fraction_non_alphanumeric': 0.14225053078556263, 'fraction_numerical': 0.009554140127388535, 'mean_word_length': 3.7125, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '193136', 'n_tokens_mistral': 703, 'n_tokens_neox': 683, 'n_words': 152}