Storing Custom JSON

in OCD4 years ago

Easy as Py

Updated the previous STM version to be used with the Hive blockchain.

ods.py

# This ods dot py is a Hive Blockchain experiment. 
# Use at your own responsibility.
# This software is provided to you as it is.
# Code is Open & Free, like Speech & Thoughts. 
# License CC-BY_SA, if you must.
# Copyrights belong to one(s) who are the first to publish. 
# Original by Oaldamster (a blockchain recorded trademark of Niwrah.) 

# Set do_store to False while doing trial n error
do_store = True

# For future use
import json

# Thanks to fellow Hiver holger80
from beem import Hive

# Test ODS setting, use the Beem key wallet!
# The Hive Account publishing 
ods_account="oaldamster" 
# Beem Key Wallet open thee
pw = "password"

# In case of API trouble: 
# Hive(node=["https://api.hive.blog"])
haif = Hive() 
haif.wallet.unlock(pw) 

# Some smart Data to store 
# Could be done with an external config file
config = {
    'task': 'remark',
    'header' : 'Storing data on the Hive blockchain',
    'text' : 'This has been stored, as a remark,\n using a simple Python3 program\n and the BEEM module.'
}
# Now it works like this too 
config['footer'] = "Only on Hive Baby, YEAH!\n"
config['footer'] += "Created by @" + ods_account

# The config data can be converted to JSON, but in this case it is not needed. 
# Let's build some JSON data
def build_JSON():
    ods_JSON = {}
    ods_JSON['genesis'] = 'ods-202005160721'
    ods_JSON['tx'] = 'ods-202005160721-00000002'
    ods_JSON['smartAction'] = config['task']
    ods_JSON['smartData'] = {}
    ods_JSON['smartData']['title'] = config['header']
    ods_JSON['smartData']['paragraph'] = config['text']
    ods_JSON['smartData']['subscript'] = config['footer']
    # And return the object
    return ods_JSON


def main():
    # Let's prepare the data to store    
    ods_JSON = build_JSON()
    
    # Only store once
    if do_store:  
        haif.custom_json('ods-subrosa1', ods_JSON ,required_auths=[ods_account])
        print(f"Stored data: {ods_JSON}")
    else:
        print(f"Testrun data: {ods_JSON}")

if __name__ == '__main__':
    main()

Have a great one!


And it got stored!
storedjson.png
Screenshot taken at HiveBlocks dot Com.

Beem 0.23.7 Documentation: https://beem.readthedocs.io/en/0.23.7/index.html

Sort:  

Congratulations @oaldamster! You received a personal badge!

Happy Hive Birthday! You are on the Hive blockchain for 4 years!

You can view your badges on your board And compare to others on the Ranking

Support the HiveBuzz project. Vote for our proposal!

Four years already. Wow. :-)

Wow! I look up to you 🙂
cheers, liz

Time flew having fun. :-)

Cheers,
Harwin

I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!

Thank you! :-)

Congratulations @oaldamster! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You made more than 10000 comments. Your next target is to reach 11000 comments.

You can view your badges on your board and compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @hivebuzz:

The Hive Gamification Proposal
Support the HiveBuzz project. Vote for our proposal!