An open API service indexing awesome lists of open source software.

https://github.com/thealoneprogrammer/bad-words-filtering


https://github.com/thealoneprogrammer/bad-words-filtering

Last synced: 15 days ago
JSON representation

Awesome Lists containing this project

README

          

This project basically filters the swear words by appending '*' at the respected position

This project is built on top of django.

**Some main parts to note**

**filter.py**

```python

import os

def process_string(string,):
result = ""
str_list = string.split()
strn_list = [i.lower() for i in str_list]

with open(os.path.dirname(__file__)+'/badwords.txt','r') as file:
for word in file:
word = word.split(', ')

for i in strn_list:
if i in word:
result += '*'*len(i)+" "
else:
result+=i+" "
return result
```

**views.py**

```python

from django.shortcuts import render
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from badApp import filter

@csrf_exempt
def getResult(request):
if request.method == 'GET':
return render(request, 'index.html')
if request.method == 'POST':
# getting values from post
string = request.POST.get('string')
response = filter.process_string(string)
print(response)
return render(request, 'response.html', {"r": response})

```

**urls.py**

```python

from django.contrib import admin
from django.urls import path
from badApp import views

urlpatterns = [
path('admin/', admin.site.urls),
path('',views.getResult)
]
```
![screenshot 90](https://user-images.githubusercontent.com/38497682/54049215-eb348900-4201-11e9-967e-e08745a70396.png)

![screenshot 91](https://user-images.githubusercontent.com/38497682/54049218-eec81000-4201-11e9-91cc-d4667441b774.png)