Ejemplo n.º 1
0
def compute_input_csv():
    from gittip import wireup
    db = wireup.db()
    participants = db.all("""

        SELECT participants.*::participants
          FROM participants
         WHERE paypal_email IS NOT null
           AND balance > 0
      ORDER BY balance DESC

    """)
    writer = csv.writer(open(INPUT_CSV, 'w+'))
    print_rule()
    print("{:<24}{:<32} {:^7} {:^7} {:^7}".format("username", "email",
                                                  "balance", "tips", "amount"))
    print_rule()
    total_gross = 0
    for participant in participants:
        tips, total = participant.get_tips_and_total(for_payday=False)
        amount = participant.balance - total
        if amount <= 0:
            continue
        total_gross += amount
        print("{:<24}{:<32} {:>7} {:>7} {:>7}".format(participant.username,
                                                      participant.paypal_email,
                                                      participant.balance,
                                                      total, amount))
        row = (participant.username, participant.paypal_email, amount)
        writer.writerow(row)
    print(" " * 72, "-" * 7)
    print("{:>80}".format(total_gross))
Ejemplo n.º 2
0
 def setUp(self):
     super(Harness, self).setUp()
     self.postgres = wireup.db()
     self.payday = Payday(self.postgres)
     self.payday.start()
     self.tipper = self.make_participant('lgtest')
     self.balanced_account_uri = '/v1/marketplaces/M123/accounts/A123'
Ejemplo n.º 3
0
def compute_input_csv():
    from gittip import wireup
    db = wireup.db()
    participants = db.all("""

        SELECT participants.*::participants
          FROM participants
         WHERE paypal_email IS NOT null
           AND balance > 0
      ORDER BY balance DESC

    """)
    writer = csv.writer(open(INPUT_CSV, 'w+'))
    print_rule()
    print("{:<24}{:<32} {:^7} {:^7} {:^7}".format("username", "email", "balance", "tips", "amount"))
    print_rule()
    total_gross = 0
    for participant in participants:
        tips, total = participant.get_tips_and_total(for_payday=False)
        amount = participant.balance - total
        if amount <= 0:
            continue
        total_gross += amount
        print("{:<24}{:<32} {:>7} {:>7} {:>7}".format( participant.username
                                                     , participant.paypal_email
                                                     , participant.balance
                                                     , total
                                                     , amount
                                                      ))
        row = (participant.username, participant.paypal_email, amount)
        writer.writerow(row)
    print(" "*72, "-"*7)
    print("{:>80}".format(total_gross))
Ejemplo n.º 4
0
def compute_input_csv():
    from gittip import wireup
    db = wireup.db(wireup.env())
    participants = db.all("""

        SELECT participants.*::participants
          FROM participants
         WHERE paypal_email IS NOT null
           AND balance > 0
      ORDER BY balance DESC

    """)
    writer = csv.writer(open(INPUT_CSV, 'w+'))
    print_rule()
    print("{:<24}{:<32} {:^7} {:^7} {:^7}".format("username", "email", "balance", "tips", "amount"))
    print_rule()
    total_gross = 0
    for participant in participants:
        tips, total = participant.get_tips_and_total(for_payday=False)
        amount = participant.balance - total
        if amount < 0.50:
            # Minimum payout of 50 cents. I think that otherwise PayPal upcharges to a penny.
            # See https://github.com/gittip/www.gittip.com/issues/1958.
            continue
        total_gross += amount
        print("{:<24}{:<32} {:>7} {:>7} {:>7}".format( participant.username
                                                     , participant.paypal_email
                                                     , participant.balance
                                                     , total
                                                     , amount
                                                      ))
        row = (participant.username, participant.paypal_email, amount)
        writer.writerow(row)
    print(" "*72, "-"*7)
    print("{:>80}".format(total_gross))
