def request_loader(request): if session: security.csrfProtect() config = api.getConfig() for k, v in config["general_settings"]["users"].items(): users[k] = v if config["general_settings"]["domoboard"]["autologon"] == "True": users['Auto'] = {'group': 'user', 'password': '******'} username = request.form.get('username') password = request.form.get('password', '') if username not in users: return user = User() user.id = username user.group = users[username]['group'] try: user.is_authenticated = compare_digest(password, users[username]['password']) except: return return user
def getData(params={}): config = api.getConfig() _api_key = config['general_settings']['wunderground']['api'] _language = config['general_settings']['wunderground']['language'] data = {} if params['action'] == 'condition': _url = "http://api.wunderground.com/api/" + _api_key + "/conditions/lang:" + _language + "/q/" + params[ 'country'] + "/" + params['loc'] + ".json" _urlForecast = "http://api.wunderground.com/api/" + _api_key + "/forecast/lang:" + _language + "/q/" + params[ 'country'] + "/" + params['loc'] + ".json" data['conditions'] = createCondition(requests.get(_url).text) data['forecastTxt'], data['forecastSimple'] = createForecast( requests.get(_urlForecast).text) elif params['action'] == 'forecast': _url = "http://api.wunderground.com/api/" + _api_key + "/forecast/lang:" + _language + "/q/" + params[ 'country'] + "/" + params['loc'] + ".json" data['forecastTxt'], data['forecastSimple'] = createForecast( requests.get(_url).text) data['dateIDToday'] = datetime.datetime.strptime( str(datetime.date.today() + timedelta(days=int(1) - 1)), "%Y-%m-%d").strftime('%Y%m%d') data['todayWeekday'] = datetime.datetime.strptime( str(datetime.date.today() + timedelta(days=int(1) - 1)), "%Y-%m-%d").strftime('%A') data['today'] = datetime.datetime.strptime(str(datetime.date.today()), "%Y-%m-%d").strftime('%Y%m%d') return simplejson.encoder.JSONEncoderForHTML().encode( simplejson.loads(json.dumps(data)))
def init(): if session: security.csrfProtect() config = api.getConfig() g.users = {} for k, v in list(config["general_settings"]["users"].items()): addUser = AuthUser(username=k) addUser.set_and_encrypt_password(v) g.users[k] = addUser
def queryDomoticz(url): config = api.getConfig() try: r = requests.get( 'http://' + config["general_settings"]["server"]["domoticz_url"] + '/json.htm' + url, auth=(config["general_settings"]["server"].get("user"), config["general_settings"]["server"].get("password")), timeout=5.00) except: return "{}" return r.text
def init(): if session: security.csrfProtect() config = api.getConfig() g.users = {} for k, v in config["general_settings"]["users"].iteritems(): addUser = AuthUser(username=k) addUser.set_and_encrypt_password(v) g.users[k] = addUser if config["general_settings"]["domoboard"]["autologon"] == "True": addUser = AuthUser(username='******') addUser.set_and_encrypt_password('auto') g.users['auto'] = addUser
def call_homegraph_api_key(payload): config = api.getConfig() url = 'https://homegraph.googleapis.com/v1/devices:requestSync?key=' + config[ "general_settings"]["google_assistant"]["api_key"] r = requests.post(url, json=payload) if 'error' in r.text: logger.error(r.text) return r.status_code == requests.codes.ok
def getData(params={}): config = api.getConfig() data = {} if params['zipcode'] != '': data['zipcode'] = params['zipcode'] if params['housenr'] != '': data['housenr'] = params['housenr'] if 'zipcode' in data and 'housenr' in data: _url = "http://mijnafvalwijzer.nl/nl/" + data['zipcode'] + '/' + data[ 'housenr'] + '/' _src = requests.get(_url).text data['month'] = parseSource(_src, params) return simplejson.encoder.JSONEncoderForHTML().encode( simplejson.loads(json.dumps(data)))
def getData(params={}): config = api.getConfig() icloudAPI = PyiCloudService( config["general_settings"]["icloud"]["user"], config["general_settings"]["icloud"]["password"]) today = datetime.date.today() monday = today - datetime.timedelta(days=today.weekday()) sunday = monday + datetime.timedelta(days=6) events = icloudAPI.calendar.events(monday, sunday) weekEvents = [] for i in events: ob = {} start = i['localStartDate'] end = i['localEndDate'] ob['start'] = str(start[1]) + '-' + str(start[2]) + '-' + str( start[3]) + ' ' + str(start[4]).zfill(2) + ':' + str( start[5]).zfill(2) ob['end'] = str(end[1]) + '-' + str(end[2]) + '-' + str( end[3]) + ' ' + str(end[4]).zfill(2) + ':' + str(end[5]).zfill(2) ob['startDate'] = datetime.datetime.strptime( ob['start'], "%Y-%m-%d %H:%M").strftime('%d/%m/%Y %H:%M') ob['endDate'] = datetime.datetime.strptime( ob['end'], "%Y-%m-%d %H:%M").strftime('%d/%m/%Y %H:%M') ob['startTime'] = datetime.datetime.strptime( ob['start'], "%Y-%m-%d %H:%M").strftime('%H:%M') ob['endTime'] = datetime.datetime.strptime( ob['end'], "%Y-%m-%d %H:%M").strftime('%H:%M') ob['day'] = calendar.day_name[datetime.datetime.strptime( ob['startDate'], '%d/%m/%Y %H:%M').weekday()] ob['event'] = i['title'] if i['location']: ob['location'] = ', ' + i['location'] else: ob['location'] = '' ob['weekday'] = (datetime.datetime.strptime( ob['startDate'], '%d/%m/%Y %H:%M').weekday()) % 7 weekEvents.append(ob) return json.dumps( sorted(weekEvents, key=lambda x: (x['weekday'], x['startTime'])))
def getData(params={}): config = api.getConfig() route = {} if 'start' in params and 'end' in params: start = params['start'] end = params['end'] if getStartGeo(start) == None: setStartGeo(start, geocode(start)) if getEndGeo(end) == None: setEndGeo(end, geocode(end)) startGeo = getStartGeo(start) endGeo = getEndGeo(end) if (type(startGeo) is dict) and (type(endGeo) is dict): if not 'town' in startGeo['address']: try: startGeo['address']['town'] = startGeo['address']['city'] except KeyError: startGeo['address']['town'] = startGeo['address']['suburb'] if not 'town' in endGeo['address']: try: endGeo['address']['town'] = endGeo['address']['city'] except KeyError: endGeo['address']['town'] = endGeo['address']['suburb'] if not 'house_number' in startGeo['address']: startGeo['address']['house_number'] = '1' if not 'house_number' in endGeo['address']: endGeo['address']['house_number'] = '1' if not 'road' in startGeo['address']: startGeo['address']['road'] = startGeo['address']['pedestrian'] if not 'road' in endGeo['address']: endGeo['address']['road'] = endGeo['address']['pedestrian'] setStartGeo(start, startGeo) setEndGeo(end, endGeo) fromAddress = startGeo['address']['road'] + ' ' + startGeo[ 'address']['house_number'] + ',' + startGeo['address'][ 'postcode'] + ',' + startGeo['address']['town'] toAddress = endGeo['address']['road'] + ' ' + endGeo['address'][ 'house_number'] + ',' + endGeo['address'][ 'postcode'] + ',' + endGeo['address']['town'] routeID = createID() startTimeNow = datetime.datetime.now().strftime( "%Y-%m-%dT%H:%M:%S.%fZ") fromd = '"transportMode":"auto","includeTraffic":true,"avoidTolls":false,"avoidTraffic":false,"address":"' + fromAddress + '","location":"' + fromAddress + '","routeType":"fast","departNow":true,"lat":"' + \ startGeo['lat'] + '","lon":"' + startGeo[ 'lon'] + '","countryCode":"NLD","mapZoom": 17,"excludeTransportType":"","includeTransportType":"Bus,Metro,Tram,Trein,Veerboot"' tod = '"transportMode":"auto","includeTraffic":true,"avoidTolls":false,"avoidTraffic":false,"address":"' + toAddress + '","location":"' + toAddress + '","routeType":"fast","departNow":true,"lat":"' + \ endGeo['lat'] + '","lon":"' + endGeo[ 'lon'] + '","countryCode":"NLD","mapZoom": 17,"excludeTransportType":"","includeTransportType":"Bus,Metro,Tram,Trein,Veerboot"' u_to = 'http://verkeerstatic.anwb.nl/anwbrouting/anwbrouting/CalculateRoute?routeId=' + routeID + '&route={"id":"' + routeID + '","waypoints":[{' + fromd + '},{' + tod + '}],"language":"NL","startDateTime":"' + startTimeNow + '","timeType":"depart"}' result_to = requestUrl(u_to) routeID = createID() u_back = 'http://verkeerstatic.anwb.nl/anwbrouting/anwbrouting/CalculateRoute?routeId=' + routeID + '&route={"id":"' + routeID + '","waypoints":[{' + tod + '},{' + fromd + '}],"language":"NL","startDateTime":"' + startTimeNow + '","timeType":"depart"}' result_back = requestUrl(u_back) json_output_to = json.loads(result_to.content) json_output_back = json.loads(result_back.content) routeInfo_to = generateInfo(json_output_to) routeInfo_to['from'] = fromAddress routeInfo_to['to'] = toAddress routeInfo_back = generateInfo(json_output_back) routeInfo_back['from'] = toAddress routeInfo_back['to'] = fromAddress route['to'] = routeInfo_to route['back'] = routeInfo_back route['traffic'] = getTrafficAndRadar() ajson = simplejson.loads(json.dumps(route)) cleaned_json = simplejson.encoder.JSONEncoderForHTML().encode( ajson) return cleaned_json else: routeInfo_to = {} routeInfo_back = {} route = {} routeInfo_to['from'] = startGeo routeInfo_to['to'] = endGeo routeInfo_back['from'] = endGeo routeInfo_back['to'] = startGeo route['to'] = routeInfo_to route['back'] = routeInfo_back route['traffic'] = getTrafficAndRadar() return simplejson.encoder.JSONEncoderForHTML().encode( simplejson.loads(json.dumps(route))) else: route['traffic'] = getTrafficAndRadar() return simplejson.encoder.JSONEncoderForHTML().encode( simplejson.loads(json.dumps(route)))
def indexWebConfig(params={}): if 'page' in params: return api.getConfig()[params['page']] else: return api.getConfig()