<commit_before>from app.bot import BaseProcessor, BotProcessorFactory
from splitwise import Splitwise
from splitwise.expense import Expense
from splitwise.user import ExpenseUser

USER_TOKEN = ''
USER_SECRET = ''

APP_KEY = ''
APP_SECRET = ''
DESC = "description"
SPLIT = "split"
PAID = "paid"
OWE = "owe"
AMOUNT = 'amount'
OUTPUT = "New Expense has been added between You and "
EQUALLY = "equally"
BOT = "From Bot"
NAME = "name"
class SplitwiseBotProcessorFactory(BotProcessorFactory):

    def __init__(self):
        pass

    def getProcessor(self, action):
        if action == 'transaction':
            return TransactionProcessor()


class TransactionProcessor(BaseProcessor):

    def __init__(self):
        pass

    def process(self, input):
        output = OUTPUT
        splitwiseobj = Splitwise(APP_KEY, APP_SECRET)
        splitwiseobj.setAccessToken(
            {
                "oauth_token": USER_TOKEN, "oauth_token_secret": USER_SECRET
            }
        )
        currentUser = splitwiseobj.getCurrentUser()
        friendslist = splitwiseobj.getFriends()

        userlist = []
        amount = input.get(AMOUNT)

        expense = Expense()
        expense.setCost(amount)
        
        mode = input.get(SPLIT).lower()

        description = ''
        if DESC in input:
            description = input.get(DESC) 
        else:
            description = BOT

        expense.setDescription(description)
        
        # current user
        paid, owed = self.getDistribution(mode, amount)
        cuser = self.getExpenseUser(currentUser, paid, owed)
        userlist.append(cuser)

        for friend in friendslist:
            if friend.getFirstName().lower() == input.get(NAME).lower():
                expenseuser = self.getExpenseUser(friend,owed,paid)
                if mode != PAID and mode != OWE:
                    expenseuser.setPaidShare(str(0))
                    expenseuser.setOwedShare(str(owed))
                
                output += friend.getFirstName()
                userlist.append(expenseuser)
                break
        
        expense.setUsers(userlist)
        expense = splitwiseobj.createExpense(expense)
        return output
    
    def getDistribution(self, mode, amount):
        if mode == PAID:
            paid = amount
            owed = 0
        elif mode == OWE:
            paid = 0
            owed = amount
        else:
            paid = amount
            owed = amount/2.0
        return paid, owed

    def getExpenseUser(self, friend, paid, owed):
        user = ExpenseUser()
        user.setId(friend.getId())
        user.setPaidShare(str(paid))
        user.setOwedShare(str(owed))
        return user<commit_msg>Added Greeting processor<commit_after>from app.bot import BaseProcessor, BotProcessorFactory
from splitwise import Splitwise
from splitwise.expense import Expense
from splitwise.user import ExpenseUser

import random

USER_TOKEN = ''
USER_SECRET = ''

APP_KEY = ''
APP_SECRET = ''
DESC = "description"
SPLIT = "split"
PAID = "paid"
OWE = "owe"
AMOUNT = 'amount'
OUTPUT = "New Expense has been added between You and "
EQUALLY = "equally"
BOT = "From Bot"
NAME = "name"
GREETING1 = "Hey, How can i help you?"
GREETING2 = "Hello, may i help you any way?"
GREETING3 = "Hi, you need any help?"


class SplitwiseBotProcessorFactory(BotProcessorFactory):

    def __init__(self):
        pass

    def getProcessor(self, action):
        if action == 'transaction':
            return TransactionProcessor()


class TransactionProcessor(BaseProcessor):

    def __init__(self):
        pass

    def process(self, input):
        output = OUTPUT
        splitwiseobj = Splitwise(APP_KEY, APP_SECRET)
        splitwiseobj.setAccessToken(
            {
                "oauth_token": USER_TOKEN, "oauth_token_secret": USER_SECRET
            }
        )
        currentUser = splitwiseobj.getCurrentUser()
        friendslist = splitwiseobj.getFriends()

        userlist = []
        amount = input.get(AMOUNT)

        expense = Expense()
        expense.setCost(amount)
        
        mode = input.get(SPLIT).lower()

        description = ''
        if DESC in input:
            description = input.get(DESC) 
        else:
            description = BOT

        expense.setDescription(description)
        
        # current user
        paid, owed = self.getDistribution(mode, amount)
        cuser = self.getExpenseUser(currentUser, paid, owed)
        userlist.append(cuser)

        for friend in friendslist:
            if friend.getFirstName().lower() == input.get(NAME).lower():
                expenseuser = self.getExpenseUser(friend,owed,paid)
                if mode != PAID and mode != OWE:
                    expenseuser.setPaidShare(str(0))
                    expenseuser.setOwedShare(str(owed))
                
                output += friend.getFirstName()
                userlist.append(expenseuser)
                break
        
        expense.setUsers(userlist)
        expense = splitwiseobj.createExpense(expense)
        return output
    
    def getDistribution(self, mode, amount):
        if mode == PAID:
            paid = amount
            owed = 0
        elif mode == OWE:
            paid = 0
            owed = amount
        else:
            paid = amount
            owed = amount/2.0
        return paid, owed

    def getExpenseUser(self, friend, paid, owed):
        user = ExpenseUser()
        user.setId(friend.getId())
        user.setPaidShare(str(paid))
        user.setOwedShare(str(owed))
        return user

class GreetingProcessor(BaseProcessor):
    
    def __init__(self):
        self.greetings = []
        self.greetings.append(GREETING1)
        self.greetings.append(GREETING2)
        self.greetings.append(GREETING3)
    
    def process(self, input):
        return random.choice(self.greetings)
{'fraction_non_alphanumeric': 0.09101735284110242, 'fraction_numerical': 0.0027220142905750254, 'mean_word_length': 2.0445365095805283, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1649332', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1667, 'n_words': 389}