From cfcad872f12cab8379cf2a1c13b5801b5a6b80a0 Mon Sep 17 00:00:00 2001 From: aakash0017 Date: Mon, 26 Apr 2021 22:25:44 +0530 Subject: [PATCH] added cms queries --- Notebooks Checkpoint/cms-queries.ipynb | 111 +++++++++++++++++++++++++ cms-queries/get-data.py | 0 cms-queries/post-data.py | 0 cms-queries/queries.py | 18 ++++ user_utility/user_utility.py | 2 +- utility/_utility.py | 4 +- utility/utility.py | 86 ------------------- 7 files changed, 132 insertions(+), 89 deletions(-) create mode 100644 Notebooks Checkpoint/cms-queries.ipynb delete mode 100644 cms-queries/get-data.py delete mode 100644 cms-queries/post-data.py create mode 100644 cms-queries/queries.py delete mode 100644 utility/utility.py diff --git a/Notebooks Checkpoint/cms-queries.ipynb b/Notebooks Checkpoint/cms-queries.ipynb new file mode 100644 index 0000000..dcba809 --- /dev/null +++ b/Notebooks Checkpoint/cms-queries.ipynb @@ -0,0 +1,111 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "python385jvsc74a57bd00f9d6a5aaa2a7fee61cf68aafdfcdaf325adf07b0836eaa1104723ace1c314f3", + "display_name": "Python 3.8.5 64-bit ('base': conda)" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "\n", + "# url = 'http://localhost:1337/tests'\n", + "# myobj = {'Name': 'nidhir test1',\n", + "# 'Email': 'test3@test.com',\n", + "# 'Phoneno': 8384041898\n", + "# }\n", + "\n", + "# x = requests.post(url, data = myobj, headers = {\n", + "\n", + "# \"Authorization\": f\"Bearer {aakash_jwt}\"}\n", + "# )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "aakash_jwt = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwODY1ZDUxMDZiZWQyZDhlYzZjNmJjNyIsImlhdCI6MTYxOTQxODU1OSwiZXhwIjoxNjIyMDEwNTU5fQ.Y52bTH80hazoVPomjX9jyE4LyyOKkEnZIRjAwgPeIuY\"" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "url = 'http://localhost:1337/tests'\n", + "myobj = {'Name': 'nidhir test1',\n", + " 'Email': 'test3@test.com',\n", + " 'Phoneno': 8384041898\n", + "}\n", + "\n", + "x = requests.get(url, headers = {\n", + "\n", + " \"Authorization\": f\"Bearer {aakash_jwt}\"}\n", + ")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "list" + ] + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "type(x.json())" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "myobj = {'Name': 'nidhir test1',\n", + " 'Email': 'test3@test.com',\n", + " 'Phoneno': 8384041898\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/cms-queries/get-data.py b/cms-queries/get-data.py deleted file mode 100644 index e69de29..0000000 diff --git a/cms-queries/post-data.py b/cms-queries/post-data.py deleted file mode 100644 index e69de29..0000000 diff --git a/cms-queries/queries.py b/cms-queries/queries.py new file mode 100644 index 0000000..e1f7182 --- /dev/null +++ b/cms-queries/queries.py @@ -0,0 +1,18 @@ +import requests + +aakash_jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwODY1ZDUxMDZiZWQyZDhlYzZjNmJjNyIsImlhdCI6MTYxOTQxODU1OSwiZXhwIjoxNjIyMDEwNTU5fQ.Y52bTH80hazoVPomjX9jyE4LyyOKkEnZIRjAwgPeIuY" + + +def get_request(endpoint, environment = 'local', url = 'http://localhost:1337/'): + + url = url + endpoint + res = requests.get(url, headers = {"Authorization": f"Bearer {aakash_jwt}"}) + return res.json() + + +def post_request(endpoint, body, environment = 'local', url = 'http://localhost:1337/'): + + url = url + endpoint + res = requests.post(url, data = body, headers = {"Authorization": f"Bearer {aakash_jwt}"} ) + return res.json() + diff --git a/user_utility/user_utility.py b/user_utility/user_utility.py index 89aa8e5..6114c12 100644 --- a/user_utility/user_utility.py +++ b/user_utility/user_utility.py @@ -16,4 +16,4 @@ def example(): dict_ = dict(zip(list_, [0]*len(list_))) return update_dict(dict_, 'Oximeter') -# print(example()) \ No newline at end of file +print(example()) \ No newline at end of file diff --git a/utility/_utility.py b/utility/_utility.py index df98ff0..edaedb0 100644 --- a/utility/_utility.py +++ b/utility/_utility.py @@ -58,9 +58,9 @@ def most_similar(user_input, input_type): def load_cities(): - return np.load('../data/cities.npy', allow_pickle=True) + return np.load('data/cities.npy', allow_pickle=True) def load_resources(): - return np.load('../data/res.npy', allow_pickle=True) + return np.load('data/res.npy', allow_pickle=True) print(take_input('res')) \ No newline at end of file diff --git a/utility/utility.py b/utility/utility.py deleted file mode 100644 index 888f8f7..0000000 --- a/utility/utility.py +++ /dev/null @@ -1,86 +0,0 @@ -from data.resource_dict import resource_dict -import numpy as np -import enchant -import numpy as np -import sys -sys.path.append('../') - - -def handle_invalid_input(user_input, input_type): - cities_list = np.load('../data/cities.npy', allow_pickle=True) - resource_list = np.load('../data/res.npy', allow_pickle=True) - possible_input = [] - if input_type == 'city': - possible_input = [i.lower() - for i in cities_list if user_input[0] == i[0].lower()] - return possible_input - - elif input_type == 'resources': - possible_input = [i.lower() - for i in resource_list if user_input[0] == i[0].lower()] - return possible_input - else: - return 'please enter a valid input' - - -def check_validity(user_input, input_type): - - if input_type == 'int': - if check_integer_input(user_input) != 'invalid': - return user_input - else: - user_input_status = check_similarity(user_input, input_type) - - if user_input_status == 'invalid': - user_input = handle_invalid_input(user_input, input_type) - status = 'invalid' - return [status, user_input] - else: - user_input = check_similarity(user_input, input_type) - return user_input - - -def take_input(input_type): - # user_input = input("") - user_input = 'jaipur' - if input_type == 'city': - user_input = user_input.lower() - else: - user_input = int(user_input) - - processed_input = check_validity(user_input, input_type) - return processed_input - -def check_integer_input(user_input): - return user_input - - -def example_main(): - processed_input = take_input('city') - return processed_input - - -def check_similarity(user_input, type_input): - resource_list = resource_dict() - cities_list = np.load('../data/cities.npy', allow_pickle=True) - - if type_input == 'city': - most_similar = [] - for i in cities_list: - if enchant.utils.levenshtein(user_input.lower(), i) < 4: - most_similar.append(i) - if len(most_similar) == 0: - return 'invalid' - return most_similar[0].lower() - - if type_input == 'resources': - most_similar = [] - for i in resource_list: - if enchant.utils.levenshtein(user_input.lower(), resource_list[i]) < 4: - most_similar.append(i) - if len(most_similar) == 0: - return 'invalid' - return most_similar[0].lower() - - -print(example_main())