Last active
July 11, 2022 12:33
-
-
Save dubeyji10/2999fd4f9e5731bd7a5f6aa89a7a149b to your computer and use it in GitHub Desktop.
modifications in gotomeeting api rendering - a json response is sent
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
{% extends "main/base_templates/base.html" %} | |
{% block content %} | |
{% if result %} | |
----- call api with ----- | |
{{ message }} | |
{% else %} | |
<div> enter your details here </div> | |
{% endif %} | |
<form target="_blank" action = "" method = "POST"> | |
{% csrf_token %} | |
<label for="startDate">Start Date: </label> | |
<input id="startDate" type="date" name="startDate"> | |
<br> | |
<label for="endDate">End Date: </label> | |
<input id="endDate" type="date" name="endDate"><br> | |
<input type="submit" value="OK"> | |
</form> | |
{% endblock content%} |
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
{% load static %} | |
<html> | |
<style> | |
#tableData{ | |
background-color: rgb(247, 221, 175); | |
padding-top: 20px; | |
padding-bottom: 20px; | |
padding-left: 1%; | |
padding-right: 1%; | |
margin-left: 2%; | |
margin-right: 2%; | |
} | |
#tableTopic_wrapper , #tableTopic_length{ | |
margin-right: 10px; | |
margin-bottom: 20px; | |
} | |
#tableTopic tr{ | |
background-color: antiquewhite; | |
font-size: smaller; | |
} | |
#tableTopic td{ | |
background-color: rgb(253, 245, 245); | |
color: #000000; | |
font-size: smaller; | |
white-space: pre; | |
} | |
</style> | |
<title>Meetings List</title> | |
<link rel="stylesheet" type="text/css" href="{% static 'main/css/main.css' %}"/> | |
<h1> | |
not extending base template -- | |
<br>has multiple versions of jquery which results in datatables rendering error | |
</h1> | |
<!-- datatables cdn --> | |
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/dt-1.10.22/datatables.min.css"/> | |
<!-- ✅ load jQuery ✅ --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<!-- ✅ load DataTables ✅ --> | |
<script type="text/javascript" src="https://cdn.datatables.net/r/dt/dt-1.10.22/datatables.min.js"></script> | |
<!-- datatables cdn end --> | |
<script> | |
$(document).ready(function() { | |
getDataForDatatables(); | |
}); | |
console.log("---running this---"); | |
var myMeetingsJson = "{{data}}"; | |
const enocodedjson = myMeetingsJson; | |
const json = enocodedjson.replace(/'/gm, '"'); | |
const myData = JSON.parse(json); | |
function getDataForDatatables(){ | |
var jsonData = { | |
"data" : myData | |
}; | |
setDataToTable(jsonData); | |
} | |
/* set data tables */ | |
function setDataToTable(jsonData){ | |
console.log("__________1__________"); | |
console.log(jsonData); | |
console.log("\n\n ......................... 2 ......................... \n\n"); | |
$('#tableTopic').DataTable( { | |
pagination: "bootstrap", | |
filter:true, | |
data: jsonData.data, | |
destroy: true, | |
lengthMenu:[5,10], | |
pageLength: 50, | |
"columns":[ | |
{ "data" : "subject" }, | |
{ "data" : "meetingId" }, | |
{ "data" : "duration" }, | |
{ "data" : "numAttendees" }, | |
{ "data" : "startTime" }, | |
{ "data" : "endTime" }, | |
{ "data" : "recording" }, | |
] | |
} ); | |
} | |
</script> | |
<div id="proper-rendering"> | |
here proper rendering of data | |
</div> | |
<div> | |
Message : {{message}} | |
<br><hr> | |
<div> using datatables to render </div><br><hr><br> | |
<div id="body"> | |
<div id="tableData"> | |
<table id="tableTopic" class="display" cellspacing="0" width="100%"> | |
<thead> | |
<tr> | |
<th>Subject</th> | |
<th>ID</th> | |
<th>Duration</th> | |
<th>#</th> | |
<th>Start</th> | |
<th>End</th> | |
<th>recording</th> | |
</tr> | |
</thead> | |
</table> | |
</div> | |
</div> | |
</div> | |
</html> |
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 , DetailView | |
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 | |
import threading | |
import time | |
dir_path = os.path.dirname(os.path.realpath(__file__)) | |
print('---dir_path-- : ',dir_path) | |
urlGotoMeeting = "https://api.getgo.com/G2M/rest/historicalMeetings?startDate={}&endDate={}" | |
urlToRefresh = 'https://api.getgo.com/oauth/v2/token' | |
grant_type = 'refresh_token' | |
refresh_token = None | |
client_code = None | |
def refresh_token_function(): | |
global refresh_token , client_code | |
myRefreshJSON =None | |
print('1. reading client code and refresh token') | |
with open(dir_path+'/gotomeeting/credentialsForRefresh.json','r') as f: | |
myJson = json.load(f) | |
refresh_token = myJson['refresh_token'] | |
client_code = myJson['client_code'] | |
response = None | |
headers = { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Authorization': 'Basic '+client_code | |
} | |
myPayload = "grant_type={}&refresh_token={}".format(grant_type , refresh_token) | |
print('2. making refresh token request to',urlToRefresh) | |
response = requests.post(url=urlToRefresh , data=myPayload , headers=headers) | |
print('3. response-code: ',response.status_code) | |
print("4. saving new tokens in file") | |
with open(dir_path+'/gotomeeting/refresh_tokens.json',"w") as f: | |
f.write(response.text) | |
print("written to ",'refresh_tokens.json') | |
print('\n---------------done-----------------') | |
## refreshing tokens every 30 minutes | |
threading.Timer(1800.0, refresh_token_function).start() | |
print("--refreshing tokens at {}--".format(time.ctime())) | |
refresh_token_function() | |
''' | |
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] | |
return json.loads(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 | |
def gotomeetingresult(request): | |
print('you are here at ',request.path) | |
# print('result - \n',result) | |
return render(request, 'getdata/meetingList.html') #returns the index.html template | |
# --- my custom view for url for a pattern an example ---- | |
def testUrl_1(request): | |
result = { | |
'message' : ' try to get url pattern', | |
'data' : 'temporary data', | |
} | |
print('you made a request to path',request.path) | |
return render(request, 'getdata/testUrlTemplate.html',result) #returns the index.html template | |
def form2(request): | |
if request.method=='POST': | |
print(' here request has been made with params : \n',request.POST) | |
print('-'*50) | |
else: | |
print("a get request was made") | |
return render(request, 'getdata/MeetingForm2.html') #returns the index.html template | |
class MeetingView2(DetailView): | |
template_name = 'getdata/testUrlTemplate.html' | |
context_object_name = 'result' | |
def get_queryset(self): | |
result = super(MeetingView2, self).get_queryset() | |
print('1->result : ',result) | |
try: | |
query = self.request.GET.get('q') | |
postresult = 'put api call here' | |
result = postresult | |
print("query = {},\nresult = {}".format(query , result)) | |
except: | |
result = 'Sorry need to work on this request' | |
return result |
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 django.urls import path | |
from . import views | |
from django.conf.urls import url , re_path | |
# from .views import getMeetingClassView | |
app_name = 'getdata' | |
# http://127.0.0.1:8000/your-name/ | |
urlpatterns = [ | |
path('getrating/', views.getrating, name='data-getrating'), | |
path('index/', views.index, name='data-index'), | |
path('gotomeeting/',views.meetingFormView,name='meetingform1'), | |
# trying a url pattern for dates | |
# gotomeetingresult | |
path('gotomeetingresult/',views.gotomeetingresult,name='gotomeetingresult'), | |
# re_path(r'^gotomeeting/((?P<id>\d+)/$)',views.testUrl_1,name='urlwithpattern'), | |
path('gotomeetingform2/',views.form2,name='meetingform2'), | |
# re_path('gotomeeting/(?q<startdate>\w+)/$',views.testUrl_1,name='urlwithpattern'), | |
url('meetingformresult/<str:q>/', views.MeetingView2.as_view(), name='meetingformresult') | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment