https://github.com/thealoneprogrammer/bad-words-filtering
https://github.com/thealoneprogrammer/bad-words-filtering
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/thealoneprogrammer/bad-words-filtering
- Owner: thealoneprogrammer
- Created: 2019-03-07T15:32:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-08T18:58:56.000Z (over 6 years ago)
- Last Synced: 2024-12-27T15:11:03.735Z (11 months ago)
- Language: Python
- Size: 14.7 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)
]
```

