Making a script to get updates when your voting power is 100% Part 03

Hello everyone!

I have some exciting updates for you all!

Working Program

The script is working much better than last time thanks to @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

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

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



0
0
0.000
3 comments
avatar

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

You distributed more than 10 upvotes.
Your next target is to reach 50 upvotes.

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

To support your work, I also upvoted your post!

Check out the last post from @hivebuzz:

Feedback from the March 1st Hive Power Up Day
Our Hive Power Delegations to the February PUM Winners
Today is the beginning of a new Hive Power Up Month!
Support the HiveBuzz project. Vote for our proposal!
0
0
0.000
avatar

This is awesome. Thank you for working on this kind of thing. Neat project.

0
0
0.000