Ejemplo n.º 5
0
def payday():

    # Wire things up.
    # ===============
    # Manually override max db connections so that we only have one connection.
    # Our db access is serialized right now anyway, and with only one
    # connection it's easier to trust changes to statement_timeout. The point
    # here is that we want to turn off statement_timeout for payday.

    env = wireup.env()
    env.database_maxconn = 1
    db = wireup.db(env)
    db.run("SET statement_timeout = 0")

    wireup.billing(env)
    wireup.nanswers(env)


    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gittip before calling wireup.billing.

    from gittip.billing.payday import Payday

    try:
        Payday(db).run()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback
        aspen.log(traceback.format_exc())
Ejemplo n.º 6
0
def payday():

    # Wire things up.
    # ===============

    env = wireup.env()
    db = wireup.db(env)

    wireup.billing(env)
    wireup.nanswers(env)


    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gittip before calling wireup.billing.

    from gittip.billing.exchanges import sync_with_balanced
    from gittip.billing.payday import Payday

    try:
        with db.get_cursor() as cursor:
            sync_with_balanced(cursor)
        Payday.start().run()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback
        aspen.log(traceback.format_exc())
Ejemplo n.º 7
0
def set_paypal_email(username='',
                     email='',
                     api_key_fragment='',
                     overwrite=False):
    """
    Usage:

    [gittip] $ env/bin/invoke set_paypal_email -u username -p [email protected] [-a 12e4s678] [--overwrite]
    """

    load_prod_envvars()

    if not username or not email:
        print(set_paypal_email.__doc__)
        sys.exit(1)

    if not api_key_fragment:
        first_eight = "unknown!"
    else:
        first_eight = api_key_fragment

    db = wireup.db(wireup.env())

    FIELDS = """
            SELECT username, api_key, paypal_email
              FROM participants
             WHERE username = %s
    """

    fields = db.one(FIELDS, (username, ))

    print(fields)

    if fields == None:
        print("No Gittip participant found with username '" + username + "'")
        sys.exit(2)

    if fields.paypal_email != None:
        print("PayPal email is already set to: " + fields.paypal_email)
        if not overwrite:
            print("Not overwriting existing PayPal email.")
            sys.exit(3)

    if fields.api_key == None:
        assert first_eight == "None"
    else:
        assert fields.api_key[0:8] == first_eight

    print("Setting PayPal email for " + username + " to " + email)

    SET_EMAIL = """
            UPDATE participants
               SET paypal_email=%s
             WHERE username=%s;
    """
    print(SET_EMAIL % (email, username))

    db.run(SET_EMAIL, (email, username))

    print("All done.")
Ejemplo n.º 8
0
def set_paypal_email(username='', email='', api_key_fragment='', overwrite=False, heroku=False):
    """
    Usage:

    [gittip] $ env/bin/invoke set_paypal_email --username=username [email protected] [--api-key-fragment=12e4s678] [--overwrite] [--heroku]

    Use --heroku when running directly on heroku
    """

    if not Heroku:
        load_prod_envvars()

    if not username or not email:
        print(set_paypal_email.__doc__)
        sys.exit(1)

    if not api_key_fragment:
        first_eight = "unknown!"
    else:
        first_eight = api_key_fragment

    db = wireup.db(wireup.env())

    FIELDS = """
            SELECT username, api_key, paypal_email
              FROM participants
             WHERE username = %s
    """

    fields = db.one(FIELDS, (username,))

    print(fields)

    if fields == None:
        print("No Gittip participant found with username '" + username + "'")
        sys.exit(2)

    if fields.paypal_email != None:
        print("PayPal email is already set to: " + fields.paypal_email)
        if not overwrite:
            print("Not overwriting existing PayPal email.")
            sys.exit(3)

    if fields.api_key == None:
        assert first_eight == "None"
    else:
        assert fields.api_key[0:8] == first_eight

    print("Setting PayPal email for " + username + " to " + email)

    SET_EMAIL = """
            UPDATE participants
               SET paypal_email=%s
             WHERE username=%s;
    """
    print(SET_EMAIL % (email, username))

    db.run(SET_EMAIL, (email, username))

    print("All done.")
