ryanjgallagher / focalevents

Tools for collecting social media data around focal events
MIT License
84 stars 15 forks source link

n_zeros circular reference? #3

Closed asmithh closed 3 years ago

asmithh commented 3 years ago

https://github.com/ryanjgallagher/focalevents/blob/22afb52a4c6b7a3d38a73d4cf70b993db4311546/twitter/search.py#L555

Here's my error message:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/a404/ivermectin/focalevents/twitter/search.py", line 769, in <module>
    main(args.event,
  File "/Users/a404/ivermectin/focalevents/twitter/search.py", line 689, in main
    search =SearchListener(event=event,
  File "/Users/a404/ivermectin/focalevents/twitter/search.py", line 273, in __init__
    self.update_query()
  File "/Users/a404/ivermectin/focalevents/twitter/search.py", line 555, in update_query
    pad_num = str(self.query_number).zfill(self.n_zeros)
AttributeError: 'SearchListener' object has no attribute 'n_zeros'

I think that when we call self.update_query() in some cases we're referencing the parameter n_zeros before it's assigned to the SearchListener? Not sure if that's intentional behavior; happy to help fix if it isn't.

ryanjgallagher commented 3 years ago

Hmm I'm having a hard time figuring out why this might be happening.

On line 277 during the initialization of the object, self.n_zeros is initialized if we're getting counts.

https://github.com/ryanjgallagher/focalevents/blob/22afb52a4c6b7a3d38a73d4cf70b993db4311546/twitter/search.py#L275-L277

Since the code has to have self.get_counts=True on line 547 to get to line 555, I'm not seeing how self.n_zeros couldn't be set for the object.

Just to check, your command for running this looked something like python -m twitter.search ivermectin --get_counts?

asmithh commented 3 years ago

I think what is going on is that we can't get to that line yet because we're calling self.update_query() at line 273, before we even get to that conditional. I think that in turn needs self.n_zeros to have a value, which hasn't been assigned yet if this is the first command you run. So maybe it's a weird edge case?

I did run python -m twitter.search ivermectin --get_counts and maybe it's worth noting that that was the first command I tried. That could have something to do with it. Sorry this is behaving so weirdly for me!!

ryanjgallagher commented 3 years ago

🤦 You're right, that's what I get for trying to look at code first thing in the morning.

Thanks for catching this, it should be fixed now if you pull the latest commit (c1f3807b9c9fdb786bdffe1483fda0ed5880801a). Let me know if run into any other trouble!