Exemple #1
0
 def __check_for_errors(self, r: requests.request) -> requests.request:
     if r.status_code == 200:
         if r.text == "":  # BUG: Delete User returns 200, not 204 like it should, as of firmware 1.5.0
             return None
         return r.json()
     elif r.status_code == 204:
         return None
     elif r.status_code == 403:
         print("Error 400: Bad request! (" + self.ip_address + ")")
     elif r.status_code == 401:
         print(
             "Error 401: Not authorized! This is an invalid token for this Aurora ("
             + self.ip_address + ")")
     elif r.status_code == 404:
         print("Error 404: Resource not found! (" + self.ip_address + ")")
     elif r.status_code == 422:
         print("Error 422: Unprocessible Entity (" + self.ip_address + ")")
     elif r.status_code == 500:
         print("Error 500: Internal Server Error (" + self.ip_address + ")")
     else:
         print(
             "ERROR! UNKNOWN ERROR " + str(r.status_code) +
             ". Please post an issue on the GitHub page: https://github.com/software-2/nanoleaf/issues"
         )
     return None
Exemple #2
0
 def get_target_url(self, url: str, res: requests.request) -> str:
     res.encoding = 'utf-8'
     html = res.text
     doc = BeautifulSoup(html, 'html.parser')
     css_q = 'a[href*="' + self.target_date + '"]'
     element = doc.select(css_q)
     if len(element):
         link = element[0].get('href')
         target_url = urljoin(url, link)
         return target_url
Exemple #3
0
    def _save_json(data: requests.request, filename: str) -> None:
        """
        Save data to file named filename (json)
        Parameters:
            data: request.request - object that contains response from requests.get
            filename: str
        """

        if not os.path.exists("data"):
            os.mkdir("data")
        with open(f"data/{filename}", 'w') as fp:
            json.dump(data.json(), fp)
Exemple #4
0
def getControllerDevices_request_to_data(
        r: requests.request) -> Tuple[list, list]:
    """
    From the controllers list to read, with SLV url and authentication, return a list of electric meters and their IDs
    in a tuple of the 2 lists.
    :param r: request from getControllerDevices
    :return: returns a tuple of two list containing the ElectricCounter names and their respective IDs.
    """
    output_json = r.json()  # get the json out of the request
    for controller in output_json:
        if controller[
                'categoryStrId'] == 'electricalCounter':  # all_counters_category =
            electric_counter_ID = controller[
                'id']  # find the electriccounter id
            electric_counter_str = controller[
                'controllerStrId']  # find the electriccounter strId
    return electric_counter_str, electric_counter_ID  # , all_counters_category
Exemple #5
0
def getAllControlers_request_to_data(
        r: requests.request) -> Tuple[list, list, list]:
    """
    Transform the input request, from getAllControllers function of SLV API to lists of interesting data for main script
    :param r: request from getAllControllers request.
    :return: a tuple of the lists of all controllers, all controllers ID and all geozones id.
    :rtype: tuple
    """
    output_json = r.json()  # get the data out of the request
    AllControllers = []  # initialize list of all controllers name
    ControllersID = []  # initialize list of all controllers ID
    GeoZoneId = []  # initialize list of all geo zones ID
    for elt in output_json:  # for each element in the data, add the appropriate element at the end of each list
        AllControllers.append(elt['controllerDevice']['controllerStrId'])
        ControllersID.append(elt['controllerDevice']['id'])
        GeoZoneId.append(elt['controllerDevice']['geoZoneId'])
    return AllControllers, ControllersID, GeoZoneId
Exemple #6
0
def home(request: requests.request) -> HttpResponse:
    ''' Doctor; kiosk office choice and interface path. The doctor chooses
        which office this tablet is running in. Two buttons then offer to
        run the tablet in Doctor mode; showing appointments for today, and
        Kiosk mode, letting patients check in. Form submission will POST
        to kiosk_path() which will redirect to the doctor or kiosk $home
    '''

    request.session['doctor'] = (
        Doctor
            .objects
            .get(user=UserSocialAuth.objects.get().user).id
    )

    data = {
        'offices': Office.objects.all(),
        'form': KioskSetupForm()
    }

    return render(request, 'home.html', data)
 def validate_response(self, _request: requests.request):
     _json = _request.json()
     if _request.status_code != 200:
         _error = _json["error"]
         _message = _error["message"]
         raise adnw_exception.HttpResponseError(_message)
     else:
         try:
             _data = _json["data"]
             if adnw_utils.is_list_empty(_data):
                 raise adnw_exception.InvalidQueryIdError(
                     "query id is invalid.")
             else:
                 for each in _data:
                     if each["status"] != "complete":
                         raise adnw_exception.ValidationError(
                             "Report is not ready in Backend, please retry later."
                         )
         except KeyError:
             return