diff --git a/snscrape/base.py b/snscrape/base.py index 37ab12d..9ee25a3 100644 --- a/snscrape/base.py +++ b/snscrape/base.py @@ -6,11 +6,23 @@ import json import logging import requests import time +import warnings logger = logging.getLogger(__name__) +class _DeprecatedProperty: + def __init__(self, name, repl, replStr): + self.name = name + self.repl = repl + self.replStr = replStr + + def __get__(self, obj, objType): + warnings.warn(f'{self.name} is deprecated, use {self.replStr} instead', FutureWarning, stacklevel = 2) + return self.repl(obj) + + def _json_serialise_datetime(obj): '''A JSON serialiser that converts datetime.datetime and datetime.date objects to ISO-8601 strings.''' if isinstance(obj, (datetime.datetime, datetime.date)): diff --git a/snscrape/modules/facebook.py b/snscrape/modules/facebook.py index f22b29a..b6d056b 100644 --- a/snscrape/modules/facebook.py +++ b/snscrape/modules/facebook.py @@ -7,7 +7,6 @@ import re import snscrape.base import typing import urllib.parse -import warnings logger = logging.getLogger(__name__) @@ -21,10 +20,7 @@ class FacebookPost(snscrape.base.Item): content: typing.Optional[str] outlinks: list - @property - def outlinksss(self): - warnings.warn('outlinksss is deprecated, use outlinks instead', FutureWarning) - return ' '.join(self.outlinks) + outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks') def __str__(self): return self.cleanUrl diff --git a/snscrape/modules/telegram.py b/snscrape/modules/telegram.py index b603913..57f7350 100644 --- a/snscrape/modules/telegram.py +++ b/snscrape/modules/telegram.py @@ -6,7 +6,6 @@ import re import snscrape.base import typing import urllib.parse -import warnings logger = logging.getLogger(__name__) @@ -30,10 +29,7 @@ class TelegramPost(snscrape.base.Item): outlinks: list linkPreview: typing.Optional[LinkPreview] = None - @property - def outlinksss(self): - warnings.warn('outlinksss is deprecated, use outlinks instead', FutureWarning) - return ' '.join(self.outlinks) + outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks') def __str__(self): return self.url diff --git a/snscrape/modules/twitter.py b/snscrape/modules/twitter.py index 9ed6bc0..d6ac2f1 100644 --- a/snscrape/modules/twitter.py +++ b/snscrape/modules/twitter.py @@ -12,7 +12,6 @@ import string import time import typing import urllib.parse -import warnings logger = logging.getLogger(__name__) @@ -41,20 +40,9 @@ class Tweet(snscrape.base.Item): quotedTweet: typing.Optional['Tweet'] = None mentionedUsers: typing.Optional[typing.List['User']] = None - @property - def username(self): - warnings.warn('username is deprecated, use user.username instead', FutureWarning) - return self.user.username - - @property - def outlinksss(self): - warnings.warn('outlinksss is deprecated, use outlinks instead', FutureWarning) - return ' '.join(self.outlinks) - - @property - def tcooutlinksss(self): - warnings.warn('tcooutlinksss is deprecated, use tcooutlinks instead', FutureWarning) - return ' '.join(self.tcooutlinks) + username = snscrape.base._DeprecatedProperty('username', lambda self: self.user.username, 'user.username') + outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks') + tcooutlinksss = snscrape.base._DeprecatedProperty('tcooutlinksss', lambda self: ' '.join(self.tcooutlinks), 'tcooutlinks') def __str__(self): return self.url