its works
							parent
							
								
									8a1292ebde
								
							
						
					
					
						commit
						33431c275a
					
				| 
						 | 
				
			
			@ -1,3 +1,3 @@
 | 
			
		|||
client_secrets.json
 | 
			
		||||
client_secret.json
 | 
			
		||||
token.json
 | 
			
		||||
__pycache__/
 | 
			
		||||
__pycache__/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -86,41 +86,58 @@ class gdoc:
 | 
			
		|||
 | 
			
		||||
    def createOption(self, value, image=None):
 | 
			
		||||
        self.infoPrint("creating option",self.progress)
 | 
			
		||||
        opt = {
 | 
			
		||||
            'insertText' : {
 | 
			
		||||
                'location':{
 | 
			
		||||
                    'index': 1,
 | 
			
		||||
                },
 | 
			
		||||
                'text': "\t{}\r\n".format(value)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        opttxt = "\t{}\r\n".format(value)
 | 
			
		||||
        opt = [{'insertText' : {
 | 
			
		||||
                'location':{ 'index': 1, },
 | 
			
		||||
                'text': opttxt }}]
 | 
			
		||||
        if(image != None):
 | 
			
		||||
            self.infoPrint("uploading option image... ",self.progress)
 | 
			
		||||
            req = requests.post(self.image_temp_service_url,files={"file": open(image,'rb')})
 | 
			
		||||
            if(req.json()['status'] == 'error'):
 | 
			
		||||
                raise Exception("upload failed : {}".format(req.json()))
 | 
			
		||||
            time.sleep(3)
 | 
			
		||||
            self.infoPrint("uploading option image... ok",self.progress)
 | 
			
		||||
            u = urlparse(req.json()['data']['url'])
 | 
			
		||||
            opt.append( { 'insertInlineImage' : {
 | 
			
		||||
                    'uri' : u._replace(path="/dl"+u.path).geturl(),
 | 
			
		||||
	                'location' : { 'index' : len(opttxt)-1}}
 | 
			
		||||
            })
 | 
			
		||||
        return opt
 | 
			
		||||
 | 
			
		||||
    def createQuestion(self, title, description, options, indexAnswer, itemImage=None):
 | 
			
		||||
        self.infoPrint("create question...",self.progress)
 | 
			
		||||
        item = [{
 | 
			
		||||
            'insertText' : {
 | 
			
		||||
                'location':{
 | 
			
		||||
                    'index': 1,
 | 
			
		||||
                },
 | 
			
		||||
                'text': "{}\r\n".format(description)
 | 
			
		||||
            }
 | 
			
		||||
        }]
 | 
			
		||||
        itemtxt = "{}\r\n".format(description)
 | 
			
		||||
        item = [{'insertText' : {
 | 
			
		||||
                'text': itemtxt, 
 | 
			
		||||
                'location':{'index': 1,}}}]
 | 
			
		||||
        if (itemImage != None):
 | 
			
		||||
            self.infoPrint("uploading question image...",self.progress)
 | 
			
		||||
            req = requests.post(self.image_temp_service_url,files={"file": open(itemImage,'rb')})
 | 
			
		||||
            if(req.json()['status'] == 'error'):
 | 
			
		||||
                raise Exception("upload failed : {}".format(req.json()))
 | 
			
		||||
            time.sleep(3)
 | 
			
		||||
            self.infoPrint("uploading question image... ok",self.progress)
 | 
			
		||||
            u = urlparse(req.json()['data']['url'])
 | 
			
		||||
            item.append( { 'insertInlineImage' : {
 | 
			
		||||
                    'uri' : u._replace(path="/dl"+u.path).geturl(),
 | 
			
		||||
	                'location' : { 'index' : len(itemtxt)-1 }}
 | 
			
		||||
            })
 | 
			
		||||
        item = list(reversed(options)) + item
 | 
			
		||||
        self.questionKey.append(indexAnswer)
 | 
			
		||||
        return item
 | 
			
		||||
 | 
			
		||||
    def submitItem(self, index, item):
 | 
			
		||||
        self.infoPrint("submit question",self.progress)
 | 
			
		||||
        self.submition['requests'].append(item)
 | 
			
		||||
        question_setting = self.docs_service.documents().batchUpdate(documentId=self.main_docs["documentId"], body=self.submition).execute()
 | 
			
		||||
        print(self.submition)
 | 
			
		||||
        print(question_setting)
 | 
			
		||||
        for _item in item :
 | 
			
		||||
            submition = {}
 | 
			
		||||
            submition["requests"] = _item
 | 
			
		||||
            print(submition)
 | 
			
		||||
            r = self.docs_service.documents().batchUpdate(documentId=self.main_docs["documentId"], body=submition).execute()
 | 
			
		||||
            print(r)
 | 
			
		||||
 | 
			
		||||
    def update(self):
 | 
			
		||||
        self.infoPrint("Updating Docs...",self.progress)
 | 
			
		||||
        # Prints the result to show the question has been added
 | 
			
		||||
        get_result = self.docs_service.documents().get(documentId=self.main_docs["documentId"]).execute()
 | 
			
		||||
        # self.resultUri = get_result['responderUri']
 | 
			
		||||
        print(get_result)
 | 
			
		||||
        # get_result = self.docs_service.documents().get(documentId=self.main_docs["documentId"]).execute()
 | 
			
		||||
        self.resultUri = self.main_docs["documentId"]
 | 
			
		||||
        self.infoPrint("Updating Form... Done",self.progress)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,11 +46,12 @@ def MakeTemplate():
 | 
			
		|||
def _statusBarInfoUpdate(text : str, progress : int):
 | 
			
		||||
    ui.ShowProgressBar("loading...", "{}% {}".format(progress,text), progress)
 | 
			
		||||
 | 
			
		||||
def _updateQuestion(q):
 | 
			
		||||
def _updateQuestion(q, isReverse = False):
 | 
			
		||||
    selctedCell = doc.CurrentSelection      #
 | 
			
		||||
    cwd = curpath
 | 
			
		||||
    maxRow = doc.LastRow(selctedCell)+1-doc.FirstRow(selctedCell)
 | 
			
		||||
    for nrow in range(0, maxRow):
 | 
			
		||||
    rnge = reversed(range(0, maxRow)) if isReverse else range(0, maxRow)
 | 
			
		||||
    for nrow in rnge:
 | 
			
		||||
        q.setProgress(int(((nrow+1)/maxRow)*100))
 | 
			
		||||
        item = doc.getValue(doc.Offset(doc.FirstCell(selctedCell),nrow,0,1,17))
 | 
			
		||||
        # item[0]	<Text question>	
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +73,8 @@ def _updateQuestion(q):
 | 
			
		|||
        # item[16]	<Text Option5>
 | 
			
		||||
        opt, theAnswer, c = [], -1, 1
 | 
			
		||||
        for o in range(2, 17, 3): # mengambil kolim jawaban saja 
 | 
			
		||||
            theAnswer = c if (item[o] == 1) else -1 
 | 
			
		||||
            if (item[o] == 1)
 | 
			
		||||
                theAnswer = c
 | 
			
		||||
            opt.append(\
 | 
			
		||||
                q.createOption(\
 | 
			
		||||
                    "{}. {}".format(chr(64+c),item[o+2]),\
 | 
			
		||||
| 
						 | 
				
			
			@ -105,6 +107,20 @@ def GoogleQuiz():
 | 
			
		|||
    _statusBarInfoUpdate("Finish!!",100)
 | 
			
		||||
    bas.InputBox("Open link to edit your form:","Your Google Form Quiz, done!", "{}".format(q.resultUri))
 | 
			
		||||
 | 
			
		||||
def GoogleDocs():
 | 
			
		||||
    _load_module()
 | 
			
		||||
    from gdoc import gdoc 
 | 
			
		||||
    q = gdoc()
 | 
			
		||||
    q.setSavePath(curpath)
 | 
			
		||||
    q.AttachProcessInfo(_statusBarInfoUpdate)
 | 
			
		||||
    q.setProgress(0)
 | 
			
		||||
    q.generateService()
 | 
			
		||||
    q.createDocs("Demo Soal") #TODO : put this mundane inside generateService()
 | 
			
		||||
    _updateQuestion(q, True)
 | 
			
		||||
    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))
 | 
			
		||||
 | 
			
		||||
def MoodleQuiz():
 | 
			
		||||
    _load_module()
 | 
			
		||||
    from moodleQuiz import moodleQuiz
 | 
			
		||||
| 
						 | 
				
			
			@ -116,4 +132,4 @@ def MoodleQuiz():
 | 
			
		|||
    ui.SetStatusbar("Done!")
 | 
			
		||||
    _statusBarInfoUpdate("Check *.xml file in curent folder!",100)
 | 
			
		||||
 | 
			
		||||
g_exportedScripts = (MakeTemplate, GoogleQuiz, MoodleQuiz)
 | 
			
		||||
g_exportedScripts = (MakeTemplate, GoogleQuiz, GoogleDocs, MoodleQuiz)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,16 +53,15 @@ def gquiz_docs_test():
 | 
			
		|||
    q.setProgress(20)
 | 
			
		||||
    q.createDocs("test quiz")
 | 
			
		||||
    q.setProgress(50)
 | 
			
		||||
    opt = [	q.createOption("A. asokdjoqwe  akls d asj ooijk okiasj "),
 | 
			
		||||
           q.createOption("B. alskdjl ka aklsdoqwieo q we1i231 kjco23ij"),
 | 
			
		||||
           q.createOption("C. kasojd skadj0o1042k j 2k3lj2lk 1l2k4k4j"),
 | 
			
		||||
           q.createOption("D. askdjo2 3 12lk3j kjsdlakoi324o  12kj 4k"),
 | 
			
		||||
           q.createOption("E. aksdjl io123jo1 kjsdl k l kjlk12j3lkj ksj") ]
 | 
			
		||||
    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") ]
 | 
			
		||||
    q.setProgress(80)
 | 
			
		||||
    qq = q.createQuestion(\
 | 
			
		||||
            title = "Soal No 1",\
 | 
			
		||||
    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 )
 | 
			
		||||
            indexAnswer = 4, options = opt, itemImage='./asset/test_image.png')
 | 
			
		||||
    q.setProgress(85)
 | 
			
		||||
    q.submitItem(0,qq)
 | 
			
		||||
    q.setProgress(90)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue