From 914307f2863c6ebe6db47fc06d5dadcccaf20b6f Mon Sep 17 00:00:00 2001 From: CYBERDEViLNL Date: Fri, 2 Nov 2018 01:14:55 +0100 Subject: [PATCH] * Dropped pytz support, `dateutil` version 2.2 or higher is now required. * Removed some `print()`'s here and there to stop some console spamming. * Removed `Post()`'s `update()` method since it's deprecated for a while now. * Small manual adjustment. * Updated `README.md`, `setup.py` and `requirements.txt` to the new requirements. * Added `optional-requirements.txt` since BS4 is optional. Reviews are welcome for those who see this :-) --- README.md | 8 ++++++++ diaspy/models.py | 11 +---------- diaspy/settings.py | 1 - diaspy/streams.py | 27 +++++---------------------- manual/posting.markdown | 2 +- optional-requirements.txt | 1 + requirements.txt | 1 + setup.py | 5 ++++- 8 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 optional-requirements.txt diff --git a/README.md b/README.md index ea51342..d135fbf 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,14 @@ Version: 3.3.3 Version: 2.1.0 [Website](http://docs.python-requests.org/en/latest/) +**`python-dateutil`** + +Version: >= 2.2 +[Website](https://github.com/dateutil/dateutil) + +*Optional:* **`python-beautifulsoup4`** +[Website](https://www.crummy.com/software/BeautifulSoup/) + ---- diff --git a/diaspy/models.py b/diaspy/models.py index e431665..e1418b9 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -14,7 +14,7 @@ try: from bs4 import BeautifulSoup except ImportError: import re - print("BeautifulSoup not found, falling back on regex.") + print("[diaspy] BeautifulSoup not found, falling back on regex.") else: BS4_SUPPORT=True from diaspy import errors @@ -111,7 +111,6 @@ class Aspect(): membership_id = None to_remove = None for each in user.aspectMemberships(): - print(self.id, each) if each.get('aspect', {}).get('id') == self.id: membership_id = each.get('id') to_remove = each @@ -555,14 +554,6 @@ class Post(): else: self.comments.set([Comment(c) for c in request.json()]) - def update(self): - """Updates post data. - FIXME This is deprecated. - """ - print('diaspy.models.Post.update() is deprecated. Use diaspy.models.Post.update() instead.') - self._fetchdata() - self._fetchcomments() - def fetch(self, comments = False): """Fetches post data. Use this function instead of diaspy.models.Post.update(). diff --git a/diaspy/settings.py b/diaspy/settings.py index 5d1cdf4..8d88f31 100644 --- a/diaspy/settings.py +++ b/diaspy/settings.py @@ -297,7 +297,6 @@ class Profile(): """ if not self._loaded: raise errors.DiaspyError('profile was not loaded') self.data['authenticity_token'] = repr(self._connection) - print(self.data) request = self._connection.post('profile', data=self.data, allow_redirects=False) return request.status_code diff --git a/diaspy/streams.py b/diaspy/streams.py index b00139c..02c1ca5 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -12,28 +12,14 @@ from diaspy.models import Post, Aspect from diaspy import errors """ -Remember created_at is in UTC so I found two options to -convert/parse it to UTC timestamp: dateutil or pytz (found some -more but those libs aren't in default repo of main distro's) +Remember created_at is in UTC We need this to get a UTC timestamp from the latest loaded post in the stream, so we can use it for the more() function. """ -try: - import dateutil.parser - def parse_utc_timestamp(date_str): - return round(dateutil.parser.parse(date_str).timestamp()) - -except ImportError: - try: - from datetime import datetime - from pytz import timezone - def parse_utc_timestamp(date_str): - return round(datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone('UTC')).timestamp()) - - except ImportError: - print("Please install either python-dateutil or python-pytz") - exit # TODO raise exception +import dateutil.parser +def parse_utc_timestamp(date_str): + return round(dateutil.parser.parse(date_str).timestamp()) class Generic(): """Object representing generic stream. @@ -90,7 +76,6 @@ class Generic(): else: self.latest += 1 params['max_time'] = max_time params['_'] = self.latest - print("Diaspy _obtain.params: {}".format(params)) request = self._connection.get(self._location, params=params) if request.status_code != 200: raise errors.StreamError('wrong status code: {0}'.format(request.status_code)) @@ -213,13 +198,11 @@ class Generic(): self.more(backtime=backtime) if len(oldstream) < len(self): continue # but if no posts were found start retrying... - print('retrying... {0}'.format(retry)) + print('[diaspy] retrying... {0}'.format(retry)) n = retry while n > 0: - print('\t', n, self.max_time) # try to get even more posts... self.more(backtime=backtime) - print('\t', len(oldstream), len(self)) # check if it was a success... if len(oldstream) < len(self): # and if so restore normal order of execution by diff --git a/manual/posting.markdown b/manual/posting.markdown index e82c126..4c3ea76 100644 --- a/manual/posting.markdown +++ b/manual/posting.markdown @@ -72,7 +72,7 @@ If you liked this post you can call `delete_like()` to undo that. By default it returns the **author** `name`. As parameter you can give another key like **`id`**, **`guid`**, **`diaspora_id`** or -**`avatar`**. +**`avatar`**. *Note*: parameter is expected to be a `str`. ---- diff --git a/optional-requirements.txt b/optional-requirements.txt new file mode 100644 index 0000000..c1f5f71 --- /dev/null +++ b/optional-requirements.txt @@ -0,0 +1 @@ +beautifulsoup4 diff --git a/requirements.txt b/requirements.txt index 9ab798d..d376c64 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ diaspy requests==1.1.0 +dateutil>=2.2 diff --git a/setup.py b/setup.py index dfae73e..3f06a30 100644 --- a/setup.py +++ b/setup.py @@ -21,5 +21,8 @@ setup( 'Topic :: Utilities', ], packages=find_packages(), - install_requires=['requests'] + install_requires=['requests', 'dateutil'] + extras_require={ + 'beautifulsoup4': ["beautifulsoup4>=3.2.1"] + } ) -- 2.25.1