Giter Club home page Giter Club logo

discourse-community-leaderboard's Introduction

Discourse Community Leaderboard

Want to motivate your Discourse Community Top Contributors? They're performing exceptionally well by providing answers and solutions to others' question? Want to send them SWAG for that or any other kind of prize? Got you covered! At least on the technical side of things: fetching leaderboard, sending SMS summary to the SWAG sender in your company, posting top 3 contributors in Slack, notifying top contributors, . You just need to take care of the physical prize shipping!

This script will execute on the first day of every month, running your Leaderbord query, parsing its results, sending SMS with top three contributors with their names, email and total points to the person in your company responsible for SWAG shipment, posting the same content to the Slack channel of your choice, as well as notifying those top performers via email about their great work and prizes on their way.

Fill in the script parameters once, deploy automatically every month!

Core Concept

The main concept here is to save your time on the manual work. You won't need to do those things anymore:

  • Execute leaderboard query manually every month
  • Copy-paste the results to let people in your company know who performed best in the community forum
  • Sending the message with top contributors to the person in your company responsible for SWAG shipping
  • Sending message to top performers with the info that they actually won something with their effort

Each of those steps will be automated, you just need to setup the script once.

Saving time one query / SMS / email at a time!

The Leaderboard

The leaderboard SQL query was developed based on point system. Number of replies, solutions provided and likes received are taken into account. Here's how the point system works:

  • Each solution provided - 3 points
  • Each reply given - 2 points
  • Each like received - 1 point

All that sums up and we have total points. Here's how example leaderboard look like:

The Script

It was developed using Python, Twilio (SMS), SendGrid (Email), cron (Scheduling) . Full script code can be found here. Simplified script code is shown below:

client = Client(ACCOUNT_SID, AUTH_TOKEN)

def fetch_leaderboard():

    headers = {'Content-Type': 'multipart/form-data', 'Api-Key': API_KEY, 'Api-Username': API_USERNAME}
    request = requests.post(url = ENDPOINT, headers = headers)

    response = json.loads(request.text)
    response_rows = response["rows"]

    first_place = {'Name': response_rows[0][1],
    'Email': response_rows[0][2],
    'Total_Points': response_rows[0][6]}

    second_place = {'Name': response_rows[1][1],
    'Email': response_rows[1][2],
    'Total_Points': response_rows[1][6]}

    third_place = {'Name': response_rows[2][1],
    'Email': response_rows[2][2],
    'Total_Points': response_rows[2][6]}

    winners_names_emails = [(first_place['Email'], first_place['Name']), (second_place['Email'], second_place['Name']), (third_place['Email'], third_place['Name'])]

    response_text = "Community Leaderboard ๐Ÿ†\n๐Ÿฅ‡ {} ({}) - {} pts\n๐Ÿฅˆ {} ({}) - {} pts\n๐Ÿฅ‰ {} ({}) - {} pts".format(first_place['Name'], first_place['Email'], first_place['Total_Points'], second_place['Name'], second_place['Email'], second_place['Total_Points'], third_place['Name'], third_place['Email'], third_place['Total_Points'])

    return response_text, winners_names_emails

def post_to_slack(leaderboard):
    slack_message = {'text': leaderboard}
    requests.post(WEBHOOK_URL, json.dumps(slack_message))

def send_leaderboard_via_sms_to_prize_sender(leaderboard):
    message = client.messages.create(
        body = leaderboard,
        from_= FROM_NUMBER,
        to = TO_NUMBER)

def notify_top_contributors_via_email(leaderboard, winners_emails):
    message = Mail(
	from_email = ('[email protected]', 'Konrad Sopala'),
	subject = 'Auth0 Community - Leaderboard ๐Ÿ†',
	html_content = '',
	plain_text_content = 'Congrats for your efforts last month! We really appreciate it! You have been one of Top 3 performers in our community forum. Someone from Auth0 will contact you shortly to send you some secret SWAG\n{}'.format(leaderboard),
	to_emails = winners_emails,
	is_multiple = True)

processed_leaderboard = fetch_leaderboard()
post_to_slack(processed_leaderboard[0])
send_leaderboard_via_sms_to_prize_sender(processed_leaderboard[0])
notify_top_contributors_via_email(processed_leaderboard[0], processed_leaderboard[1])

This method runs the Python script automatically provided that you scheduled that with cron (described below). Here are the steps to make the method work, assuming you have Python installed on your computer:

To make it execute itself on the first day of each month at 12:00 automatically, go through following steps:

  • Open terminal (Mac / Linux)
  • Type in crontab -e
  • Press i to enable insert mode in Vim
  • Copy and paste this snippet adjusting the path for where you downloaded your script:
0 12 1 * * cd <insert_script_folder_location_path> && python leaderboard.py

  • Press esc and type :wq

If you want to schedule the execution of the script at different time, follow this cron scheduling mechanism:

# โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ minute (0 - 59)
# โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ hour (0 - 23)
# โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ day of month (1 - 31)
# โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ month (1 - 12)
# โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ day of week (0 - 6) (Sunday to Saturday;
# โ”‚ โ”‚ โ”‚ โ”‚ โ”‚                                       7 is also Sunday on some systems)
# โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
# โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
# * * * * *  command_to_execute

Your post on Slack, SMS and EMAIL should be all there on the first day of each month at 12:00 your machine time! Congrats! ๐ŸŽ‰

Supporting documentation

If you want to find out more about the stack used in those tools or even build your own tools, make sure to visit following links and get inspired:

discourse-community-leaderboard's People

Contributors

konradsopala avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

discourse-community-leaderboard's Issues

IDEA: Create a discourse post in specific category about winner for the month

This is an idea, and not an issue. In addition to an email, Slack message, and SMS being sent, it would be good to have the option to post a topic in a specific category (say "Community Corner" or something) with the "Monthly Winner" info so that it's public to the community, and they can be energised to participate next month.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.