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

Error when calculating recent_cutoff #141

Open
iamdadmin opened this issue Aug 12, 2019 · 7 comments
Open

Error when calculating recent_cutoff #141

iamdadmin opened this issue Aug 12, 2019 · 7 comments

Comments

@iamdadmin
Copy link

iamdadmin commented Aug 12, 2019

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
Copy link
Author

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
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

e-m-m-a commented Aug 26, 2019

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

@iamdadmin
Copy link
Author

iamdadmin commented Aug 26, 2019

@e-m-m-a The patch is detailed here 5af09bf - 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
Copy link

e-m-m-a commented Aug 26, 2019

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

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

No branches or pull requests

3 participants