Ejemplo n.º 9
0
def compute_input_csv():
    from gittip import wireup
    db = wireup.db(wireup.env())
    participants = db.all("""

        SELECT participants.*::participants
          FROM participants
         WHERE paypal_email IS NOT null
           AND balance > 0
      ORDER BY balance DESC

    """)
    writer = csv.writer(open(INPUT_CSV, 'w+'))
    print_rule(88)
    headers = "username", "email", "fee cap", "balance", "tips", "amount"
    print("{:<24}{:<32} {:^7} {:^7} {:^7} {:^7}".format(*headers))
    print_rule(88)
    total_gross = 0
    for participant in participants:
        tips, total = participant.get_tips_and_total(for_payday=False)
        amount = participant.balance - total
        if amount < 0.50:
            # Minimum payout of 50 cents. I think that otherwise PayPal upcharges to a penny.
            # See https://github.com/gittip/www.gittip.com/issues/1958.
            continue
        total_gross += amount
        print("{:<24}{:<32} {:>7} {:>7} {:>7} {:>7}".format(
            participant.username, participant.paypal_email,
            participant.paypal_fee_cap, participant.balance, total, amount))
        row = (participant.username, participant.paypal_email,
               participant.paypal_fee_cap, amount)
        writer.writerow(row)
    print(" " * 80, "-" * 7)
    print("{:>88}".format(total_gross))
Ejemplo n.º 10
0
    def test_stats_description_accurate_outside_of_payday(self, mock_datetime):
        """Test stats page outside of the payday running"""
        a_monday = datetime(2012, 8, 6, 11, 00, 01)
        mock_datetime.utcnow.return_value = a_monday

        payday = Payday(wireup.db())
        payday.start()

        body = self.get_stats_page()
        assert "is ready for <b>this Thursday</b>" in body, body
        payday.end()
Ejemplo n.º 11
0
def payday():
    wireup.db()
    wireup.billing()

    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gittip before calling wire_samurai, and it also dodges:
    #
    #   https://github.com/FeeFighters/samurai-client-python/issues/8

    from gittip import billing

    try:
        billing.payday()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback

        aspen.log(traceback.format_exc())
Ejemplo n.º 12
0
    def test_stats_description_accurate_outside_of_payday(self, mock_datetime):
        """Test stats page outside of the payday running"""
        self.clear_paydays()
        a_monday = datetime(2012, 8, 6, 12, 00, 01)
        mock_datetime.utcnow.return_value = a_monday

        db = wireup.db()
        wireup.billing()
        pd = Payday(db)
        pd.start()

        body = self.get_stats_page()
        self.assertTrue("is ready for <b>this Friday</b>" in body)
        pd.end()
Ejemplo n.º 13
0
    def test_stats_description_accurate_during_payday_run(self, mock_datetime):
        """Test that stats page takes running payday into account.

        This test was originally written to expose the fix required for
        https://github.com/gittip/www.gittip.com/issues/92.
        """
        a_thursday = datetime(2012, 8, 9, 11, 00, 01)
        mock_datetime.utcnow.return_value = a_thursday

        wireup.billing()
        payday = Payday(wireup.db())
        payday.start()

        body = self.get_stats_page()
        assert "is changing hands <b>right now!</b>" in body, body
        payday.end()
Ejemplo n.º 14
0
    def test_stats_description_accurate_during_payday_run(self, mock_datetime):
        """Test that stats page takes running payday into account.

        This test was originally written to expose the fix required for
        https://github.com/whit537/www.gittip.com/issues/92.
        """
        self.clear_paydays()
        a_friday = datetime(2012, 8, 10, 12, 00, 01)
        mock_datetime.utcnow.return_value = a_friday

        db = wireup.db()
        wireup.billing()
        pd = Payday(db)
        pd.start()

        body = self.get_stats_page()
        self.assertTrue("is changing hands <b>right now!</b>" in body)
        pd.end()
Ejemplo n.º 15
0
def payday():
    db = wireup.db()
    wireup.billing()

    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gittip before calling wireup.billing.

    from gittip.billing.payday import Payday

    try:
        Payday(db).run()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback
        aspen.log(traceback.format_exc())
