update for beem: create posts more easily and draw pseudo-random numbers
hive-139531·@holger80·
0.000 HBDupdate for beem: create posts more easily and draw pseudo-random numbers
## Repository
https://github.com/holgern/beem<center>

</center>
[beem](https://github.com/holgern/beem) is a python library and command line tool for HIVE. The current version is 0.23.11.
There is also a discord channel for beem: https://discord.gg/4HM592V
The newest beem version can be installed by:
```
pip install -U beem
```
Check that you are using hive nodes. The following command
```
beempy updatenodes --hive
```
updates the nodelist and uses only hive nodes. After setting hive as default_chain, `beempy updatenodes` can be used.
The list of nodes can be checked with
```
beempy config
```
and
```
beempy currentnode
```
shows the currently connected node.
## Changelog for versions 0.23.10
* get_node_answer_time added to NodeList
* New node added
* new stored parameter: default_canonical_url
* beempy notifications sorting is reversed, a new parameter can be used to change the sorting
* New beempy createpost command, it can be used to create an empty markdown file with YAML header for a new post
* beempy post has now a canonical_url parameter, when not set, default_canonical_url is set
* New beempy draw command, can be used to generate pseudo-random number from block identifiers using hashsums
* remove enum34 dependency
## Changelog for version 0.23.11
* replace asn1 by asn1crypto
## Setting canonical URLs when posting with beempy
The `canonical_url` field in the json_metadata of a post is part of an open standard that defines which canonical URL should be set by all hive front-ends.
The canonical URL is then parsed by the search engines and shown in search results.
A default canonical URL can now be set with
```
beemy set default_canonical_url https://hive.blog
````
When not modified, `https://hive.blog` is the default value. When posting now with `beempy post` this canonical URL is set in the json_metadata field.
It is also possible to set a canonical URL by:
```
beempy post --canonical-url https://hive.blog my_post.md
```
## Create a new markdown file for posting
The following command
```
beempy createpost my_new_post.md
```
can be used to create an empty markdown file with a YAML header.
After executing the command, beempy asks the following questions:

and creates the following YAML header in the created markdown file:

## Draw pseudo-random numbers and post the result as a comment
`beempy draw` can be used to generate pseudo-random numbers based on a seed which is generated as follows:
```
if hashtype == "md5":
seed = hashlib.md5((trx_id + block["block_id"] + block["previous"]).encode()).hexdigest()
elif hashtype == "sha256":
seed = hashlib.sha256((trx_id + block["block_id"] + block["previous"]).encode()).hexdigest()
elif hashtype == "sha512":
seed = hashlib.sha512((trx_id + block["block_id"] + block["previous"]).encode()).hexdigest()
```
`beempy draw` uses three entropy sources: the hash of the last block, the hash of the current block and the hash of a transaction inside the current block.
When using `md5` as hashtype, the seed is used to initialize the random generator:
```
random.seed(a=seed, version=2)
number = int(random.random() * len(draw_list))
```
This is e.g. used in splinterlands to generate random numbers.
When using `sha256` or `sha512`, `,<draw_number>` is added to the seed and a pseudo-random number is generated by
```
bigRand = int.from_bytes(seed, 'big')
number = bigRand % (len(draw_list))
```
It is possible to choose the separator by using ``-s`` parameter.
The results for `sha256` can be validated [here](https://www.stat.berkeley.edu/~stark/Java/Html/sha256Rand.htm).
### Usage
The following command uses the latest block number and the last transaction for building the seed and draw three number of 1000 different ones.
```
beempy draw -d 3 -p 1000
```
creates the following output
```
+--------------+------------------------------------------+
| Key | Value |
+--------------+------------------------------------------+
| block number | 43892950 |
| trx id | 38206e28dcbf15d8f9ce1be907fb60a99d427171 |
| block id | 029dc0d6a1fe487b5f2907988ba72b3ba495589b |
| previous | 029dc0d55023bdf2f6450083c52349c4cd838f65 |
| hash type | sha256 |
| draws | 3 |
| participants | 1000 |
| 1. draw | 406 |
| 2. draw | 568 |
| 3. draw | 186 |
+--------------+------------------------------------------+
```
We can validate the results by adding the value of trx id, block id and previous in this order into the seed field of [this pseudo-random generator](https://www.stat.berkeley.edu/~stark/Java/Html/sha256Rand.htm):

We can see that the same numbers were generated.
The results can also be validated by
```
beempy draw -d 3 -p 1000 -b 43892950 -t 38206e28dcbf15d8f9ce1be907fb60a99d427171
```
Adding `--markdown` or `-m` creates a markdown output which can directly copied into a post. The command above with `-m` generates:
The following results can be checked with:
```
beempy draw -d 3 -p 1000 -b 43892950 -t 38206e28dcbf15d8f9ce1be907fb60a99d427171 -h sha256 -s ','
```
| key | value |
| --- | --- |
| block number | [43892950](https://hiveblocks.com/b/43892950#38206e28dcbf15d8f9ce1be907fb60a99d427171) |
| trx id | [38206e28dcbf15d8f9ce1be907fb60a99d427171](https://hiveblocks.com/tx/38206e28dcbf15d8f9ce1be907fb60a99d427171) |
| block id | 029dc0d6a1fe487b5f2907988ba72b3ba495589b |
| previous id | 029dc0d55023bdf2f6450083c52349c4cd838f65 |
| hash type | sha256 |
| draws | 3 |
| participants | 1000 |
| 1. draw | 406 |
| 2. draw | 568 |
| 3. draw | 186 |
### Posting the results directly as reply
This can be used to directly publish results in a comment.
```
beempy draw -d 3 -p 10 --reply @user/my-post
```
`@user/my-post` is the parent post to which the comment is replied.
### Prevent cheating
A user could rerun `beempy draw` until the results are fitting. This can be prevented by defining previously which future block number is used for generating the pseudo-random numbers.
Or a future broadcast is used as reference, e.g. the next post. After broadcasting a new post, the trx-id and the block number can be checked and provided to ´beempy draw´.
### Creating a participants list to draw user from a list
`beempy draw` can be used to draw account names from a list of accounts. The participants can be stored in a text file where each line is one participant.
In order to draw one account, I can store all participating accounts in a file:
```
@holger80
@beembot
@beempy
```
A participant can now be selected by:
```
beempy draw -p account_list.txt
```
which results in
```
+--------------+------------------------------------------+
| Key | Value |
+--------------+------------------------------------------+
| block number | 43893720 |
| trx id | c12b9911d6c9d950f02700ae70c066e105c40aba |
| block id | 029dc3d8bc1518ad8a92c6e9fd2cce4e64095fb2 |
| previous | 029dc3d7d7b53b31b7d389a0cc9a84e8352ddb19 |
| hash type | sha256 |
| draws | 1 |
| participants | 3 |
| 1. draw | 2 - @beembot |
+--------------+------------------------------------------+
```
The order of the participants should be clear (e.g. ordered by date or ordered by letter) and defined previously.
When each participant should only be drawn once, the `--without-replacement` or `-w` parameter must be used.
## Feedback
Do you have some new ideas or improvements for beem or beempy? Let me know.
___
*If you like what I do, consider casting a vote for me as witness on [Hivesigner](https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1) or on [PeakD](https://peakd.com/witnesses)*👍 everyoung, elleok, crypticat, onealfa, stevescoins, techslut, swedishdragon76, frankydoodle, dera123, izzynoel, lionsuit, crokkon, amico, sneakyninja, hive.curation, kriang3tee, imtase, thedailysneak, akioexzgamer, yuza, paopaoza, ten-years-before, puza, crypto.story, univers.crypto, mintrawa, steementertainer, nalexadre, redouanemez, saboin, gerber, ezzy, exyle, deathwing, nealmcspadden, mice-k, steemcityrewards, shitsignals, cadawg, bestboom, freddio, gallerani, dlike, bobby.madagascar, determine, permaculturedude, battlegames, steem.leo, leo.voter, freddio.sport, asteroids, mapxv, leo.syndication, one.life, maxuvd, huaren.news, goodreader, staryao, daan, dune69, felander, yogacoach, roleerob, pataty69, caladan, blockbrothers, swisswitness, triptolemus, followjohngalt, steemindian, milu-the-dog, triplea.bot, citrus-soap, dappcoder, ribary, someguy123, mys, rafalski, investprosper, flyingbolt, map10k, cd-leo, blocktvnews, whd, erikah, beleg, julian2013, munhenhos, benedict08, mistia, b00m, spamfarmer, abh12345, ew-and-patterns, accelerator, mermaidvampire, jimcustodio, sweetkathy, plankton.token, gerbo, revisesociology, steembasicincome, florino, anikys3reasure, sbi-tokens, sbi2, therealwolf, sbi3, smartsteem, sbi4, tombstone, lordjames, simply-happy, epicdice, tinyhousecryptos, sbi5, triviummethod, sbi6, abitcoinskeptic, sbi7, ilovecanada, sbi8, onetin84, jpphotography, nerdtopiade, casberp, sudefteri, whack.science, avel692, brucutu, pocoto, kitty-kitty, sbi9, mcoinz79, sashas, kahvesizlik, tipsybosphorus, sbi10, brucutu1, carioca, ticketyboo, ticketywoof, borbina, satren, carlpei, pagliozzo, tubiska, cyrillo, borran, tarazkp, nokodemion, hasmez, jussara, markkujantunen, gagago, daath, thrasher666, moneytron, brucutu2, cpt-sparrow, blockchainpeople, iamjohn, babytarazkp, nobyeni, ronaldoavelino, monsterjamgold, ninnu, danielsaori, dalz, netaterra, agent14, onepercentbetter, slobberchops, therealyme, themarkymark, tobias-g, chronocrypto, offgridlife, buildawhale, makerhacks, upmyvote, ipromote, urdreamscometrue, forecasteem, gamer00, itchyfeetdonica, blacklux, bubke, chrismadcboy2016, marcus0alameda, solarwarrior, merlion, broxi, realgoodcontent, hungrybear, lemouth, kimzwarch, akifane, fw206, besheda, lesmouths-travel, dachcolony, angelinafx, suonghuynh, smartvote, eikejanssen, matschi, richie.rich, sparschwein, tabea, tipu, freebornsociety, mytechtrail, helpyou, monster.oo7, dyrt88, happy-soul, stefannikolov, leighscotford, emrebeyler, likwid, jerrybanfield, bronkong, anli, andrepol, candyboy, maxpatternman, inteligente, re2pair, detetive, jacekw, flugschwein, cst90, promobot, raspibot, dollarbills, flemingfarm, a-bot, blue.rabbit, losi, backinblackdevil, properfraction, furioslosi, lrekt01, steempearls, ladyinblack, isnochys, superlao, szf, ctl001, fengchao, drorion, arcange, digital.mine, eunsik, smon-joa, gringo211985, lauchmelder, thranax, raphaelle, elbrava, livingfree, created, mittwochsquickie, ambyr00, actifit-devil, bartheek, borislavzlatanov, thedevilsbride, sparstrumpf, naltedtirt, brujas, digital-wisdom, longer, mark-waser, ethical-ai, jwaser, bwaser, funnyman, ellepdub, herpetologyguy, morgan.waser, handyman, strong-ai, technoprogressiv, holycow2019, vaansteam, linnyplant, tonalddrump, commonlaw, maxxie1, kissi, captain.kirk, softworld, korinkrafting, drsensor, hivewatchers, steemcleaners, logic, bewithbreath, idkpdx, santigs, maxsieg, steempty, fminerten, edicted, sn0n, hextech, blokz, the3metrewrap, goumao, wf9877, superhardness, iamdanny, stranger27, judasp, syedumair, morellys2004, cheftony, condeas, stuntman.mike, linuxbot, heighung, cambalache, gulf41, neuerko, blocktrades, tomatom, gabrielatravels, jancharlest, helgalubevi, kgswallet, mr-critic.aaa, reghunter, bilpcoinbpc, blocktokens, tinoie, celinavisaez, timcliff, sreypov, mariela53, steempower, rashid001, trustwallet, rilo, yuriy4, hiveupme, dkt333, ozraeliavi, twinner, dein-problem, akkibadboy, marius19, actnearn, jamesbattler, rehkal, cotarelo, hive-139156, hive-122120, ladynazgool, bitt.nerd, alexbalan, famegirl, bescouted, e-r-k-a-n, igorg, brandaswitch, marki99, muelli, fooblic, aanjz09123, khazrakh, beejah, seikatsumkt, afiqsejuk, zakia, oaldamster, skaidy96, jackofcrows, shihabieee, moniristi, hafez, monirhossen, robiul985340, adnan9, germansailor, sabine-reichert, tazi, romiferns, giuatt07, debhietifany, gabrielamenesesg, druglord247, arrixion, gitplait, tykee, bala41288, leonardodaslade, ttg, xtrimmer, jphamer1, jeanpi1908, j-p-bs, manwojciech, callmekat, abulabubu, espoem, kokamspycare, angel33, maini, kaeserotor, tiochilo, circa, lichtblick, kreur, doomboom, ericahan, picciridda2, titusfrost, nadhora, davidesimoncini, kork75, nigerian-yogagal, bib15hash, jenina619, achim86, zen.fit, muhammedfit, cryptoanalysis, evildeathcore, andricinaa, iaberius, hotbit, zottone444, tomhall, lefty619, salimbur, jkramer, netuoso, mare123, dec.entralized, stickstore, quekery, redaktion, newsticker, steemcartel, hiq, smooms, beggars, maxxie, mgzayyar, abrockman, cesinfenianos, ashwim, ssjsasha, idoctor, yoogyart, atyh, toomatoo, lelon, sampraise, yadamaniart, v4vapid, enki, primeradue, cryptocalendar, prameshtyagi, radiv, fidget09, ssc-token, jewel-lover, gdhaetae, amkn6590, sudutpandang, jedigeiss, erixink, p2hive, deepak1471985, androshchuk, asgarth-dev, yehey, filipino, shares, branding, broadcast, automation, council, pesos, petscorner, aggroed, pinoy, lesmann, kotturinn, feelx, waytolifecare, neon3000, cristiano6, steemik, tradingideas, marlians.spt, rowell, rabibulhasan, jefz, brianbrogan1960, bela29, thikanavul, diegor, electronicsworld, jaster, eliasseth, adamdabeast, bcgator, rafaelaquino, lays, boholtamsi, angelescats, miloshpro, asgarth, techtek, inertia, arabisouri, ahmedsy, mrsyria, andrewmusic, marymi, irynochka, calist, sonder-an, pranay5073,