import requests
from bs4 import BeautifulSoup
import datetime
import os
import json
# Function to check last post date, track merit changes, and log wallet addresses
def track_merit_and_wallet_changes():
# Load previously logged data if available
log_data = {}
log_file = "merit_logs/merit_wallet_changes_log.json"
if os.path.exists(log_file):
with open(log_file, 'r') as file:
log_data = json.load(file)
# URL for the Bitcointalk recent posts
url = '
https://bitcointalk.org/index.php?action=recent'
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
post_table = soup.find('table', class_='bordercolor')
post_rows = post_table.find_all('tr')[1:] # Skip the table header
for row in post_rows:
username_elem = row.find('td', class_='poster_info').find('a', class_='msguser')
if username_elem:
username = username_elem.text.strip()
user_url = f"
https://bitcointalk.org/index.php?action=profile;username={username}"
user_response = requests.get(user_url)
if user_response.status_code == 200:
user_soup = BeautifulSoup(user_response.content, 'html.parser')
merit_element = user_soup.find('div', class_='merit_bar')
# Check last post date
last_post_element = user_soup.find('td', text='Last post')
if last_post_element:
last_post_date_str = last_post_element.find_next('td').text.strip()
last_post_date = datetime.datetime.strptime(last_post_date_str, "%B %d, %Y, %I:%M:%S %p")
current_month_start = datetime.datetime.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
if last_post_date >= current_month_start and merit_element:
wallet_element = user_soup.find('div', {'id': 'info_section'})
wallet_address = None
if wallet_element:
wallet_row = wallet_element.find(text='Sollet Wallet:').find_next('td')
if wallet_row:
wallet_address = wallet_row.text.strip()
if wallet_address:
current_merit = int(merit_element['title'])
previous_merit = log_data.get(username, 0)
if current_merit - previous_merit > 10:
# Log if the merit change is more than 10 along with the wallet address
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
log_data[username] = current_merit
with open(log_file, 'w') as file:
json.dump(log_data, file, indent=4)
print(f"Merit change detected for {username}: +{current_merit - previous_merit} merits")
print(f"Solana Wallet Address: {wallet_address}")
else:
print(f"No significant merit change for {username}")
print(f"Solana Wallet Address: {wallet_address}")
else:
print(f"{username} did not post within the last month or has no Solana wallet address")
else:
print(f"{username} did not post within the last month or has no merit information")
else:
print(f"Unable to find last post information for {username}")
else:
print(f"Failed to fetch user data for {username}")
else:
print("Username not found in post")
else:
print("Failed to fetch recent posts")
if __name__ == "__main__":
track_merit_and_wallet_changes()
This script checks each user's profile for recent posts within the last month and also looks for Solana wallet addresses in their profiles. If a user has a Solana wallet address listed, it logs their merit changes along with the wallet address in the merit_wallet_changes_log.json file within the merit_logs directory. Adjustments to the HTML structure may be needed if Bitcointalk updates its layout.
Ensure you have added wallet# to profile to be included!