bugfix moodle xml file in curent dokumen file, test file, and migrate to showprogress bar
parent
978a488ae6
commit
3931a1f24e
|
@ -26,6 +26,7 @@ class gquiz:
|
||||||
self.infoPrint = self._defaultPrint
|
self.infoPrint = self._defaultPrint
|
||||||
self.progress = -1
|
self.progress = -1
|
||||||
self.resultUri = ""
|
self.resultUri = ""
|
||||||
|
self.savePath = './'
|
||||||
|
|
||||||
self.submition["requests"].append({
|
self.submition["requests"].append({
|
||||||
"updateSettings": {
|
"updateSettings": {
|
||||||
|
@ -40,6 +41,10 @@ class gquiz:
|
||||||
|
|
||||||
def setProgress(self, i : int):
|
def setProgress(self, i : int):
|
||||||
self.progress = i
|
self.progress = i
|
||||||
|
|
||||||
|
def setSavePath(self, path):
|
||||||
|
self.savePath = path
|
||||||
|
|
||||||
def AttachProcessInfo(self, callback):
|
def AttachProcessInfo(self, callback):
|
||||||
self.infoPrint = callback
|
self.infoPrint = callback
|
||||||
|
|
||||||
|
@ -71,7 +76,7 @@ class gquiz:
|
||||||
self.infoPrint("refresh token",self.progress)
|
self.infoPrint("refresh token",self.progress)
|
||||||
else:
|
else:
|
||||||
flow = InstalledAppFlow.from_client_secrets_file(
|
flow = InstalledAppFlow.from_client_secrets_file(
|
||||||
'./secret/client_secrets.json', SCOPES)
|
self.savePath+'/secret/client_secrets.json', SCOPES)
|
||||||
creds = flow.run_local_server(port=0)
|
creds = flow.run_local_server(port=0)
|
||||||
self.infoPrint("generate token",self.progress)
|
self.infoPrint("generate token",self.progress)
|
||||||
# Save the credentials for the next run
|
# Save the credentials for the next run
|
||||||
|
|
|
@ -9,6 +9,10 @@ class moodleQuiz:
|
||||||
self.progress = -1
|
self.progress = -1
|
||||||
self.resultUri = ""
|
self.resultUri = ""
|
||||||
self.data = ET.Element('quiz')
|
self.data = ET.Element('quiz')
|
||||||
|
self.savePath = '.'
|
||||||
|
|
||||||
|
def setSavePath(self, path):
|
||||||
|
self.savePath = path
|
||||||
|
|
||||||
def setProgress(self, i : int):
|
def setProgress(self, i : int):
|
||||||
self.progress = i
|
self.progress = i
|
||||||
|
@ -82,6 +86,6 @@ class moodleQuiz:
|
||||||
def update(self):
|
def update(self):
|
||||||
ET.indent(self.data)
|
ET.indent(self.data)
|
||||||
print(ET.tostring(self.data))
|
print(ET.tostring(self.data))
|
||||||
ET.ElementTree(self.data).write("./moodleXMLMultichoiceQuestion.xml")
|
ET.ElementTree(self.data).write("{}/{}".format(self.savePath, "moodleXMLMultichoiceQuestion.xml"))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import sys, os
|
||||||
|
import requests
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
# to run separatly from soffice
|
||||||
|
# $ soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
|
||||||
|
|
||||||
|
sys.path.append("/lib64/libreoffice/program/")
|
||||||
|
|
||||||
|
from scriptforge import ScriptForge, CreateScriptService
|
||||||
|
from unohelper import fileUrlToSystemPath
|
||||||
|
|
||||||
|
sys.path.insert(0, '{}/{}'.format(os.getcwd(),'Library'))
|
||||||
|
ScriptForge(hostname='localhost', port=2002)
|
||||||
|
|
||||||
|
from gquiz import gquiz
|
||||||
|
|
||||||
|
ui = CreateScriptService("UI")
|
||||||
|
doc = CreateScriptService("Calc")
|
||||||
|
bas = CreateScriptService("Basic")
|
||||||
|
|
||||||
|
q = gquiz()
|
||||||
|
q.generateService()
|
||||||
|
|
||||||
|
def get_file_id_from_link(link):
|
||||||
|
# Find the starting index of the file ID
|
||||||
|
start_index = -1
|
||||||
|
if "/d/" in link:
|
||||||
|
start_index = link.index("/d/") + 3
|
||||||
|
elif "id=" in link:
|
||||||
|
start_index = link.index("id=") + 3
|
||||||
|
elif "rs/" in link:
|
||||||
|
start_index = link.index("rs/") + 3
|
||||||
|
|
||||||
|
if start_index != -1:
|
||||||
|
# Find the ending index of the file ID
|
||||||
|
end_index = link.index("/", start_index)
|
||||||
|
if end_index == -1:
|
||||||
|
# If there is no trailing "/", use the end of the string
|
||||||
|
end_index = len(link)
|
||||||
|
|
||||||
|
# Extract the file ID
|
||||||
|
file_id = link[start_index:end_index]
|
||||||
|
return file_id
|
||||||
|
else:
|
||||||
|
# Return None if no file ID is found
|
||||||
|
return None
|
||||||
|
|
||||||
|
cells = doc.getValue("")
|
||||||
|
|
||||||
|
for col in range(0, len(cells)):
|
||||||
|
for row in range(0, len(cells[0])):
|
||||||
|
if(str(cells[col][row]).startswith("https://")):
|
||||||
|
print("found the culprit!!")
|
||||||
|
url = cells[col][row]
|
||||||
|
print(url)
|
||||||
|
Id=get_file_id_from_link(url)
|
||||||
|
file = q.drive_service.files().get(fileId=Id).execute()
|
||||||
|
newCell = "/asset/{newname}".format(newname=file["name"])
|
||||||
|
print("{new} <- {old}".format(new=newCell, old=cells[col][row]))
|
||||||
|
doc.setValue(doc.Offset("A1",col,row),newCell)
|
||||||
|
|
|
@ -13,27 +13,26 @@ import importlib
|
||||||
from scriptforge import ScriptForge, CreateScriptService
|
from scriptforge import ScriptForge, CreateScriptService
|
||||||
from unohelper import fileUrlToSystemPath
|
from unohelper import fileUrlToSystemPath
|
||||||
|
|
||||||
#[start] comment for run separatly from soffice
|
|
||||||
if (not 'gquiz' in sys.modules) or (not 'moodleQuiz' in sys.modules):
|
|
||||||
doc = XSCRIPTCONTEXT.getDocument()
|
|
||||||
url = fileUrlToSystemPath('{}/{}'.format(doc.URL,'Scripts/python/Library'))
|
|
||||||
sys.path.insert(0, url)
|
|
||||||
else:
|
|
||||||
importlib.reload(gquiz)
|
|
||||||
importlib.reload(moodleQuiz)
|
|
||||||
|
|
||||||
#[end]
|
|
||||||
#[start] uncomemnt for run separatly from soffice
|
|
||||||
#sys.path.insert(0, '{}/{}'.format(os.getcwd(),'Library'))
|
|
||||||
#ScriptForge(hostname='localhost', port=2002)
|
|
||||||
#[end]
|
|
||||||
|
|
||||||
from gquiz import gquiz
|
|
||||||
from moodleQuiz import moodleQuiz
|
|
||||||
|
|
||||||
ui = CreateScriptService("UI")
|
ui = CreateScriptService("UI")
|
||||||
doc = CreateScriptService("Calc")
|
doc = CreateScriptService("Calc")
|
||||||
bas = CreateScriptService("Basic")
|
bas = CreateScriptService("Basic")
|
||||||
|
url = fileUrlToSystemPath(XSCRIPTCONTEXT.getDocument().URL )
|
||||||
|
curpath = '/'.join([url.split('/')[x] for x in range(0,len(url.split('/'))-1)])
|
||||||
|
if not ui.Activate(url) :
|
||||||
|
bas.MsgBox("Error no window active",bas.MB_OK)
|
||||||
|
|
||||||
|
def _load_module():
|
||||||
|
#[start] comment for run embeded module
|
||||||
|
if (not 'gquiz' in sys.modules) or (not 'moodleQuiz' in sys.modules):
|
||||||
|
doc = XSCRIPTCONTEXT.getDocument()
|
||||||
|
urlem = '{}/{}'.format(url,'/Scripts/python/Library')
|
||||||
|
sys.path.insert(0, urlem)
|
||||||
|
_statusBarInfoUpdate("Load embedded modul link form {}".format(url),0)
|
||||||
|
#[end]
|
||||||
|
#[start] uncomemnt for run separatly from soffice
|
||||||
|
#sys.path.insert(0, '{}/{}'.format(os.getcwd(),'Library'))
|
||||||
|
#ScriptForge(hostname='localhost', port=2002)
|
||||||
|
#[end]
|
||||||
|
|
||||||
def MakeTemplate():
|
def MakeTemplate():
|
||||||
doc.SetArray(doc.CurrentSelection, \
|
doc.SetArray(doc.CurrentSelection, \
|
||||||
|
@ -45,11 +44,11 @@ def MakeTemplate():
|
||||||
"<isAnswerE>", "<IMG option5>", "<Text Option5>", ),))
|
"<isAnswerE>", "<IMG option5>", "<Text Option5>", ),))
|
||||||
|
|
||||||
def _statusBarInfoUpdate(text : str, progress : int):
|
def _statusBarInfoUpdate(text : str, progress : int):
|
||||||
ui.SetStatusbar("{}% {}".format(progress,text), progress)
|
ui.ShowProgressBar("loading...", "{}% {}".format(progress,text), progress)
|
||||||
|
|
||||||
def _updateQuestion(q):
|
def _updateQuestion(q):
|
||||||
selctedCell = doc.CurrentSelection
|
selctedCell = doc.CurrentSelection
|
||||||
cwd = os.getcwd()
|
cwd = curpath
|
||||||
maxRow = doc.LastRow(selctedCell)+1-doc.FirstRow(selctedCell)
|
maxRow = doc.LastRow(selctedCell)+1-doc.FirstRow(selctedCell)
|
||||||
for nrow in range(0, maxRow):
|
for nrow in range(0, maxRow):
|
||||||
q.setProgress(int(((nrow+1)/maxRow)*100))
|
q.setProgress(int(((nrow+1)/maxRow)*100))
|
||||||
|
@ -82,21 +81,28 @@ def _updateQuestion(q):
|
||||||
q.update()
|
q.update()
|
||||||
|
|
||||||
def GoogleQuiz():
|
def GoogleQuiz():
|
||||||
|
_load_module()
|
||||||
|
from gquiz import gquiz
|
||||||
q = gquiz()
|
q = gquiz()
|
||||||
|
q.setSavePath(curpath)
|
||||||
q.AttachProcessInfo(_statusBarInfoUpdate)
|
q.AttachProcessInfo(_statusBarInfoUpdate)
|
||||||
q.setProgress(0)
|
q.setProgress(0)
|
||||||
q.generateService()
|
q.generateService()
|
||||||
q.createForm("Demo Soal")
|
q.createForm("Demo Soal")
|
||||||
_updateQuestion(q)
|
_updateQuestion(q)
|
||||||
ui.SetStatusbar("creating google form quiz done!")
|
ui.SetStatusbar("creating google form quiz done!")
|
||||||
|
_statusBarInfoUpdate("Finish!!",100)
|
||||||
bas.InputBox("Open link to edit your form:","Your Google Form Quiz, done!", "{}".format(q.resultUri))
|
bas.InputBox("Open link to edit your form:","Your Google Form Quiz, done!", "{}".format(q.resultUri))
|
||||||
|
|
||||||
def MoodleQuiz():
|
def MoodleQuiz():
|
||||||
|
_load_module()
|
||||||
|
from moodleQuiz import moodleQuiz
|
||||||
q = moodleQuiz()
|
q = moodleQuiz()
|
||||||
|
q.setSavePath(curpath)
|
||||||
q.AttachProcessInfo(_statusBarInfoUpdate)
|
q.AttachProcessInfo(_statusBarInfoUpdate)
|
||||||
q.setProgress(0)
|
q.setProgress(0)
|
||||||
_updateQuestion(q)
|
_updateQuestion(q)
|
||||||
ui.SetStatusbar("Done!")
|
ui.SetStatusbar("Done!")
|
||||||
bas.MsgBox("Check *.xml file in curent folder!")
|
_statusBarInfoUpdate("Check *.xml file in curent folder!",100)
|
||||||
|
|
||||||
g_exportedScripts = (MakeTemplate, GoogleQuiz, MoodleQuiz)
|
g_exportedScripts = (MakeTemplate, GoogleQuiz, MoodleQuiz)
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import sys, requests
|
||||||
|
from unohelper import fileUrlToSystemPath
|
||||||
|
|
||||||
|
def gquiz_test():
|
||||||
|
if not 'gquiz' in sys.modules:
|
||||||
|
doc = XSCRIPTCONTEXT.getDocument()
|
||||||
|
url = fileUrlToSystemPath('{}/{}'.format(doc.URL,'Scripts/python/Library'))
|
||||||
|
sys.path.insert(0, url)
|
||||||
|
from gquiz import gquiz
|
||||||
|
|
||||||
|
q = gquiz()
|
||||||
|
|
||||||
|
q.generateService()
|
||||||
|
|
||||||
|
q.copyFile("16-rh3W-NwYzdKVBZJmi574sTWe_rMIdE-FQSw_33qXI", "Soal Masuk Penjara")
|
||||||
|
opt = [ q.createOption("A.","./asset/option1.png"),
|
||||||
|
q.createOption("B.","./asset/option2.png"),
|
||||||
|
q.createOption("C.","./asset/option3.png"),
|
||||||
|
q.createOption("D.","./asset/option4.png"),
|
||||||
|
q.createOption("E.","./asset/option5.png") ]
|
||||||
|
|
||||||
|
qq = q.createQuestion(title = "Soal No 1",\
|
||||||
|
description = "Dari gambar dibawah ini, ada bagian gambar yang hilang. Dari pilihan dibawah, manakah gambar yang benar?",\
|
||||||
|
indexAnswer = 4, options = opt, itemImage='./asset/test_image.png')
|
||||||
|
q.submitQuestion(0,qq)
|
||||||
|
q.update()
|
|
@ -1,33 +0,0 @@
|
||||||
# coding: utf-8
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import sys, requests, os
|
|
||||||
from unohelper import fileUrlToSystemPath
|
|
||||||
|
|
||||||
sys.path.insert(0, "{}/{}".format(os.getcwd(),"Library"))
|
|
||||||
from gquiz import gquiz
|
|
||||||
from moodleQuiz import moodleQuiz
|
|
||||||
|
|
||||||
def test(q):
|
|
||||||
opt = [ q.createOption("A.","./asset/option1.png"),
|
|
||||||
q.createOption("B.","./asset/option2.png"),
|
|
||||||
q.createOption("C.","./asset/option3.png"),
|
|
||||||
q.createOption("D.","./asset/option4.png"),
|
|
||||||
q.createOption("E.","./asset/option5.png") ]
|
|
||||||
qq = q.createQuestion(title = "Soal No 1",\
|
|
||||||
description = "Dari gambar dibawah ini, ada bagian gambar yang hilang. Dari pilihan dibawah, manakah gambar yang benar?",\
|
|
||||||
indexAnswer = 4, options = opt, itemImage='./asset/test_image.png')
|
|
||||||
q.submitQuestion(0,qq)
|
|
||||||
q.update()
|
|
||||||
|
|
||||||
os.system("mkdir asset && mkdir secret")
|
|
||||||
os.system("cp ../../asset/* ./asset")
|
|
||||||
os.system("cp ../../secret/client_secrets.json ./secret")
|
|
||||||
|
|
||||||
q = moodleQuiz()
|
|
||||||
test(q)
|
|
||||||
|
|
||||||
q = gquiz()
|
|
||||||
q.generateService()
|
|
||||||
q.createForm("test")
|
|
||||||
test(q)
|
|
|
@ -1 +1,12 @@
|
||||||
ok
|
Authorize credentials for a desktop application
|
||||||
|
To authenticate as an end user and access user data in your app, you need to create one or more OAuth 2.0 Client IDs. A client ID is used to identify a single app to Google's OAuth servers. If your app runs on multiple platforms, you must create a separate client ID for each platform.
|
||||||
|
|
||||||
|
In the Google Cloud console, go to Menu menu > APIs & Services > Credentials.
|
||||||
|
|
||||||
|
Go to Credentials
|
||||||
|
Click Create Credentials > OAuth client ID.
|
||||||
|
Click Application type > Desktop app.
|
||||||
|
In the Name field, type a name for the credential. This name is only shown in the Google Cloud console.
|
||||||
|
Click Create. The OAuth client created screen appears, showing your new Client ID and Client secret.
|
||||||
|
Click OK. The newly created credential appears under OAuth 2.0 Client IDs.
|
||||||
|
Save the downloaded JSON file as credentials.json, and move the file to your working directory.
|
||||||
|
|
Loading…
Reference in New Issue