Beispiel #1
0
def Send():

    global subject, Rsub5, Rsub1, Rsub3, Rsub2, Rsub4, other
    id = ""
    msg1 = QMessageBox()

    if "a" == "a":
        if Rsub6.isChecked():
            subject = "Other"
            # subject=str(subject)

            # if subject=="":
            #    subject=time.asctime( time.localtime(time.time()) )
            id = "0Bx8BFa4-Ejy_YWlxTWl1UlU5OEU"
            print subject
        elif Rsub5.isChecked():
            subject = sub5
            id = "0Bx8BFa4-Ejy_cHpwd3ZqY2toWlE"
        elif Rsub1.isChecked():
            subject = sub1
            id = "0Bx8BFa4-Ejy_b0haa3ZsTG5LSG8"
        elif Rsub3.isChecked():
            subject = sub3
            id = "0Bx8BFa4-Ejy_MGUydkJfano0dVk"
        elif Rsub2.isChecked():
            subject = sub2
            id = "0Bx8BFa4-Ejy_ektlT0gxclJ3R28"
        elif Rsub4.isChecked():
            subject = sub4
            id = "0Bx8BFa4-Ejy_TkZLSlYyaDhrSlk"

        # AUTHENTICATION WITH GOOGLE SERVER
        home = expanduser("~")
        path = home + "/PICT/" + subject + "/"
        if os.path.exists(path):
            shutil.copy(fname, path)
        else:
            os.makedirs(path)
            shutil.copyfile(fname, path + fname)

        auth = GoogleAuth()

        auth.LoadCredentialsFile("cred.txt")
        if auth.credentials is None:

            auth.LocalWebserverAuth()

        elif auth.access_token_expired:
            auth.Refresh()

        else:
            auth.Authorize()
        auth.SaveCredentialsFile("cred.txt")
        drive = GoogleDrive(auth)

        files = drive.CreateFile(
            {
                "title": "%s" % filename,
                "mimeType": "text/csv",
                "parents": [{"kind": "drive#TE3#%s" % subject, "id": "%s" % id}],
            }
        )
        files.SetContentFile("%s" % fname)
        files.Upload()

        #   file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
        #  for file1 in file_list:
        #     print 'title: %s, id: %s' % (file1['title'], file1['id'])

        msg1.setGeometry(500, 400, 60, 30)
        msg1.setText("Successfully Send")
        msg1.exec_()
        msg1.destroy()