Automated Hive Posts Using Beem

avatar
(Edited)

beemposts.png

This post is a continuation of my FinViz project from yesterday. I was trying to create custom reports for potential stock picks of the day. The goal is to go through thousands of stocks programmatically and sort out some stocks that fit certain criteria. For the purposes of this experiment, I am using my triangle indicator, about which I have written before. Nothing special about the indicator, so I won't provide a link to the post. However, the idea is to apply any other indicators to this project in the future.

Normally, triangle indicator have very few picks a day, about 2-6 picks. Once these picks are identified, then I get charts and other additional data about this stock. Then put them together in a report. The report is very boring, and only has some value for me. Most others would consider it a useless spam.

Now the next step is to store the report or publish online to access on the go and have a chronological records for future reference. I had to try posting on Hive programmatically from an alt account (librarian) for educational purposes and experimentation. After three hundred and thirty lines of code, I was able to finish the project. Of course, the report looks ugly. But it serves the purpose for now. This is not a permanent solution. I want to use custom_json instead in the future.

Beem is a python library created and maintained by @holger80, and is an awesome tool to interact with Hive blockchain. I am not sure if Holger is still maintaining the library. For now it works. Let's look at the code first. Then I will try to explain what is happening in the code. This is not the full code for the project mentioned above, but rather a template to programmatically publish Hive posts using Beem.

from beem.imageuploader import ImageUploader
from beem import Hive
from beem.nodelist import NodeList

nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_hive_nodes()

#wif = getpass.getpass(prompt='Enter your Hive active key:')
wif = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
hive = Hive(node=nodes, keys=[wif])
author = 'librarian'
image_path = '/Users/librarian/project/charts/COIN_1642474232.png'
image_name = 'COIN'
image_uploader = ImageUploader(blockchain_instance=hive)
img_link = image_uploader.upload(image_path, author, image_name=image_name)

title = "COIN stock price data"
body = f'''
This is COIN price data start

![{image_name}]({img_link['url']})

This is COIN price data end
'''

parse_body = True
self_vote = False
tags = ['stocks', 'coin', 'test']

hive.post(title, body, author=author, tags=tags, parse_body=parse_body, self_vote=self_vote)

First we import modules we need from Beem. ImageUploader will help with uploading images, NodeList will be used to get the Hive nodes.

In this example there are two ways to provide private posting keys. First one is commented out, but is the better way, because you will not need to keep the private posting key within the code. For testing purposes I used the second way of just assigning the posting key to a variable wif. Then we create a hive instance proving nodes and private keys.

To upload an image, we will need a full path to the image, and an image name, which usually is the image file name, and author name. After creating an instance of an ImageUploader, which requires a blockchain instance, in this case it is hive variable, we upload the image using the .upload() method. This is where we use image path, image name and author names. This will return an image link, which we can use in the body of the post. img_link['url'] will have the url to the uploaded image.

Now that image is ready, we need to create a title for the post and store it in a variable. We will need a list of tags, if we are using any. Set parse_body to True, and self_vote to False. Most importantly we need to create a body text with proper markdown and include image url in the body text.

Once all of these parts of the post are ready, we can broadcast this transactions with .post() method of the hive instance. Very last line of the code executes the posting transaction, includes all the parts of the post as arguments. When we ran the post, if everything goes well, the post will be published on Hive blockchain.

This is a basic template for publishing Hive posts. There are more interesting parameters like json_metadata and comment_options that can be configured depending on what we are trying to do. While I was able to successfully publish a post with Beem and even integrate Beem in a creating stock reports project, there is more I need to learn.

For example, I wanted to set decline post rewards for these automated posts. However when I tried to do that I got an error. I will have to experiment with this and other feature of Hive posts. To learn more about Beem and how to use it, feel free to read the Beem documentation.

If you have experience with Beem and know how I can add decline post rewards, please let me know in the comments. My understanding is this configuration will go inside of comment_options by setting "allow_votes: False". However, this caused an error.

Posted Using LeoFinance Beta



0
0
0.000
36 comments
avatar

Do you mean FinViz will choose stocks and a report will be posted on HIVE? What kind of report will it be?

0
0
0.000
avatar

No, code will pick the stocks. To see the report check @librarian posts. But they will be meaningless and useless for you.

0
0
0.000
avatar

This finViz is definitely a nice project with awesome features around it.

0
0
0.000
avatar

This post has been manually curated by @bhattg from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating your Leo power to @india-leo account? We share 100 % of the curation rewards with the delegators.

