Add liberapay integration

master
Drew DeVault 7 years ago
parent 0a3a05024e
commit ecdc7e4f22
  1. 18
      fosspay/blueprints/html.py
  2. 27
      templates/goal.html

@ -13,6 +13,7 @@ import bcrypt
import hashlib import hashlib
import stripe import stripe
import binascii import binascii
import requests
encoding = locale.getdefaultlocale()[1] encoding = locale.getdefaultlocale()[1]
html = Blueprint('html', __name__, template_folder='../../templates') html = Blueprint('html', __name__, template_folder='../../templates')
@ -49,12 +50,27 @@ def index():
patreon_count = 0 patreon_count = 0
patreon_sum = 0 patreon_sum = 0
liberapay = _cfg("liberapay-campaign")
if liberapay:
lp = (requests
.get("https://liberapay.com/{}/public.json".format(liberapay))
).json()
lp_count = lp['npatrons']
lp_sum = int(float(lp['receiving']['amount']) * 100)
# Convert from weekly to monthly
lp_sum = lp_sum * 52 // 12
else:
lp_count = 0
lp_sum = 0
return render_template("index.html", projects=projects, return render_template("index.html", projects=projects,
avatar=avatar, selected_project=selected_project, avatar=avatar, selected_project=selected_project,
recurring_count=recurring_count, recurring_count=recurring_count,
recurring_sum=recurring_sum, recurring_sum=recurring_sum,
patreon_count=patreon_count, patreon_count=patreon_count,
patreon_sum=patreon_sum) patreon_sum=patreon_sum,
lp_count=lp_count,
lp_sum=lp_sum)
@html.route("/setup", methods=["POST"]) @html.route("/setup", methods=["POST"])
def setup(): def setup():

@ -2,12 +2,13 @@
<div class="container" style="padding-top: 5rem"> <div class="container" style="padding-top: 5rem">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">
{% set total_sum = recurring_sum + patreon_sum %} {% set total_sum = recurring_sum + patreon_sum + lp_sum %}
{% set total_count = recurring_count + patreon_count %} {% set total_count = recurring_count + patreon_count + lp_count %}
{% if _cfg("goal") %} {% if _cfg("goal") %}
{% set goal = int(_cfg("goal")) %} {% set goal = int(_cfg("goal")) %}
{% set recurring_progress = recurring_sum / goal %} {% set recurring_progress = recurring_sum / goal %}
{% set patreon_progress = patreon_sum / goal %} {% set patreon_progress = patreon_sum / goal %}
{% set lp_progress = lp_sum / goal %}
{% set progress = total_sum / goal %} {% set progress = total_sum / goal %}
<div class="progress" style="height: 3rem"> <div class="progress" style="height: 3rem">
<div <div
@ -23,18 +24,26 @@
> >
<span>${{ "{:.0f}".format(patreon_sum / 100) }}</span> <span>${{ "{:.0f}".format(patreon_sum / 100) }}</span>
</div> </div>
<div
class="progress-bar progress-bar-warning"
style="width: {{ lp_progress * 100 }}%; line-height: 2.5"
>
<span>${{ "{:.0f}".format(lp_sum / 100) }}</span>
</div>
</div> </div>
{% endif %} {% endif %}
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-3"> <div class="col-md-6 col-md-offset-3">
{% if patreon_count %} {% if patreon_count or lp_count %}
<p> <p>
${{ "{:.2f}".format(recurring_sum / 100) }}/mo ${{ "{:.2f}".format(recurring_sum / 100) }}/mo
via <strong class="text-primary">{{ domain }}</strong> via <strong class="text-primary">{{ domain }}</strong>
({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }}) ({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }})
</p> </p>
{% if patreon_count %}
<p> <p>
${{ "{:.2f}".format(patreon_sum / 100) }}/mo ${{ "{:.2f}".format(patreon_sum / 100) }}/mo
via via
@ -45,6 +54,18 @@
</a></strong> ({{ patreon_count }} supporter{{ "s" if patreon_count != 1 else "" }}) </a></strong> ({{ patreon_count }} supporter{{ "s" if patreon_count != 1 else "" }})
</p> </p>
{% endif %} {% endif %}
{% if lp_count %}
<p>
${{ "{:.2f}".format(lp_sum / 100) }}/mo
via
<strong><a
class="text-warning"
href="https://liberapay.com/{{ _cfg("liberapay-campaign") }}">
Liberapay <i class="glyphicon glyphicon-share"></i>
</a></strong> ({{ lp_count }} supporter{{ "s" if lp_count != 1 else "" }})
</p>
{% endif %}
{% endif %}
{% if goal %} {% if goal %}
<p class="{{ "text-center" if not patreon_sum else "" }}"> <p class="{{ "text-center" if not patreon_sum else "" }}">
${{ "{:.2f}".format(total_sum / 100)}}/mo ${{ "{:.2f}".format(total_sum / 100)}}/mo

Loading…
Cancel
Save