def do_query_all(xml_response_value):
            done = utils.get_element_by_name(xml_response_value, 'done')

            if done:
                return response
            else:
                query_locator = utils.get_element_by_name(
                    xml_response_value, 'queryLocator')

                result = self.query_more(query_locator)
                xml_result_value = xml.dom.minidom.parseString(result.text)

                done = utils.get_element_by_name(xml_result_value, 'done')
                total_size = utils.get_element_by_name(xml_result_value,
                                                       'totalSize')
                records = utils.get_element_by_name(xml_result_value,
                                                    'records')

                xml_response_value.getElementsByTagName('done').item(
                    0).firstChild.nodeValue = done
                xml_response_value.getElementsByTagName('totalSize').item(
                    0).firstChild.nodeValue += total_size
                xml_response_value.getElementsByTagName('records').appendChild(
                    records)

                return do_query_all(xml_response_value)
Ejemplo n.º 2
0
 def _generate_fix_day(self):
     for day in self.week:
         if day.fix_evening is not None:
             day.evening_dish = utils.get_element_by_name(
                 self._dishes_poll, day.fix_evening)
             self._dishes_poll.remove(day.evening_dish)
         if day.fix_noon is not None:
             day.noon_dish = utils.get_element_by_name(
                 self._dishes_poll, day.fix_noon)
             self._dishes_poll.remove(day.noon_dish)
Ejemplo n.º 3
0
    def authenticate(self):
        login_url = self.__get_token_endpoint()
        data = self.__get_params()
        headers = utils.xml_content_headers(len(data), "login")

        response = utils.send_request("POST", self.httplib, login_url, headers, data=data)

        xml_value = xml.dom.minidom.parseString(response.text)
        access_token = utils.get_element_by_name(xml_value, "sessionId")
        url = urlparse(utils.get_element_by_name(xml_value, "serverUrl"))
        instance_url = "{0}://{1}".format(url.scheme, url.netloc)

        return Authentication(access_token, instance_url)
Ejemplo n.º 4
0
    def authenticate(self):
        login_url = self.__get_token_endpoint()
        data = self.__get_params()
        headers = utils.xml_content_headers(len(data), 'login')

        response = utils.send_request('POST',
                                      self.httplib,
                                      login_url,
                                      headers,
                                      data=data)

        xml_value = xml.dom.minidom.parseString(response.text)
        access_token = utils.get_element_by_name(xml_value, 'sessionId')
        url = urlparse(utils.get_element_by_name(xml_value, 'serverUrl'))
        instance_url = '{0}://{1}'.format(url.scheme, url.netloc)

        return Authentication(access_token, instance_url)
Ejemplo n.º 5
0
 def _set_fix_days(self):
     for day in self.week:
         if day.fix_noon is not None:
             dish = utils.get_element_by_name(self.dishes, day.fix_noon)
             if dish.long_preparation:
                 self._long_preparation -= 1
             if dish.cold_meat:
                 self._max_cold_meat -= 1
             self._dishes_poll.append(dish)
             self.dishes.remove(dish)
         if day.fix_evening is not None:
             dish = utils.get_element_by_name(self.dishes, day.fix_evening)
             if dish.long_preparation:
                 self._long_preparation -= 1
             if dish.cold_meat:
                 self._max_cold_meat -= 1
             self._dishes_poll.append(dish)
             self.dishes.remove(dish)
Ejemplo n.º 6
0
    def setup(self):
        vegetarians = self._get_vegetarian_dishes()
        fishes = self._get_fish_dishes()
        min_vegetarian = utils.get_element_by_name(self.rules,
                                                   'min_vegetarian',
                                                   Rule(value=0))
        min_fish = utils.get_element_by_name(self.rules, 'min_fish',
                                             Rule(value=0))
        max_cold_meat = utils.get_element_by_name(self.rules, 'max_cold_meat',
                                                  Rule(value=7))

        self._max_cold_meat = max_cold_meat.value
        self._dishes_number, self._long_preparation = self._get_dishes_number_and_long_preparation(
        )
        self._min_rules(min_vegetarian.value, vegetarians)
        self._min_rules(min_fish.value, fishes)
        self._set_fix_days()

        if path.exists(self._save_file):
            with open("./{}".format(self._save_file), 'r') as file:
                save = json.loads(file.read())
                self.dishes = list(
                    filter(lambda x: x.name not in save, self.dishes))

        for i in range(len(self._dishes_poll) - 1, self._dishes_number):
            dish_is_ok = False
            while dish_is_ok is False:
                dish = utils.get_random_element(self.dishes)
                dish_is_ok = True
                if dish.long_preparation and self._long_preparation <= 0:
                    dish_is_ok = False
                elif dish.cold_meat and self._max_cold_meat <= 0:
                    dish_is_ok = False
                else:
                    if dish.long_preparation:
                        self._long_preparation -= 1
                    if dish.cold_meat:
                        self._max_cold_meat -= 1
            self._dishes_poll.append(dish)
            self.dishes.remove(dish)
        self._logger.info("Dishes poll:")
        for dish in self._dishes_poll:
            self._logger.info(dish)
        return self
        def do_query_all(xml_response_value):
            done = utils.get_element_by_name(xml_response_value, 'done')

            if done:
                return response
            else:
                query_locator = utils.get_element_by_name(xml_response_value, 'queryLocator')

                result = self.query_more(query_locator)
                xml_result_value = xml.dom.minidom.parseString(result.text.encode('utf-8'))

                done = utils.get_element_by_name(xml_result_value, 'done')
                total_size = utils.get_element_by_name(xml_result_value, 'totalSize')
                records = utils.get_element_by_name(xml_result_value, 'records')

                xml_response_value.getElementsByTagName('done').item(0).firstChild.nodeValue = done
                xml_response_value.getElementsByTagName('totalSize').item(0).firstChild.nodeValue += total_size
                xml_response_value.getElementsByTagName('records').appendChild(records)

                return do_query_all(xml_response_value)