ruffington avatar

BEST Coding Script For EXTRA Hive Power!

ruffington

Published: 13 Mar 2022 › Updated: 13 Mar 2022BEST Coding Script For EXTRA Hive Power!

BEST Coding Script For EXTRA Hive Power!

Hello everyone!

I have some exciting updates for you all!

Working Program

The script is working much better than last time thanks to bhanutejap@bhanutejap, the TA in my class.

Issue faced
I was able to fix the errors from last time by delaying my program for 3 seconds once I get the url. This is because the website needs a little time to load, and if we dont pause the program the default value of voting power is 100%

python
hivestats_url = 'https://hivestats.io/@' + self.username
self.driver.get(hivestats_url)
time.sleep(3)

As you can see in the above code, once I get the URL, I let the script pause for 3 seconds. This lets the website to load.

New code to make it better

By solving this error I moved on to make the code more reusable for the automation part. I made it Object Oriented. As a new programmer I under estimated the power of object-oriented-programming OOP. As you will see in my code I was quickly able to collect and print data from 3 different users.

python
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.by import By
import time

class Hive_power_tracker:

def __init__(self, username):

    # getting drivers / webscraping working
    options = FirefoxOptions()
    options.add_argument("--headless")
    self.driver = webdriver.Firefox(options=options) #this is the path where my geckodriver exists

    # getting data paramaters accessible for the whole class
    self.username = username
    self.vote_value_percentage = ''
    self.time_to_100 = ''
    self.effective_hive_power = ''
    self.hive_power = ''

# gets user data
def get_user_data(self):

    hivestats_url = 'https://hivestats.io/@' + self.username
    self.driver.get(hivestats_url)
    time.sleep(3)
    self.vote_value_percentage = self.driver.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div[2]/section[1]/div[2]/div/div/span[1]/span[2]')
    self.time_to_100 = self.driver.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div[2]/section[3]/div[2]/table/tbody/tr[8]/td[2]')
    self.effective_hive_power = self.driver.find_element(By.XPATH, '/html/body/div/div/div[1]/div/div[2]/section[3]/div[2]/table/tbody/tr[1]/td[2]/span')
    self.hive_power = self.driver.find_element(By.XPATH, '/html/body/div/div/div[1]/div/div[2]/section[3]/div[2]/table/tbody/tr[2]/td[2]/span')

    return 0

# prints out user data 
def __repr__(self): 
    print("---------------","\nUser:", self.username, "\nVote Power:", self.vote_value_percentage.text, "\nTime untill full:", self.time_to_100.text, "\nEffective HP:", self.effective_hive_power.text, "\nActual HP:", self.hive_power.text)
    #return "User: % s Vote Power: % s Time untill full: % s Effective HP: % s Actual HP: % s" % (self.username, self.vote_value_percentage, self.time_to_100, self.effective_hive_power, self.hive_power) 
    return "---------------"

object armoredbanana

user1 = Hive_power_tracker(username = "armoredbanana")
user1.get_user_data()
print(user1)

object trostparadox

user2 = Hive_power_tracker(username = "trostparadox")
user2.get_user_data()
print(user2)

object bhanutejap

user3 = Hive_power_tracker(username = "bhanutejap")
user3.get_user_data()
print(user3)
The output of this code is

output

User: armoredbanana
Vote Power: 93.10%
Time untill full: 8 hours 16 minutes
Effective HP: 17.74 HP
Actual HP: 7.71 HP



User: trostparadox
Vote Power: 94.56%
Time untill full: 6 hours 31 minutes
Effective HP: 104,252.25 HP



User: trostparadox
Vote Power: 94.59%
Time untill full: 6 hours 29 minutes
Effective HP: 104,252.26 HP
Actual HP: 5,118.4 HP



User: bhanutejap
Vote Power: 63.13%
Time untill full: 1 day 20 hours 14 minutes
Effective HP: 0 HP
Actual HP: 0 HP


It neatly outputs the user data.

Whats coming next week
Next week I will be working with creating a notification system for each user. This is what my tasks look like:

Convert time data into integers to work with them easily
Store data from each user in a database (on a raspberry pi)
Look into how to send emails or texts using python or other services
I am glad the project came to working this week. For the future I will be partnering with my classmate veryjerry3@veryjerry3

Furthermore I would like to thank trostparadox@trostparadox for teaching the class and bhanutejap@bhanutejap for helping me out on the code!

Thank you for reading and looking forward to seeing you next Sunday again!

#vyb#hivepower#staking#engineering#hive#coding#python#selenium

Leave BEST Coding Script For EXTRA Hive Power! to:

Written by

Read more #vyb posts


Best Posts From ruffington

We have not curated any of ruffington's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From ruffington