示例#1
0
def _get_opening_hours(site):
    oh = site["attributes"].get("operatinghours")
    if oh:
        try:
            return OpeningHours.parse(oh).json()
        except Exception:
            # store the notes back in the dict so the notes function can grab it later
            site["opening_hours_notes"] = "Hours: " + oh
    else:
        return None
示例#2
0
 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())
示例#3
0
文件: features.py 项目: Asphahyre/gip
        return json.load(fs)

weather = json_from_file('../data/weather.json')

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)):
        # Displays X and y depending on the temperature (Z) and humidity (colors)
        #scat = ax.scatter(X, y, map(lambda x: float(get_weather(last, int(x), "temperature")), X), c = map(lambda x: 1 - float(get_weather(last, int(x), "humidex")), X))
示例#4
0

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
示例#5
0
    except Exception as e:
        pass

print
print "Retrieving holidays"
xml = ET(file = '../data/holidays.xml')
oh = ""
for node in xml.findall('./calendrier/zone[@libelle="A"]/*'):
    begin = node.get('debut').split('/')
    end = node.get('fin').split('/')
    if (begin[0] == end[0]):
        oh += begin[0] + " " + months[begin[1]] + " " + begin[2] + " - " + months[end[1]] + " " + end[2] + " ; "
    else:
        oh += begin[0] + " " + months[begin[1]] + " " + begin[2] + " - Dec 31 ; " + end[0] + " Jan 01 - " + months[end[1]] + " " + end[2] + " ; "

hd = OH(oh[:len(oh) - 3])

print
print "Weather forecast"
weather = [{} for i in range(0, len(places))]
loading = ['-', '\\', '|', '/']
icons = {
        "clear-day"             : 0,
        "clear-night"           : 0,
        "rain"                  : 2,
        "snow"                  : 3,
        "sleet"                 : 3,
        "wind"                  : 1,
        "fog"                   : 2,
        "cloudy"                : 1,
        "partly-cloudy-day"     : 1,
示例#6
0
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)):
示例#7
0
def finish_happy_hours(chaine, jour_heure):
    definition = OpeningHours(chaine)
    if bouchon :
    	return definition.minutes_to_closing("fr", "19:00") 
    return definition.minutes_to_closing(jour_heure[0], jour_heure[1])
示例#8
0
def check_happy_hours(chaine, jour_heure):
    definition = OpeningHours(chaine)
    if bouchon :
    	return definition.is_open("fr", "19:00")
    return definition.is_open(jour_heure[0], jour_heure[1])