Ejemplo n.º 16
0
def payday():
    db = wireup.db()
    wireup.billing()


    # Lazily import the billing module.
    # =================================
    # This dodges a problem where db in billing is None if we import it from
    # gittip before calling wire_samurai.

    from gittip.billing.payday import Payday

    try:
        Payday(db).run()
    except KeyboardInterrupt:
        pass
    except:
        import aspen
        import traceback
        aspen.log(traceback.format_exc())
Ejemplo n.º 17
0
def set_paypal_email(username='',
                     email='',
                     api_key_fragment='',
                     overwrite=False,
                     heroku=False):
    """
    Usage:

    [gittip] $ env/bin/invoke set_paypal_email --username=username [email protected] [--api-key-fragment=12e4s678] [--overwrite] [--heroku]

    Use --heroku when running directly on heroku
    """

    if not heroku:
        load_prod_envvars()

    if not username or not email:
        print(set_paypal_email.__doc__)
        sys.exit(1)

    if not api_key_fragment:
        first_eight = "unknown!"
    else:
        first_eight = api_key_fragment

    db = wireup.db(wireup.env())

    FIELDS = """
            SELECT username, api_key, paypal_email
              FROM participants
             WHERE username = %s
    """

    fields = db.one(FIELDS, (username, ))

    print(fields)

    if fields == None:
        print("No Gittip participant found with username '" + username + "'")
        sys.exit(2)

    # PayPal caps the MassPay fee at $20 for users outside the U.S., and $1 for
    # users inside the U.S. Most Gittip users using PayPal are outside the U.S.
    # so we set to $20 and I'll manually adjust to $1 when running MassPay and
    # noticing that something is off.
    FEE_CAP = ', paypal_fee_cap=20'

    if fields.paypal_email != None:
        print("PayPal email is already set to: " + fields.paypal_email)
        if not overwrite:
            print("Not overwriting existing PayPal email.")
            sys.exit(3)
        else:
            FEE_CAP = ''  # Don't overwrite fee_cap when overwriting email address.

    if fields.api_key == None:
        assert first_eight == "None"
    else:
        assert fields.api_key[0:8] == first_eight

    print("Setting PayPal email for " + username + " to " + email)

    SET_EMAIL = """
            UPDATE participants
               SET paypal_email=%s{}
             WHERE username=%s;
    """.format(FEE_CAP)
    print(SET_EMAIL % (email, username))

    db.run(SET_EMAIL, (email, username))

    print("All done.")
Ejemplo n.º 18
0
 def setUpClass(cls):
     cls.db = gittip.db = wireup.db()
Ejemplo n.º 19
0
    """Given an URL path, return response.
    """
    request = StubRequest(path)
    request.website = test_website
    if user is not None:
        user = User.from_id(user)
        # Note that Cookie needs a bytestring.
        request.headers.cookie[str('session')] = user.session_token
    response = test_website.handle_safely(request)
    return response

def load_simplate(path):
    """Given an URL path, return resource.
    """
    request = StubRequest(path)
    request.website = test_website

    # XXX HACK - aspen.website should be refactored
    from aspen import dispatcher, sockets
    test_website.hooks.run('inbound_early', request)
    dispatcher.dispatch(request)  # sets request.fs
    request.socket = sockets.get(request)
    test_website.hooks.run('inbound_late', request)

    return resources.get(request)

if __name__ == "__main__":
    """ One additional DB connection during testing occurs """
    db = wireup.db()
    populate_db_with_dummy_data(db)
Ejemplo n.º 20
0
Usage:

    [gittip] $ heroku config -s -a gittip | foreman run -e /dev/stdin ./env/bin/python ./scripts/untip.py "username"

"""
from __future__ import print_function

import sys

from gittip import wireup


tippee = sys.argv[1] # will fail with KeyError if missing

db = wireup.db()

tips = db.all("""

    SELECT amount
         , ( SELECT participants.*::participants
               FROM participants
              WHERE username=tipper
            ) AS tipper
         , ( SELECT participants.*::participants
               FROM participants
              WHERE username=tippee
            ) AS tippee
      FROM current_tips
     WHERE tippee = %s
       AND amount > 0
