Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: NoneType error when adding new query #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jaco-99
Copy link
Contributor

@jaco-99 jaco-99 commented Dec 29, 2024

Issue

This PR addresses issue #38.
When attempting to add a new query in certain situations, the following error is raised: AttributeError: 'NoneType' object has no attribute 'get'.

The error can occur for two reasons:

  1. Attempting to add a query that was previously added but with different parameters (e.g., without the --minPrice and --maxPrice arguments):
$ python3 subito-searcher.py --add RTX_2060_Super --url "https://www.subito.it/annunci-italia/vendita/elettronica/?q=super+2060" --minPrice 0 --maxPrice 110
2024-12-29, 17:45:40 running query ("RTX_2060_Super" - https://www.subito.it/annunci-italia/vendita/elettronica/?q=super+2060)...

2024-12-29, 17:45:45 New search added: RTX_2060_Super
2024-12-29, 17:45:45 Adding result: GTX 1060 6GB MSI OC EDITION Scheda Video - 100 - Santa Maria Capua Vetere (CE)
2024-12-29, 17:45:45 Query added.

$ python3 subito-searcher.py --add RTX_2060_Super --url "https://www.subito.it/annunci-italia/vendita/elettronica/?q=super+2060"
2024-12-29, 17:45:50 running query ("RTX_2060_Super" - https://www.subito.it/annunci-italia/vendita/elettronica/?q=super+2060)...
Traceback (most recent call last):
  File "/.../subito-it-searcher/subito-searcher.py", line 335, in <module>
    run_query(args.url, args.name, False, args.minPrice if args.minPrice is not None else "null", args.maxPrice if args.maxPrice is not None else "null",)
  File "/.../subito-it-searcher/subito-searcher.py", line 227, in run_query
    if not queries.get(name).get(url).get(minPrice).get(maxPrice).get(link):   # found a new element
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
  1. Adding a new query where the first product identified on the website has already been sold. This error seems to have been the issue encountered in PR Impossibile aggiungere prodotti da tracciare #38.
    The error occurs because the query being accessed in the dictionary had not yet been added. The problematic code is shown below:
# check if the product has already been sold
if sold != None:
    # if the product has previously been saved remove it from the file
    if queries.get(name).get(url).get(minPrice).get(maxPrice).get(link): # ON THIS LINE
        del queries[name][url][minPrice][maxPrice][link]
        products_deleted = True
    continue

Solution

This PR aim to resolve both issues by recreating the query every time the user uses the --add and --url arguments to add a new one, even if a query with the same name already exists. This ensures that updated parameters are correctly applied (1), and the query is properly initialized before accessing it (2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant