#!/usr/bin/env python
import sys, urllib2, re, os

# Check for configuration
board_url = os.environ.get('board_url')
if(board_url == None):
    exit(0)

if(len(sys.argv) > 1 and sys.argv[1] == "config"):
    print """
graph_title Registered Members
graph_vlabel members
graph_category mybb
members.label Members
"""
    exit(0)

# Load the main page
response = urllib2.urlopen(board_url)
html = response.read()

# Extract the data
re_members = re.compile("We currently have ([\d\,]+) members registered.")
members = re_members.search(html)

# Output values
if(members != None):
    print ("members.value %s" % members.group(1)).replace(',', '')