Ejemplo n.º 21
0
def main():
    populate_db(wireup.db())
Ejemplo n.º 22
0
def main():
    populate_db(wireup.db(wireup.env()))
Ejemplo n.º 23
0
 def __init__(self):
     self.db = wireup.db()
     self.billing = wireup.billing()
     self._delete_data()
Ejemplo n.º 24
0
 def setUpClass(cls):
     cls.db = gittip.db = wireup.db()
Ejemplo n.º 25
0
 def __init__(self):
     self.db = wireup.db()
     self.billing = wireup.billing()
     self._delete_data()
Ejemplo n.º 26
0
#!/usr/bin/env python
"""Distribute a balance as a final gift. This addresses part of #54.

Usage:

    [gittip] $ heroku config -s -a gittip | foreman run -e /dev/stdin ./env/bin/python ./bin/final-gift.py "username" [first-eight-of-api-key]

"""
from __future__ import print_function

import sys

from gittip import wireup
from gittip.models.participant import Participant

db = wireup.db(wireup.env())

username = sys.argv[1] # will fail with KeyError if missing
tipper = Participant.from_username(username)
if len(sys.argv) < 3:
    first_eight = "unknown!"
else:
    first_eight = sys.argv[2]

# Ensure user is legit
FIELDS = """
        SELECT username, username_lower, api_key, claimed_time
          FROM participants
         WHERE username = %s
"""
Ejemplo n.º 27
0
 def setUp(self):
     super(TestBillingCharges, self).setUp()
     self.postgres = wireup.db()
     self.payday = Payday(self.postgres)
     self.alice = self.make_participant('alice')
Ejemplo n.º 28
0
def set_paypal_email(username='', email='', api_key_fragment='', overwrite=False):
    """
    Usage:

    [gittip] $ env/bin/invoke set_paypal_email --username=username [email protected] [--api-key-fragment=12e4s678] [--overwrite]
    """

    if not os.environ.get('DATABASE_URL'):
        load_prod_envvars()

    if not username or not email:
        print(set_paypal_email.__doc__)
        sys.exit(1)

    if not api_key_fragment:
        first_eight = "unknown!"
    else:
        first_eight = api_key_fragment

    db = wireup.db(wireup.env())

    FIELDS = """
            SELECT username, api_key, paypal_email
              FROM participants
             WHERE username = %s
    """

    fields = db.one(FIELDS, (username,))

    print(fields)

    if fields == None:
        print("No Gittip participant found with username '" + username + "'")
        sys.exit(2)

    # PayPal caps the MassPay fee at $20 for users outside the U.S., and $1 for
    # users inside the U.S. Most Gittip users using PayPal are outside the U.S.
    # so we set to $20 and I'll manually adjust to $1 when running MassPay and
    # noticing that something is off.
    FEE_CAP = ', paypal_fee_cap=20'

    if fields.paypal_email != None:
        print("PayPal email is already set to: " + fields.paypal_email)
        if not overwrite:
            print("Not overwriting existing PayPal email.")
            sys.exit(3)
        else:
            FEE_CAP = ''  # Don't overwrite fee_cap when overwriting email address.

    if fields.api_key == None:
        assert first_eight == "None"
    else:
        assert fields.api_key[0:8] == first_eight

    print("Setting PayPal email for " + username + " to " + email)

    SET_EMAIL = """
            UPDATE participants
               SET paypal_email=%s{}
             WHERE username=%s;
    """.format(FEE_CAP)
    print(SET_EMAIL % (email, username))

    db.run(SET_EMAIL, (email, username))

    print("All done.")
Ejemplo n.º 29
0
def main():
    db = orm.db
    dbsession = db.session
    gittip.db = wireup.db()
    populate_db(dbsession)
Ejemplo n.º 30
0
 def setUp(self):
     super(TestBillingPayday, self).setUp()
     self.postgres = wireup.db()
     self.payday = Payday(self.postgres)