Created
July 9, 2022 11:56
-
-
Save dubeyji10/240a2f828c5bb81f3a550ddd61761a3d to your computer and use it in GitHub Desktop.
api response working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.client import HTTPResponse | |
import json | |
from django.shortcuts import render | |
from django.views.generic import ListView | |
import os | |
from requests import request | |
from . import forms | |
from django.views import View | |
from django.views.generic.edit import FormView | |
from django.utils.dateformat import format | |
from django.shortcuts import redirect | |
import requests | |
dir_path = os.path.dirname(os.path.realpath(__file__)) | |
print('---dir_path-- : ',dir_path) | |
urlGotoMeeting = "https://api.getgo.com/G2M/rest/historicalMeetings?startDate={}&endDate={}" | |
''' | |
always refresh tokens first before making any api call | |
''' | |
# views on ratings data. | |
def getrating(request): | |
return render(request, 'getdata/getrating.html', {'title': 'getrating'}) | |
def index(request): | |
return render(request, 'getmain/base_templates/analysis_index.html', {'title': 'index'}) | |
def show(request): | |
employees = Employee.objects.all() | |
return render(request,"accounts/show.html",{'employees':employees}) | |
# writing a custom view to handle form input and display at the same time | |
# example from https://www.digitalocean.com/community/tutorials/how-to-build-a-weather-app-in-django | |
#example date pattern -- | |
# startDate = "2022-05-01T12:00:00Z" | |
# method to get meeting response from gotomeeting api | |
def getmeetingresponse(startDate , endDate): | |
access_token = None | |
print('-'*50) | |
print("1. getting access tokens") | |
with open(dir_path+'/gotomeeting/refresh_tokens.json','r') as f: | |
myJson = json.load(f) | |
access_token = myJson['access_token'] | |
response = None | |
headers = { | |
'Authorization': 'Bearer '+access_token | |
} | |
print("2. getting meetings from {} to {}\n\nwith header : \n".format(startDate , endDate , headers['Authorization'])) | |
urlMeeting = urlGotoMeeting.format(''.join([str(startDate),'T12:00:00Z']) ,''.join([str(endDate),'T12:00:00Z'])) | |
print("3. request made : ",urlMeeting) | |
response = requests.request("GET" , url=urlMeeting , headers=headers) | |
print('4. response-code: ',response.status_code) | |
print('5. rendering with variable data') | |
print('-'*50) | |
return [response.text] | |
def meetingFormView(request): | |
# testing purpose hardcoding allDataJsons | |
allDataJsons = ['abcdefgd'] | |
myJsonMeetings = None | |
# print('1->',request.POST) | |
# print('2->',request.POST.mycity) | |
if request.method=='POST': | |
print('here') | |
print('1->',request.POST) | |
startDate = request.POST['startDate'] | |
endDate = request.POST['endDate'] | |
print('2->',request.POST['startDate']) | |
print('3->',request.POST['endDate']) | |
allDataJsons = [] | |
# filePath = dir_path+"/gotomeeting/meetings_2.json" | |
allDataJsons = getmeetingresponse(startDate , endDate) | |
result = { | |
'data' : allDataJsons, | |
'message' : "getting meetings between {} and {}".format( ''.join([str(startDate),'T12:00:00Z']), ''.join([str(endDate),'T12:00:00Z'])) | |
} | |
# print('5-> result : ',result) | |
return render(request, 'getdata/meetingList.html',result) #returns the index.html template | |
return render(request, 'getdata/MeetingForm.html') #returns the index.html template |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment