Skip to content

Instantly share code, notes, and snippets.

@sungkhum
Last active December 22, 2022 05:21
Show Gist options
  • Save sungkhum/206e18ffdefe448d6954c754f5532b72 to your computer and use it in GitHub Desktop.
Save sungkhum/206e18ffdefe448d6954c754f5532b72 to your computer and use it in GitHub Desktop.
Mass Diamond Shower Python Script for DeSo Blockchain
#################################
#
# Mass Diamond Shower Script
# by https://diamondapp.com/u/nathanwells
#
# Uses DeSo Python Library
# https://pypi.org/project/deso/
# by https://diamondapp.com/u/ItsAditya
#
#################################
import deso
import json
import requests
from tqdm import tqdm
DIAMONDERPUBLICKEY = YOURPUBLICKEY
###############################
# KEEP YOUR SEED HEX PRIVATE! To find it, use Chrome and browse to https://diamondapp.com then right-click
# and click "Inspect" then click the Application tab and expand Local Storage and click on identity.deso.org
# scroll to users and click and then find the public key paired with your seed hex
# Best practice is to store your seed hex in an environment variable!
###############################
DIAMONDERSEEDHEX = YOURSEEDHEX
# Set the diamond level you would like to give - default is 1
DIAMONDLEVEL = 1
API = 'https://node.deso.org/api/v0/'
def getPostsForPublicKey(
username="",
publicKey="",
mediaRequired=False,
numToFetch=10,
lastPostHashHex="",
):
endpoint = API + "get-posts-for-public-key"
payload = {
"PublicKeyBase58Check": publicKey,
"Username": username,
"ReaderPublicKeyBase58Check": DIAMONDERPUBLICKEY,
"LastPostHashHex": lastPostHashHex,
"NumToFetch": numToFetch,
"MediaRequired": mediaRequired,
}
response = requests.post(endpoint, json=payload)
return response
def giveDiamonds(userList, numberDiamonds):
if getCost(len(userList), numberDiamonds, DIAMONDLEVEL):
for user in userList:
allPosts = getPostsForPublicKey(username=user, numToFetch=numberDiamonds).json()
for post in tqdm(allPosts['Posts'], desc="Giving Diamonds to " + user + "..."):
try:
desoSocial = deso.Social(publicKey=DIAMONDERPUBLICKEY, seedHex=DIAMONDERSEEDHEX)
desoSocial.diamond(post['PostHashHex'], post['PosterPublicKeyBase58Check'], diamondLevel=DIAMONDLEVEL)
except Exception as e:
# Skip post if already given diamond in the past
if "RuleErrorCreatorCoinTransferPostAlreadyHasSufficientDiamonds" in str(e):
continue
else:
print(e)
break
return
else:
print("Cancelled")
return
def getCost(numUsers, numDiamonds, diamondLevel):
endpoint = API + "get-app-state"
payload = {
"PublicKeyBase58Check": DIAMONDERPUBLICKEY
}
response = requests.post(endpoint, json=payload).json()
desoNanosDiamondLevel = response["DiamondLevelMap"][str(diamondLevel)]
#Find total DeSo nanos of Diamond Shower
desoNanoTotal = numUsers * numDiamonds * desoNanosDiamondLevel
desoTotal = desoNanoTotal / 1e9
USDcost = (desoTotal * response["USDCentsPerDeSoCoinbase"]) / 100
userChoice = input("The cost of this diamond shower will be about: $" + str(USDcost) + " Do you want to continue (Y or N)? ")
if userChoice == "Y":
return True
else:
return False
# Function takes list of usernames and the number of posts you want to diamond (starting with the newest post)
giveDiamonds(['SeanSlater', 'StarGeezer'], 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment