<commit_before>from django.utils import timezone
from django.conf import settings
from channels import Group
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.conf import settings
import json


def ws_connect(message):
    message.reply_channel.send({"accept": True})


def ws_message(message):
    body = json.loads(message.content['text'])
    if body["event"] == "ConnectionEstablished":
        Group(body["socketId"]).add(message.reply_channel)

    elif body["event"] == "fetchCurrentPort":
        text = json.dumps({
            "data": settings.PORT,
                    "event": "fetchedCurrentPort"
        })
        message.reply_channel.send({"text": text})

    elif body["event"] == "getPublicIPaddress":
        text = json.dumps({
            "data": settings.HOST_NAME,
                    "event": "gotPublicIP"
        })
        message.reply_channel.send({"text": text})


@csrf_exempt
def inject(request):
    if request.method == "POST":
        body = json.loads(request.body)
        text = json.dumps({
            "data": body,
            "event": "injectOutputData"
        })
        Group(body["socketId"]).send({"text": text})
        return HttpResponse(status=200)<commit_msg>Update inject to use DRF (#76)<commit_after>from django.utils import timezone
from django.conf import settings
from channels import Group
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.conf import settings
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework import status as response_status
import json


def ws_connect(message):
    message.reply_channel.send({"accept": True})


def ws_message(message):
    body = json.loads(message.content['text'])
    if body["event"] == "ConnectionEstablished":
        Group(body["socketId"]).add(message.reply_channel)

    elif body["event"] == "fetchCurrentPort":
        text = json.dumps({
            "data": settings.PORT,
                    "event": "fetchedCurrentPort"
        })
        message.reply_channel.send({"text": text})

    elif body["event"] == "getPublicIPaddress":
        text = json.dumps({
            "data": settings.HOST_NAME,
                    "event": "gotPublicIP"
        })
        message.reply_channel.send({"text": text})


@csrf_exempt
@api_view(['POST'])
def inject(request):
    if request.method == "POST":
        body = request.data
        text = json.dumps({
            "data": body,
            "event": "injectOutputData"
        })
        Group(body["socketId"]).send({"text": text})
        return Response(status=response_status.HTTP_200_OK)
{'fraction_non_alphanumeric': 0.12729948491537896, 'fraction_numerical': 0.0029433406916850625, 'mean_word_length': 2.9693430656934305, 'pattern_counts': {'":': 28, '<': 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': '1018132', 'n_tokens_mistral': 787, 'n_tokens_neox': 763, 'n_words': 175}