<commit_before>import serial
import schedule
import time
import json
import forecastio
import sys
from flask import Flask, request, jsonify, send_from_directory
from threading import Thread
from influxdb import InfluxDBClient
from pprint import pprint

try:
  from flask.ext.cors import CORS  # The typical way to import flask-cors
except ImportError:
  # Path hack allows examples to be run without installation.
  import os
  parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  os.sys.path.insert(0, parentdir)
  from flask.ext.cors import CORS

# COM_PORT = 2
COM_PORT = "/dev/ttyUSB0"
BAUDRATE = 9600
READ_SENSORS_TIMER = 30
READ_SENSORS_FAST_TIMER = 5
GET_METEO_TIMER = 2 * 60
# DB_HOST = '192.168.1.73'
DB_HOST = "localhost"
DB_PORT = 8086
DB_NAME = 'awarehouse'
DB_PASS = '<PASSWORD>'
DB_USER = 'admin'

FORECAST_API_KEY = "111fece1a5a2d1828fb6e795221e2c25"
FORECAST_LAT = 41.1492
FORECAST_LNG = -8.6104
#FORECAST_UNIT = "si"

current_forecast = {}

influxdb = InfluxDBClient(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME)

ser = serial.Serial(COM_PORT, BAUDRATE)

app = Flask(__name__, static_url_path='/static')
app.debug = True
cors = CORS(app)

def get_sensors():
  if get_sensors.counter == ((READ_SENSORS_TIMER / READ_SENSORS_FAST_TIMER) - 1):
    ser.write('r')
  else:
    ser.write('x')

  get_sensors.counter += 1

  jsonInfo = ser.readline()
  jsonInfo = jsonInfo.replace('\n', '')
  jsonInfo = jsonInfo.replace('\r', '')
  jsonInfo = jsonInfo.replace('\'', '\"')
  m = json.loads(jsonInfo)
  m.append(current_forecast)
  try:
    influxdb.write_points(m)
  except:
    print "Unexpected error InfluxDB:", sys.exc_info()[0]

get_sensors.counter = 0

def get_meteo():
  try:
    forecast = forecastio.load_forecast(
        FORECAST_API_KEY, FORECAST_LAT, FORECAST_LNG)
    temp = forecast.currently().temperature
    humi = forecast.currently().humidity * 100
  except:
    print "Unexpected error Forecast.io:", sys.exc_info()[0]
  else:
    global current_forecast
    current_forecast = {
        "points": [[temp, humi]],
        "name": "forecastio",
        "columns": ["temperature", "humidity"]
    }
<commit_msg>bug on read<commit_after>import serial
import schedule
import time
import json
import forecastio
import sys
from flask import Flask, request, jsonify, send_from_directory
from threading import Thread
from influxdb import InfluxDBClient
from pprint import pprint

try:
  from flask.ext.cors import CORS  # The typical way to import flask-cors
except ImportError:
  # Path hack allows examples to be run without installation.
  import os
  parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  os.sys.path.insert(0, parentdir)
  from flask.ext.cors import CORS

# COM_PORT = 2
COM_PORT = "/dev/ttyUSB0"
BAUDRATE = 9600
READ_SENSORS_TIMER = 30
READ_SENSORS_FAST_TIMER = 5
GET_METEO_TIMER = 2 * 60
# DB_HOST = '192.168.1.73'
DB_HOST = "localhost"
DB_PORT = 8086
DB_NAME = 'awarehouse'
DB_PASS = '<PASSWORD>'
DB_USER = 'admin'

FORECAST_API_KEY = "111fece1a5a2d1828fb6e795221e2c25"
FORECAST_LAT = 41.1492
FORECAST_LNG = -8.6104
#FORECAST_UNIT = "si"

current_forecast = {}

influxdb = InfluxDBClient(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME)

ser = serial.Serial(COM_PORT, BAUDRATE)

app = Flask(__name__, static_url_path='/static')
app.debug = True
cors = CORS(app)


def get_sensors():
  if get_sensors.counter == ((READ_SENSORS_TIMER / READ_SENSORS_FAST_TIMER) - 1):
    ser.write('r')
    get_sensors.counter = 0
  else:
    ser.write('x')
  get_sensors.counter += 1
  jsonInfo = ser.readline()
  jsonInfo = jsonInfo.replace('\n', '')
  jsonInfo = jsonInfo.replace('\r', '')
  jsonInfo = jsonInfo.replace('\'', '\"')
  m = json.loads(jsonInfo)
  m.append(current_forecast)
  try:
    influxdb.write_points(m)
  except:
    print "Unexpected error InfluxDB:", sys.exc_info()[0]

get_sensors.counter = 0


def get_meteo():
  try:
    forecast = forecastio.load_forecast(
        FORECAST_API_KEY, FORECAST_LAT, FORECAST_LNG)
    temp = forecast.currently().temperature
    humi = forecast.currently().humidity * 100
  except:
    print "Unexpected error Forecast.io:", sys.exc_info()[0]
  else:
    global current_forecast
    current_forecast = {
        "points": [[temp, humi]],
        "name": "forecastio",
        "columns": ["temperature", "humidity"]
    }

{'fraction_non_alphanumeric': 0.11878453038674033, 'fraction_numerical': 0.030156537753222835, 'mean_word_length': 4.266666666666667, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1949875', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1587, 'n_words': 358}