-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswearjar.py
executable file
·54 lines (42 loc) · 1.56 KB
/
swearjar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from swearlist import swears
from batch_postgres import BatchPostgres
from profanity_check import predict, predict_prob
import os
import math
class Swearjar(object):
defaultSwearIncrement = 1
def __init__(self):
self.swearlist = swears
self.defaultMultiplier = 0.25
self.storage = BatchPostgres()
self.userSwearCountCache = {}
def hasSwear(self, text):
result = predict_prob([text])
return result > 0.5
#return set(x.lower() for x in text.split()) & self.swearlist
def getSwearList(self):
return self.swears
def addToSwearJar(self, user, swearIncrement = defaultSwearIncrement):
swearCount = self.storage.incrementSwearCount(user, swearIncrement)
self.userSwearCountCache[user] = swearCount
return swearCount
def checkSwearJar(self, user):
if user in self.userSwearCountCache:
return self.userSwearCountCache[user]
return self.storage.getSwearCount(user)
def getMoneyOwed(self, user):
return self.swearsToDollarAmount(self.checkSwearJar(user))
def addNewUser(self, userinfo):
return self.storage.addNewUser(userinfo)
def getUserData(self, user):
return self.storage.getUserData(user)
def getAllBalances(self):
swearCounts = self.storage.getAllUserSwearCounts()
balances = "Balances: \n"
for userSwearCount in swearCounts:
balances += "%s: $%.2f\n" % (userSwearCount[1], self.swearsToDollarAmount(userSwearCount[2]))
self.userSwearCountCache[userSwearCount[0]] = userSwearCount[2]
return balances
def swearsToDollarAmount(self, swears):
money = swears * self.defaultMultiplier
return math.ceil(money * 100) / 100