Skip to content

Reduce API query if not needed #2

@Klausoleum

Description

@Klausoleum

I had another idea to reduce the API access to the tgtg server side and not to provoke the 403 error (capture).

Currently the tgtg api is queried every 60 seconds (default) regardless of the settings in Telegram (/settings).
Before you start the loop, you could query the settings whether information is desired. If no information is required, the API is not queried and tgtg does not notice the bot.

Here is an untested draft:

def get_available_items_per_user(self):
    while True:
        try:
            if any(val == 1 for user_settings in self.users_settings_data.values() for val in user_settings.values()):
                # Führe die Abfragen nur aus, wenn mindestens eine Einstellung aktiviert ist
                temp_available_items = {}
                for key in self.users_login_data.keys():
                    self.connect(key)
                    time.sleep(1)
                    available_items = self.get_favourite_items()
                    for item in available_items:
                        status = "null"
                        item_id = item['item']['item_id']
                        # ... (Code davor)
                        if not status == "null":
                            temp_available_items[item_id] = status
                        self.available_items_favorites[item_id] = item
                        if item_id in temp_available_items and \
                                self.users_settings_data[key][temp_available_items[item_id]] == 1:
                            # ... (Code davor)
                            self.send_message_with_link(key, text, item_id)
                self.save_available_items_favorites_to_txt()
            time.sleep(60)
        except Exception as err:
            print(f"Unexpected {err=}, {type(err)=}")```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions