x89 / Shreddit

Remove your comment history on Reddit as deleting an account does not do so.
Other
1k stars 134 forks source link

Error when calculating recent_cutoff #141

Open iamdadmin opened 5 years ago

iamdadmin commented 5 years ago
Traceback (most recent call last):
  File "/usr/local/bin/shreddit", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/shreddit/app.py", line 44, in main
    shredder = Shredder(default_config, args.user)
  File "/usr/local/lib/python2.7/dist-packages/shreddit/shredder.py", line 33, in __init__
    self._recent_cutoff = arrow.now().replace(hours=-self._hours)
  File "/usr/local/lib/python2.7/dist-packages/arrow/arrow.py", line 590, in replace
    raise AttributeError('unknown attribute: "{}"'.format(key))
AttributeError: unknown attribute: "hours"

I tried to refactor to use timedelta instead but I really don't know what I'm doing (I'm more of a PHP guy) and this error still ends up being thrown.

When I installed it, the following versions of the dependencies were installed arrow-0.14.5 backports-abc-0.5 backports.functools-lru-cache-1.5 futures-3.3.0 idna-2.7 praw-6.3.1 prawcore-1.0.1 python-dateutil-2.8.0 shreddit-6.0.7 singledispatch-3.4.0.3 tornado-5.1.1 update-checker-0.16 websocket-client-0.56.0

Is this something changed in arrow that's impacting the script?

iamdadmin commented 5 years ago

I tried this on the following environments:

python 2.7 on LXSS (Ubuntu on Windows 10) python 3.7 on Windows 10 python 2.7 on Debian Stretch

All give identical error.

iamdadmin commented 5 years ago

Lines 589 and 590

            elif key != "tzinfo":
                raise AttributeError('unknown attribute: "{}"'.format(key))

Full routine from arrow.py

    def replace(self, **kwargs):
        """ Returns a new :class:`Arrow <arrow.arrow.Arrow>` object with attributes updated
        according to inputs.

        Use property names to set their value absolutely::

            >>> import arrow
            >>> arw = arrow.utcnow()
            >>> arw
            <Arrow [2013-05-11T22:27:34.787885+00:00]>
            >>> arw.replace(year=2014, month=6)
            <Arrow [2014-06-11T22:27:34.787885+00:00]>

        You can also replace the timezone without conversion, using a
        :ref:`timezone expression <tz-expr>`::

            >>> arw.replace(tzinfo=tz.tzlocal())
            <Arrow [2013-05-11T22:27:34.787885-07:00]>

        """

        absolute_kwargs = {}

        for key, value in kwargs.items():

            if key in self._ATTRS:
                absolute_kwargs[key] = value
            elif key in ["week", "quarter"]:
                raise AttributeError("setting absolute {} is not supported".format(key))
            elif key != "tzinfo":
                raise AttributeError('unknown attribute: "{}"'.format(key))

        current = self._datetime.replace(**absolute_kwargs)

        tzinfo = kwargs.get("tzinfo")

        if tzinfo is not None:
            tzinfo = self._get_tzinfo(tzinfo)
            current = current.replace(tzinfo=tzinfo)

        return self.fromdatetime(current)
this-user commented 5 years ago

The issues lies with the latest version of the 'Arrow' library that has removed deprecated functionality that Shreddit was still using. I have replaced the removed call with the correct one, and it seems to be working again. PR #142

iamdadmin commented 5 years ago

Tested and can confirm the workaround does it, hopefully when it's released next it'll backfill to everyone else also.

e-m-m-a commented 5 years ago

How can I apply this latest workaround? My new install of shreddit is failing with this error. Thanks.

iamdadmin commented 5 years ago

@e-m-m-a The patch is detailed here https://github.com/x89/Shreddit/pull/142/commits/5af09bfd372ce77622f17f4e4e3f49a20516c369 - you need to locate and manually edit shredder.py finding lines 33 and 34, and changing "replace" to "shift".

I also deleted shredder.pyc (the compiled code) in the same folder just to force it to re-compile.

e-m-m-a commented 5 years ago

Done - working. Thanks so much. I love shreddit.