The Global Hive Blacklist is BACK!!...not quite lol!!

Whoever has an accout on Hive for some time will probably have heard at least once the controversial Global Hive Blacklist.
A huge list, union of all existing blacklists on Hive.

Understood by a few, loved by a very few and hated by many.
The Poor Global Hive Blacklist, born with the noble intent to safeguard our dear Blockchain from bad users, has arrived at the end of his life.
Or rather the Global Blacklist API managed by @themarkarkmark is no longer running.
With this API it was possible to check with a couple of clicks if a Hive user was part of some blacklists such as spaminator, buildawhale, hivewatchers etc. etc.
Very useful for those who do curation on Hive.

For our @discovery-it curators team the Global Blacklist API was very important, in fact our bot called "discoBOT" :) with a simple query was able to automatically check if the authors chosen by the curators were part of some blacklists. And in the affirmative case the bot did not upvote the post in question.

Fortunately despite the closure of the service we managed to recover the blacklist, a huge JSON file containing about 85000 accounts, which is now examined directly by discoBOT.

You can find a copy of this blacklist here on Github.

In this post I want to share with you the simple but operative solution that I found to run the bot without the need to occupy the program memory with the entire list.

Simply, instead of loading the JSON file into a variable, I created a SQLite database that remains outside the code and allow the scrypt to interact to it quickly and safely.

Discobot is written in Python and interacts with our Blockchain thanks to the Beem library of @holger80.
I take this opportunity to thank him for the fundamental contribution he brings to Hive.

Let's talk about the code:

To be able to use a SQLite database in a Python scrypt you must first import the sqlite3 library within the code.

import sqlite3

Then you need to create a connection with the database. If as in this case, the database still does not exist, don't worry the following line of code will create an empty one inside the current folder.
To do this I have defined a variable conn and used the connect() method from the sqlite3 library.
The name I chose for the database is black.db

conn = sqlite3.connect("black.db")

For this specific database, I decided to create a table called BLACK with a single column of textual values called NAME. Normally databases are rather complicated objects, thanks to tables and columns they can store a lot of different information, such as: name, surname, sex, age, job, etc. etc.
But in this case the only information I needed is whether a given account is part of the blacklist. So the single NAME column which contains all the accounts is more than enough for my purpose.
I used the execute() method to create the table called BLACK.

conn.execute("CREATE TABLE BLACK (NAME TEXT   NOT NULL);")

Now one needs to fill the database with the list of users.
The list is a simple array contained in a json Blacklist.json file, so you need to import the json library and define a variable to store its contents.

import json
black_list = json.load(open('Blacklist.json'))

For each blacklist user I have created an INSERT query
and with a for cycle I ran them all in the database. Finally I used the commit() method, to load the data permanently and the close() method to close the connection.

for name in black_list:
    query = "INSERT INTO BLACK (NAME) VALUES ('"+name+"');"
    conn.execute(query)

conn.commit()
conn.close()

Well at this point the black.db database is ready to be used.

Remains to show you the piece of code I added to discoBOT

For simplicity, the nick variable will represent the author of a post selected by a curator. My goal is to know if that author is blacklisted or not, so just do a SELECT query like this: SELECT NAME FROM BLACK WHERE NAME = nick. If the author belongs to the blacklist then the query will return the author's name otherwise it will return a null value.
To distinguish the 2 cases I used an if on the length of the output obtained using the fetchall() method of the cursor() class which produces an array as a response.
Therefore, since the output is an array, if the value is null, the array will be an empty array and therefore of zero length. In this case len(result) will be equal to zero.

# Previous Code 

query = "SELECT NAME FROM BLACK WHERE NAME = '"+nick+"'"

conn = sqlite3.connect('black.db')
cursor = conn.cursor()
cursor.execute(query)

result = cursor.fetchall()
conn.close()

if len(result) > 0:
    # the author is on the blacklist
    # do nothing or scold the curator!! :)
else:
    # the author is NOT on the blacklist
    # vote , comment , follow , spread love , smoke weed!!!

Well and with this I leave you for today. Bye Bye!!


ITA

Chi bazzica su Hive da qualche tempo avrà probabilmente sentito nominare almeno una volta la controversa e famigerata Global Hive Blacklist.
Una lista enorme, unione di tutte le blacklist esistenti su Hive.

Compresa da pochi, amata da pochissimi e odiata da molti.
La povera Global Hive Blacklist, nata con il nobile intento di salvaguardare la nostra cara blockchain da utenti maleintenzionati, è arrivata a termine della sua vita.
O meglio la Global Blacklist API gestita da @themarkymark non è più in funzione.
Con questa Api era possibile controllare con un paio di click se un utente di Hive faceva parte di qualche blacklist come quelle di Spaminator, BuildAWhale, HiveWatchers ecc ecc.
Molto utile per chi fa curation su Hive.