Please contribute to the community by upvoting this comment and posts made by @indiaunited.

0
0
0.000
avatar

You don't perhaps know how I can write one post, then get it published automatically on all of the many social sites I'm on? Buffer and Integromat don't do crypto sites like Hive and SteemIt and Flote and the many others, and I want an article to appear on all of them, with the link of my first post as source to appear on the others. Any ideas? How would you go about it?

0
0
0.000
avatar

Since they aren’t all on same blockchain, maybe the easiest way would be to use Selenium and code the sequence of clicks you would make to post on various websites.

0
0
0.000
avatar

I was afraid of that answer! 😁 Spent quite some time last year playing with Selenium, on another project (till my Chromium bombed out for some mysterious reason.) Guess I'll have to get working on that again, using Firefox this time. Since I like PyAutoGUI as well, I may even try to smuggle that in my script too. Thanks for the reply.

0
0
0.000
avatar

This post might become useful for me. Because I’m planning to do a interview series on Hive Called Five Crypto Questions with Mars.

So Thank you

Posted Using LeoFinance Beta

0
0
0.000
avatar

That’s great! Thanks Nathan!

0
0
0.000
avatar

Very nice. I am just learning the same, but I was trying LightHive library first. https://lighthive.readthedocs.io/en/latest/index.html
Maybe I should try Beem too
I also use python and I am programming a full trading app with it :)

0
0
0.000
avatar

I have used lighthive before too. They both are good. It is good to have multiple options.
You will need to tell me more about your trading app. Sounds interesting.

0
0
0.000
avatar

The app started as an experimental simple trading app to quickly manage orders directly on the chart. For now it only works to trade Bitcoin on Binance exchange. It is still very basic and a lot of things need to be done. But it is evolving now to a more complete trading app with focus on risk management tools which is something very important, and in the future, some semiautomated trading. Sometimes I get stuck on some problems like disconnecting websockets, but I am learning a lot. Maybe I could post about it on Hive :D You gave me an idea to use Beem to automatically post the screenshots the app generates when I see something interesting happening. I use it as a trading journal log, but maybe using Hive blockchain for the log is the best because it cannot be changed in the future so it is sure that the log is authentic. :)

0
0
0.000
avatar

Cool posts automation with a new tool on Hive. We need more development and then to make it easy to use for end users.

Posted Using LeoFinance Beta

0
0
0.000
avatar

That’s a really cool script. I like having the insider trading info like that. That’s actually quite useful in some cases, especially if you are trading options. It’s good to see who in the company is selling ;) Good work! Reblogging for the https://coin-logic.com community!

0
0
0.000
avatar

Thank you. What is Coinlogic?

0
0
0.000
avatar
(Edited)

Our little crypto research site that will one day be a DAO, trying to find the right directions and keep building more good educational content. Trying to find the right approach without overdoing it or becoming another shill channel. Mainly focused on overall crypto and market education.

https://coin-Logic.com

0
0
0.000
avatar

This is still kind of complex because I don’t know anything in coding, it will be great if the develop it

Posted Using LeoFinance Beta

0
0
0.000
avatar

I won’t lie , this honestly looks like rocket science to me .

0
0
0.000
avatar

Beem is a really great tools that I have used quite a lot (and I am still using it) for a lot of shell-based operations. Is @holger80 still actively maintaining it? I have read I don't remember where that he had left the chain for good (and this is also what his account suggests). Hopefully I am wrong here....

0
0
0.000
avatar

Yes, beem is very useful. I am not sure if Holger is still around or not either. Hopefully he is still here.

0
0
0.000
avatar

Lots of information that I barely understand. This code thing us not just for me😢

0
0
0.000
avatar

some very sleek automation there. powerful little code. i don't understand much code at all, but can appreciate how it can help us. :)

0
0
0.000
avatar

This is showing how important infrastructure is out there. We also see how quickly things can expand with open source code. The shortcuts provided help others to create projects, many of which end up as open sourced. This, of course, creates the feedback loop where more is being created.

Over time, this saves developers a ton of time, allowing for a vast amount of applications to be created.

Posted Using LeoFinance Beta

0
0
0.000
avatar

tagging @cryptocharmers This might be useful to you soon.

Posted Using LeoFinance Beta

0
0
0.000
avatar

For now I'm trying to handle processes without relying on Beem through Python, as it is an additional layer of reliance that at this moment in time I think is not necessary.

0
0
0.000