Exemplo n.º 1
0
def chat_view(request):
    dialogflow = Dialogflow(**settings.DIALOGFLOW)
    input_dict = convert(request.body)
    input_text = json.loads(input_dict)['text']
    responses = dialogflow.text_request(str(input_text))

    if request.method == 'GET':

        data = {
            'detail': 'You should make a POST request to this endpoint',
            'name': '/chat'
        }
        return JsonResponse(data, status=405)
    elif request.method == 'POST':
        data = {
            'text': responses[0],
        }
        return JsonResponse(data, status=200)
    elif request.method == "PATCH":
        data = {
            'detail': 'You should make a POST request to this endpoint.',
            'name': '/chat'
        }
        return JsonResponse(data, status=405)
    elif request.method == "DELETE":
        data = {
            'detail': 'You should make a POST request to this endpoint.',
            'name': '/chat'
        }

        return JsonResponse(data, status=405)
Exemplo n.º 2
0
def chat_view(request):
    dialogflow = Dialogflow(**settings.DIALOGFLOW)
    input_dict = convert(request.body)
    input_text = json.loads(input_dict)['text']
    responses = dialogflow.text_request(str(input_text))

    if request.method == "GET":
        # Return a method not allowed response
        data = {
            'detail': 'You should make a POST request to this endpoint.',
            'name': '/chat'
        }
        return JsonResponse(data, status=405)
    elif request.method == "POST":

        data = {
            'text': responses[0],
        }
        print(str(input_text))
        out_str = ''
        MedicinesModel = Medicines.objects.all()
        for medicine in MedicinesModel:
            if str(input_text).find(medicine.name) != -1:
                print(medicine.name)
                out_str += 'Medicine Information --> ' + medicine.name + ' :: '
                if medicine.alternative_medicines is not None:
                    out_str += 'Alternative Medicines --> ' + medicine.alternative_medicines + ' :: '
                out_str += 'Medicine Indication --> ' + medicine.indication
                AllStores = Stores.objects.all()
                out_str += ':: Medicine are available at store --> '
                for store in AllStores:
                    #print('store available'+store.medicines_available)
                    if str(medicine.name) in store.medicines_available:
                        out_str += 'Store Name: ' + store.name + ' Address: ' + store.address
                        print('store available')
                data = {
                    'text': out_str,
                }

        return JsonResponse(data, status=200)
    elif request.method == "PATCH":
        data = {
            'detail': 'You should make a POST request to this endpoint.',
            'name': '/chat'
        }

        # Return a method not allowed response
        return JsonResponse(data, status=405)

    elif request.method == "DELETE":
        data = {
            'detail': 'You should make a POST request to this endpoint.',
            'name': '/chat'
        }

        # Return a method not allowed response
        return JsonResponse(data, status=405)
Exemplo n.º 3
0
def chat(request):

    if request.method == 'POST':
        form = ChatForm(request.POST)
        if form.is_valid():
            mess = form.save(commit=False)
            user_uid = Profile.objects.get(user=request.user)
            mess.user_uuid = user_uid
            dialogflow = Dialogflow(**settings.DIALOGFLOW)
            responses = dialogflow.text_request(str(mess.message))
            mess.response = responses[0]

            if(len(mess.response.split())!=2):
                mess.save()

                return render(request, 'chat.html', {'mess': mess})

            else:
                source, destination = mess.response.split()
                source_code_response = requests.get('https://api.railwayapi.com/v2/name-to-code/station/'+source+'/apikey/rfgbncxndq/')
                dest_code_response = requests.get('https://api.railwayapi.com/v2/name-to-code/station/'+destination+'/apikey/rfgbncxndq/')

                source_code_json = source_code_response.json()
                dest_code_json = dest_code_response.json()


                source_code = source_code_json["stations"][0]["code"]
                dest_code = dest_code_json["stations"][0]["code"]


                final_response = requests.get('https://api.railwayapi.com/v2/between/source/'+source_code+'/dest/'+dest_code+'/date/<15-09-2018>/apikey/rfgbncxndq/')
                final_response_json = final_response.json()
                final_response_string = json.dumps(final_response_json)
                mess.response = final_response_string
                mess.save()

                return render(request, 'chat.html', {'mess': mess})

    else:
        form = ChatForm()

    return render(request, 'sendMessage.html', {'form': form})
