parent
e97840b00d
commit
30833d0717
|
@ -0,0 +1,9 @@
|
|||
|
||||
install:
|
||||
python3 setup.py install
|
||||
|
||||
build:
|
||||
python3 setup.py sdist
|
||||
|
||||
upload:
|
||||
twine upload dist/*
|
|
@ -44,6 +44,7 @@ async def text_parser(status: Blacklist):
|
|||
return text
|
||||
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
loop.close()
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
loop.close()
|
|
@ -0,0 +1,47 @@
|
|||
from spamprotection.sync import SPBClient
|
||||
from spamprotection.types import Blacklist
|
||||
|
||||
# initializing the client
|
||||
client = SPBClient()
|
||||
|
||||
|
||||
def main():
|
||||
# calling for status
|
||||
user = input("Enter a Username or UserID to check Spam Prediction on SPB: ")
|
||||
status = client.check_blacklist(user)
|
||||
# check if status got a successful response
|
||||
if status.success:
|
||||
print((text_parser(status)))
|
||||
else:
|
||||
print("Polish Cow did not Approve this!")
|
||||
|
||||
|
||||
def text_parser(status: Blacklist):
|
||||
text = "Private TelegramID: {}\n".format(status.private_telegram_id)
|
||||
text += "Entity Type: {}\n".format(status.entity_type)
|
||||
if status.attributes.is_blacklisted:
|
||||
text += "Blacklist Flag: {}\n".format(status.attributes.blacklist_flag)
|
||||
text += "Blacklist Reason: {}\n".format(status.attributes.blacklist_reason)
|
||||
text += "Original PrivateID: {}\n".format(status.attributes.original_private_id)
|
||||
if status.attributes.is_potential_spammer:
|
||||
text += "This user is a Spammer\n"
|
||||
if status.attributes.is_operator:
|
||||
text += "This user is an Operator\n"
|
||||
if status.attributes.is_agent:
|
||||
text += "This user is an Agent\n"
|
||||
if status.attributes.is_whitelisted:
|
||||
text += "This user is Whitelisted\n"
|
||||
if status.attributes.intellivoid_accounts_verified:
|
||||
text += "This user is an Intellivoid Verified Account\n"
|
||||
if status.attributes.is_official:
|
||||
text += "This is an Official Account\n"
|
||||
text += "Language: {}\n".format(status.language_prediction.language)
|
||||
text += "Language Probability: {}\n".format(status.language_prediction.probability)
|
||||
text += "Ham Prediction: {}\n".format(status.spam_prediction.ham_prediction)
|
||||
text += "Spam Prediction: {}\n".format(status.spam_prediction.spam_prediction)
|
||||
text += "Last Updated On: {}\n".format(status.last_updated)
|
||||
return text
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,3 +1,3 @@
|
|||
aiohttp==3.7.3
|
||||
asyncio==3.4.3
|
||||
attrdict==2.0.1
|
||||
requests==2.20
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
aiohttp==3.7.3
|
||||
asyncio==3.4.3
|
||||
requests==2.20
|
||||
twine==3.3.0
|
1
setup.py
1
setup.py
|
@ -21,6 +21,7 @@ setuptools.setup(
|
|||
url="https://github.com/pokurt/intellivoid-spam-protection",
|
||||
packages=setuptools.find_packages(),
|
||||
classifiers=[
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
],
|
||||
install_requires=dependencies,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
from .client import SPBClient # noqa: F401
|
||||
|
||||
__version__ = "0.0.2"
|
||||
__version__ = "0.0.3"
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import requests
|
||||
|
||||
from .errors import UnknownError
|
||||
from .types import Blacklist
|
||||
|
||||
from json import JSONDecodeError
|
||||
from typing import Union
|
||||
|
||||
|
||||
class SPBClient:
|
||||
def __init__(
|
||||
self, *, host: str = "https://api.intellivoid.net/spamprotection/v1/lookup"
|
||||
) -> None:
|
||||
self._host = host
|
||||
|
||||
def do_request(self, user_id: str, method: str = "get"):
|
||||
request = requests.get(f"{self._host}?query={user_id}")
|
||||
try:
|
||||
return request.json(), request
|
||||
except JSONDecodeError:
|
||||
return request.text(), request
|
||||
|
||||
def raw_output(self, user_id: Union[int, str]) -> Union[Blacklist, bool]:
|
||||
try:
|
||||
data, _ = self.do_request(user_id)
|
||||
return data
|
||||
except UnknownError:
|
||||
return False
|
||||
|
||||
def check_blacklist(self, user_id: Union[int, str]) -> Union[Blacklist, bool]:
|
||||
try:
|
||||
data, _ = self.do_request(user_id)
|
||||
return Blacklist(**data)
|
||||
except UnknownError:
|
||||
return False
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from attrdict import AttrDict
|
||||
from .utils import attrdict
|
||||
|
||||
|
||||
class SPB:
|
||||
def __str__(self) -> str:
|
||||
|
@ -13,9 +14,12 @@ class Blacklist(SPB):
|
|||
def __init__(self, success: bool, response_code: int, results=dict, **kwargs):
|
||||
self.success = success
|
||||
self.response_code = response_code
|
||||
try:
|
||||
self.private_telegram_id = results["private_telegram_id"]
|
||||
self.entity_type = results["entity_type"]
|
||||
self.attributes = AttrDict(results["attributes"])
|
||||
self.language_prediction = AttrDict(results["language_prediction"])
|
||||
self.spam_prediction = AttrDict(results["spam_prediction"])
|
||||
self.attributes = attrdict(results["attributes"])
|
||||
self.language_prediction = attrdict(results["language_prediction"])
|
||||
self.spam_prediction = attrdict(results["spam_prediction"])
|
||||
self.last_updated = datetime.fromtimestamp(results["last_updated"])
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class attrdict(dict):
|
||||
def __init__(self, *args, **kwargs):
|
||||
dict.__init__(self, *args, **kwargs)
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self[name]
|
Loading…
Reference in New Issue