mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-06-08 02:28:29 +03:00
Refactor deprecated properties
This commit is contained in:
@@ -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)):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user