create account

Bot para hacer sorteos en Hive / Python + Beem by enrique89

View this thread on: hive.blogpeakd.comecency.com
· @enrique89 · (edited)
$23.55
Bot para hacer sorteos en Hive / Python + Beem
<center>![image.png](https://files.peakd.com/file/peakd-hive/enrique89/23x14cUVBPje5bjS8btYt52nwkkt29rrMzTeHuqx5MCfa8V1pbNxjg9dNB2YuSQanqy6q.png)</center>


Hola Hivers, saludos. 


Luego de tanto tiempo en espera para algunos amigos, he comenzado a liberar códigos, con la intensión de que los que saben programar les pueden resultar útiles para hacer algunas actividades dentro de la blockchain Hive y aportar herramientas para las comunidades. 


Debo resaltar que yo no soy programador, solo sé lo más básico, pero he podido a traves de python realizar algunas aplicaciones para conectarse a la blockchain Hive, luego voy a explicar en un post. 


Tengo pendiente publicar algunos códigos como el de @aliento que le paga a las personas que delegran, para que la comunidad la pueda usar. 


El código de sorteo es sumamente sencillo, al ejecutarse puede arrojar el resultado tomando como referencia una serie o lista de usuarios que comentan en un post, con el fin de hacer sorteos de manera aleatoria.


Está escrito en Python y se conecta a través de Hive con la librería de Beem. 

### ¿Qué necesitas para ejecutar este bot? 

Beem de Hive: https://github.com/holgern/beem [Sigue las instrucciones en el repositorio]

Python: https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe 


### ¿Cómo funciona?


El bot tiene 2 modalidades: La primera es elegir a un ganador y luego deja un comentario en el post donde queremos que se publique el ganador, para que la elección sea transparente, y la segunda es solo con la consola de python, solo la persona que ejecute el bot puede ver el resultado. 

wif: Allí colocarás tu clave de posting de la cuenta que hará el comentario.

comment: Allí colocas el post comenzando con el @ ejemplo: 
> @enrique89/hivechat-sorteo-por-los-100-hive-patrocinado-por-theycallmedan-3-ganadores 

El código es el siguiente  (copia y pega en tu editor de texto):

```
import random
import datetime
import random
import datetime

from beem.instance import set_shared_steem_instance
from beem.comment import Comment

from pprint import pprint
from beem import Hive
from beem.account import Account
from beem.vote import Vote
from beem.comment import Comment
from beemapi.exceptions import RPCError
from beemapi.exceptions import InvalidEndpointUrl
from beem.exceptions import ContentDoesNotExistsException
from datetime import datetime, timedelta
from beem.amount import Amount
from beem.nodelist import NodeList
from beem.instance import set_shared_steem_instance
from beem.instance import shared_hive_instance
from time import sleep
from beem.utils import construct_authorperm, addTzInfo



wif = "Key" # Colocar la clave publica 

hive = Hive(
    #bundle=True, # Enable bundle broadcast
    nobroadcast=True, # Habilitado para Test y si quieres conectar con la blockchain coloca False y bot funcionará normalmente.
    keys=[wif],
)


namehive = "votovzla"  # coloca tu usuario de Hive y dejar las comillas"


acc = Account(namehive , blockchain_instance=hive) 


#Extrae a los participantes mediante un post en Hive, debes añadir la lista de las personas que quieras que se excluyan"

def extraeruser():

    comment = Comment("@enrique89/hivechat-sorteo-por-los-100-hive-patrocinado-por-theycallmedan-3-ganadores")

    # lista de user excluidos 

    

    replies = comment.get_all_replies()
    participants = set()
    for r in replies:
    	listaexluir= ['hivebuzz', 'poshbot'] #Agrega la lista, los usuarios exluidos para el sorteo
    	if (r.author in listaexluir):

    		pass

    	else: 	
    		participants.add(r.author)

    participants = list(participants)

    return participants

# Elegir ganador

def ganador():

    extraer = extraeruser()
    win= random.choice(extraer)
    ganador = win
    return ganador 




def win():


	print("")
	for p in extraeruser():
	    print("- @%s" %p)
	print("")
	print("El ganador ha sido:")
	print("")

	ganadoruno = ganador()
	print (ganadoruno)
	print("")



	return ganadoruno













variable = 0  # Colocar 1 si no quieres dejar el comentario en la blockchain 

if variable == 1:

	print ('Ejecutar sin comentario')

	a = win()


	
else:

	print ('ejecutar con comentario')
	



	extraerganador = win()


	ganadores = (' El ganador es  @{}, este ganador a es elegido  a traves de un bot que se conecta con la blockchain Hive '.format(extraerganador) ) #Puedes personalizar el mensaje

	print(ganadores)



	comment = Comment("@enrique89/hivechat-sorteo-por-los-100-hive-patrocinado-por-theycallmedan-3-ganadores", blockchain_instance=hive) #Sustituir con el post en donde van a anuniciar el ganador

	sleep(5)

	comment.reply(ganadores, "", author = acc )
	pprint(hive.broadcast())




#fin  




```


Voy a adaptar este bot a Discord con otras funcionalidades para que cualquiera que no sepa de programación pueda realizar sorteos a través de la blockchain Hive y elegir al ganador de la manera más rápida.

Igualmente, está abierta la constribución, si eres programador y quiere mejorar el código, eres bienvenido. 



<center>Imagen usada en la portada [Ver en pixabay](https://pixabay.com/es/photos/loter%c3%ada-tour-figuras-2154610/) LIBRE DE DERECHO DE AUTOR</center>



<center>https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/enrique89/zLRXvucf-rect908.png</center>

<center> https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/enrique89/1wK1k8h4-rect4225.png </center>

👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 183 others
properties (23)
authorenrique89
permlinkbot-para-hacer-sorteo-en-hive
categoryspanish
json_metadata{"app":"peakd/2021.06.2","format":"markdown","tags":["spanish","python","beem","bot","hive"],"users":["aliento","enrique89"],"image":["https://files.peakd.com/file/peakd-hive/enrique89/23x14cUVBPje5bjS8btYt52nwkkt29rrMzTeHuqx5MCfa8V1pbNxjg9dNB2YuSQanqy6q.png","https://files.peakd.com/file/peakd-hive/enrique89/zLRXvucf-rect908.png","https://files.peakd.com/file/peakd-hive/enrique89/1wK1k8h4-rect4225.png"]}
created2021-06-16 06:24:09
last_update2021-06-16 06:24:54
depth0
children3
last_payout2021-06-23 06:24:09
cashout_time1969-12-31 23:59:59
total_payout_value11.890 HBD
curator_payout_value11.656 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,427
author_reputation600,207,252,457,300
root_title"Bot para hacer sorteos en Hive / Python + Beem"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id104,361,117
net_rshares53,955,158,245,157
author_curate_reward""
vote details (247)
@ecency ·
Your content has been **voted** as a part of [Encouragement program](https://ecency.com/ecency/@good-karma/encouragement-program-continues-82eafcd10a299). Keep up the good work! <br><br>Use Ecency daily to boost your growth on platform! <br><br><b>Support Ecency</b><br>[Vote for Proposal](https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B141%5D&approve=true)<br>[Delegate HP and earn more](https://ecency.com/hive-125125/@ecency/daily-100-curation-rewards)
properties (22)
authorecency
permlinkre-2021616t13611810z
categoryspanish
json_metadata{"tags":["ecency"],"app":"ecency/3.0.16-welcome","format":"markdown+html"}
created2021-06-16 13:06:12
last_update2021-06-16 13:06:12
depth1
children0
last_payout2021-06-23 13:06:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length474
author_reputation550,722,819,147,141
root_title"Bot para hacer sorteos en Hive / Python + Beem"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id104,366,192
net_rshares0
@fuerza-hispana ·
Muy buen post @enrique89, realmente será más fácil para los que hacen sorteos de este tipo. Gracias por el aporte.
properties (22)
authorfuerza-hispana
permlinkre-enrique89-qut6ww
categoryspanish
json_metadata{"tags":["spanish"],"app":"peakd/2021.06.2"}
created2021-06-16 19:17:24
last_update2021-06-16 19:17:24
depth1
children0
last_payout2021-06-23 19:17:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length114
author_reputation29,518,701,778,699
root_title"Bot para hacer sorteos en Hive / Python + Beem"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id104,372,397
net_rshares0
@sindetalles ·
>Voy a adaptar este bot a Discord con otras funcionalidades para que cualquiera que no sepa de programación pueda realizar sorteos a través de la blockchain Hive y elegir al ganador de la manera más rápida.

Que agradable que pienses en los que no sabemos NADA de programación. Gracias por esto.
properties (22)
authorsindetalles
permlinkre-enrique89-2021616t134640399z
categoryspanish
json_metadata{"tags":["spanish","python","beem","bot","hive"],"app":"ecency/3.0.17-vision","format":"markdown+html"}
created2021-06-16 17:46:42
last_update2021-06-16 17:46:42
depth1
children0
last_payout2021-06-23 17:46:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length295
author_reputation3,328,890,165,392
root_title"Bot para hacer sorteos en Hive / Python + Beem"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id104,370,890
net_rshares0