Exemplo n.º 4
0
def view_store(request):
    client_access_token = '0bb7a3b7450f4159a441699a80ed6ade'
    dialogflow = Dialogflow(client_access_token=client_access_token)
    input_dict = convert(request.body)
    action = json.loads(input_dict)['queryResult']['action']
    parameters = json.loads(input_dict)['queryResult']['parameters']
    if request.method == "POST":
        
        if (action == 'goodnight'):
            Text = json.loads(input_dict)['queryResult']['fulfillmentMessages'][0]['text']['text'][0]
            Answer = json.loads(input_dict)['queryResult']['fulfillmentMessages']
            ans = parameters['agree']
            if ans == 'yes':
                mixer.init()
                mixer.music.load('/home/pi/Downloads/lalluby.mp3')
                mixer.music.play()
                
        if (action == 'stop_music'):
            Text = json.loads(input_dict)['queryResult']['fulfillmentMessages'][0]['text']['text'][0]
            Answer = json.loads(input_dict)['queryResult']['fulfillmentMessages']
            mixer.music.stop()
        
        if (action == 'rotation'):
            Text = json.loads(input_dict)['queryResult']['fulfillmentMessages'][0]['text']['text'][0]
            Answer = json.loads(input_dict)['queryResult']['fulfillmentMessages']
        
        if (action == 'brightness'):
            Text = json.loads(input_dict)['queryResult']['fulfillmentMessages'][0]['text']['text'][0]
            Answer = json.loads(input_dict)['queryResult']['fulfillmentMessages']
            
            if (parameters['temp'] == 'cold'):
                color = 100
            if (parameters['temp'] == 'warm'):
                color = 100
                
            bright = parameters['bright']
            print('Light')
            light.writeNumber(color, bright)
        
        if (action == 'up_down'):
            Text = json.loads(input_dict)['queryResult']['fulfillmentMessages'][0]['text']['text'][0]
            Answer = json.loads(input_dict)['queryResult']['fulfillmentMessages']
            if parameters['up_down'] == 'up':
                angle = parameters['value']
            if parameters['up_down'] == 'down':
                angle = -1 * parameters['value']
            servo.SetAngle(angle)
            
    data = {'fulfillmentText': Text, 'fulfillmentMessages': Answer}
    return HttpResponse(json.dumps(data))
Exemplo n.º 5
0
def view_store(request):
    client_access_token = 'a4074b8968b642569227649d49ea41eb'
    dialogflow = Dialogflow(client_access_token=client_access_token)
    input_dict = convert(request.body)
    action = json.loads(input_dict)['queryResult']['action']
    parameters = json.loads(input_dict)['queryResult']['parameters']
    if request.method == "POST":
        if (action == 'on_off'):
            if (str(parameters['switch_state']) == 'on'):
                On_Off(
                    on_off=1,
                ).save()
            if (str(parameters['switch_state']) == 'off'):
                On_Off(
                    on_off=0,
                ).save()

        if (action == 'rotation'):
            if (str(parameters['side']) == 'left'):
                Rotations(
                    corner=-1*parameters['rotate']
                ).save()
            if (str(parameters['side']) == 'right'):
                Rotations(
                    corner=parameters['rotate']
                ).save()

        if(action == 'brightness'):
            Bright(
                bright=parameters['bright']
            ).save()

        if (action == 'up_down'):
            if (str(parameters['up_down']) == 'down'):
                print(parameters['value'])
                Up_down(
                    up_down=-1 * parameters['value']
                ).save()
            if (str(parameters['up_down']) == 'up'):
                print(parameters['value'])
                Up_down(
                    up_down=parameters['value']
                ).save()



    data = {'fulfillmentText': json.loads(input_dict)['queryResult']['fulfillmentText'], 'fulfillmentMessages': json.loads(input_dict)['queryResult']['fulfillmentMessages']}
    return HttpResponse(json.dumps(data))
Exemplo n.º 6
0
#!/usr/bin/env python

from dialogflow_lite.dialogflow import Dialogflow

# demo agent access token: e5dc21cab6df451c866bf5efacb40178
client_access_token = 'e5dc21cab6df451c866bf5efacb40178'
dialogflow = Dialogflow(client_access_token=client_access_token)
response = dialogflow.text_request('how are you')
print(response)
response = dialogflow.text_request('howz the weather today')
print(response)
Exemplo n.º 7
0
from lxml import html
import re
from dateutil import tz
from datetime import datetime
from covid import Covid  #new
import requests

#Token
token = "1014221587:AAHe6wUDSBf47Oj1Lb_JMEk8EgBmYU0yKvY"
bot = telebot.TeleBot(token=token)
STICKER_ID = 'CAADAgADXwMAAgw7AAEKTh8jAAH9Q-gAAQI'
#client = Client('ylFpj3mg5MhcKlQGkSnqcnyU1NCQm88KicZVFLHV')
url = 'https://api.nasa.gov/planetary/apod?'  # I don't get how url queries work, someone help
API_KEY = 'api_key=ylFpj3mg5MhcKlQGkSnqcnyU1NCQm88KicZVFLHV'  #own API key, please register for your own at NASA Open APIs
client_access_token = '7f9559e9436744a9bef9a562551c16ff'
dialogflow = Dialogflow(client_access_token=client_access_token)
genius = lyricsgenius.Genius(
    "cw_sMUY8L7tqlykWOqiWwasqcPq_9SofNKX8CxKyOMIarw4TABsU2x6WxSeKol_j")
translator = Translator()
c = CurrencyRates()
tmdb = TMDb()
tmdb.api_key = 'ee01893e3d8f4d2026795ad38b8bb5fe'
tmdb.language = 'en'
movie = Movie()
covid = Covid(source="worldometers")
confirmed_t = covid.get_total_confirmed_cases()
deaths_t = covid.get_total_deaths()
recovered_t = covid.get_total_recovered()
#c = CurrencyConverter()