Python-Spamprotection-API/examples/async_example.py

51 lines
2.0 KiB
Python
Raw Normal View History

2021-01-02 06:08:55 +01:00
from spamprotection import SPBClient
from spamprotection.types import Blacklist
import asyncio
# initializing the client
client = SPBClient()
async def main():
# calling for status
user = input("Enter a Username or UserID to check Spam Prediction on SPB: ")
status = await client.check_blacklist(user)
# check if status got a successful response
if status.success:
print((await text_parser(status)))
else:
print("Polish Cow did not Approve this!")
async def text_parser(status: Blacklist):
text = "Private TelegramID: {}\n".format(status.private_telegram_id)
text += "Entity Type: {}\n".format(status.entity_type)
2021-01-02 09:03:20 +01:00
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:
2021-01-02 06:08:55 +01:00
text += "This user is a Spammer\n"
2021-01-02 09:03:20 +01:00
if status.attributes.is_operator:
2021-01-02 06:08:55 +01:00
text += "This user is an Operator\n"
2021-01-02 09:03:20 +01:00
if status.attributes.is_agent:
2021-01-02 06:08:55 +01:00
text += "This user is an Agent\n"
2021-01-02 09:03:20 +01:00
if status.attributes.is_whitelisted:
2021-01-02 06:08:55 +01:00
text += "This user is Whitelisted\n"
2021-01-02 09:03:20 +01:00
if status.attributes.intellivoid_accounts_verified:
2021-01-02 06:08:55 +01:00
text += "This user is an Intellivoid Verified Account\n"
2021-01-02 09:03:20 +01:00
if status.attributes.is_official:
2021-01-02 06:08:55 +01:00
text += "This is an Official Account\n"
2021-01-02 09:03:20 +01:00
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)
2021-01-02 06:08:55 +01:00
text += "Last Updated On: {}\n".format(status.last_updated)
return text
2021-01-02 10:09:20 +01:00
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()