Per il nostro team di curatori di @discovery-it la Global Blacklist API era molto importante, infatti il nostro bot chiamato "discoBOT" :) con una semplice query controllava in automatico se gli autori scelti dai curatori facevano parte di qualche blacklist. E in caso affermativo il bot non curava il post in questione.

Fortunatamente nonostante la chiusura del servizio siamo riusciti a recuperare la blacklist, un file JSON enorme contenente circa 85000 account, il quale ora viene esaminato direttamente da discoBOT.

Potete trovare una copia di questa blacklist qui su Github.

In questo post volevo condividere con voi la soluzione seppur semplice ma efficace che ho trovato per far girare il bot senza il bisogno di occupare la memoria del programma con l'intera lista.

Semplicemente invece di caricare il file JSON in una variabile, ho creato un database SQLite che rimane esterno al codice e con cui lo scrypt può interagire in maniera rapida e sicura.

DiscoBot è scritto in python e interagisce con la nostra blockchain grazie alla libreria Beem di @holger80.
Colgo l'occasione per ringraziarlo per il fondamentale contributo che porta ad Hive.

Passo ora a parlarvi del codice:

Per poter utilizzare un database SQLite in uno scrypt python bisogna innanzitutto importare la libreria sqlite3 all'interno del codice.

import sqlite3

Poi bisogna creare una connessione con il database. Se come in questo caso, il database ancora non esiste, non vi preoccupate la seguente riga di codice ne creerà uno vuoto all'interno della cartella di lavoro.
Per fare questo ho definito una variabile conn e utilizzato il metodo connect() della libreria sqlite3.
Il nome che ho scelto per il database è black.db

conn = sqlite3.connect("black.db")

Per questo database in particolare, ho deciso di creare una tabella chiamata BLACK con un'unica colonna di valori testuali chiamata NAME. Normalmente i database sono oggetti piuttosto complicati, grazie a tabelle e colonne possono archiviare molte informazioni differenti, come ad esempio: nome, cognome, sesso, età, lavoro, ecc ecc.
Ma in questo caso l'unica informazione che mi serviva è se un dato account fa parte della blacklist. Quindi la sola colonna NAME che contiene tutti gli account è più che sufficiente per il mio scopo.
Ho utilizzato il metodo execute() per creare la tabella chiamata BLACK.

conn.execute("CREATE TABLE BLACK (NAME TEXT   NOT NULL);")

Adesso bisogna riempire il database con la lista degli utenti.
La lista è un semplice array contenuto in un file json Blacklist.json , bisogna quindi importare la libreria json e definire una variabile per memorizzarne il contenuto.

import json
black_list = json.load(open('Blacklist.json'))

Per ogni utente della blacklist ho creato una query INSERT
e con un cliclo for le ho eseguite tutte nel database. Infine ho utilizzato il metodo commit(), per caricare i dati in maniera definitiva e il metodo close() per chiudere la connessione.

for name in black_list:
    query = "INSERT INTO BLACK (NAME) VALUES ('"+name+"');"
    conn.execute(query)

conn.commit()
conn.close()

Bene arrivati a questo punto il database black.db è pronto per essere usato.

Mi resta da mostrare la parte di codice che ho aggiunto a discoBOT.

Per semplicità la variabile nick rappresenterà l'autore di un post selezionato da un curatore. Il mio obiettivo è sapere se quell'autore fa parte della blacklist o meno, quindi basterà fare una query SELECT di questo tipo: SELECT NAME FROM BLACK WHERE NAME = nick. Se l'autore appartiene alla blacklist la query restituirà il nome dell'autore altrimenti restituirà un valore nullo.
Per distinguere i 2 casi ho usato un if sulla lunghezza dell'output ottenuto utilizzato il metodo fetchall() della classe cursor() che produce un array come risposta.
Dunque essendo l'output un array, se il valore è nullo, l'array sarà un array vuoto e quindi di lunghezza zero. In questo caso len(result) sarà uguale a zero.

# Previous Code 

query = "SELECT NAME FROM BLACK WHERE NAME = '"+nick+"'"

conn = sqlite3.connect('black.db')
cursor = conn.cursor()
cursor.execute(query)

result = cursor.fetchall()
conn.close()

if len(result) > 0:
    # the author is on the blacklist
    # do nothing or scold the curator!! :)
else:
    # the author is NOT on the blacklist
    # vote , comment , follow , spread love , smoke weed!!!

Bene e con questo vi saluto. Ciao ciao!!


I'm a member of the Discovery-it Witness Team

Vote for Us as Witness!
Join our community!

H2
H3
H4
3 columns
2 columns
1 column
15 Comments
Ecency