def do_POST(self): content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length) response = BytesIO() try: schedule = OpeningHours(body) resp_text = str(schedule) self.send_response(HTTPStatus.OK) except Exception as e: resp_text = str(e) self.send_response(HTTPStatus.BAD_REQUEST) self.end_headers() response.write(bytes(resp_text, encoding='utf-8')) self.wfile.write(response.getvalue())
def json_from_file(relative_path): with open( os.path.dirname(os.path.abspath(__file__)) + "/" + relative_path) as fs: return json.load(fs) # Loading all sensors' datas weather_forecast = json_from_file('../sensors/weather.json') places = json_from_file("/../sensors/all_places_infos.json") opening_hours = {} for place in places: opening_hours[str(place["id"])] = OpeningHours( json_from_file("../sensors/opening_hours-" + str(place["id"]) + ".json")[0]['opening_hours']) allsensors = [] base = datetime.datetime.today() week_day = { "Mon": 0, "Tue": 1, "Wed": 2, "Thu": 3, "Fri": 4, "Sat": 5, "Sun": 6 } # Initializing timezone
def get_weather(date, hour, what): try: return weather[str(date.year)][str(date.month)][str( date.day)][what][str(hour)] except: return 0 X = [] y = [] last = datetime.datetime.fromtimestamp(0) before = last try: oh = OpeningHours( json_from_file("../data/sensors/opening_hours-" + place_id + ".json")[0]['opening_hours']) except: oh = 0 tides = json_from_file('../data/tides.json') # Processing for each measure for i, measure in enumerate(measures): sys.stdout.write('\r ' + str(i * 100 / len(measures) + 1) + '%') sys.stdout.flush() measure_date = dateutil.parser.parse( measure["date"]) + datetime.timedelta(hours=2) # If the date has changed, we have to process the last day's data if ((measure_date.day > last.day) or (measure_date.month > last.month)):