Bonjour,


J'ai commencé récemment à apprendre la programmation sur python dans le cadre de l'automatisation des tâches liées à mon boulot.
Aujourd'hui mon script est la suite de 3 petits scrypts que j'ai écris, qui me permettent d'effacer un dossier, d'aller sur internet et télécharger des fichiers puis de les copier coller dans un autre fichier. Pour rentre l'application utilisable pour mes collègue j'ai pensé utiliser tkinter pour récupérer une entry qui va me permettre de rendre le programme fonctionnel sur n'importe quel pc.
Mes 3 fonctions marchent parfaitement ensemble, le problème vient de tkinter je pense.
Je pense que mon script est très brouillon et mal organisé. Mais surtout je n'arrive pas à récupérer la variable de l'entry. Je suis sous Python 2.7 et je tourne un peu en rond.
Je fais donc appel à vous pour me guider vers une façon plus propre de coder et surtout pour résoudre mon problème de global name 'mavariable' is not defined.

Merci d'avance,

Kair0

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
from Tkinter import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re, os, shutil
 
 
 
master = Tk()
 
Label(master, text="UID: ").grid(row=0, sticky=W)
 
entry = Entry(master)
entry.grid(row=0, column=1)
 
 
b1 = Button(master, text="RUN", command=maestro)
b1.grid(row=2, column=1)
 
mainloop()
 
 
 
 
 
def partie1():
    folder = "C:\Users\\" + UID + '\Downloads'
        for the_file in os.listdir(folder):
            file_path = os.path.join(folder, the_file)
            try:
                if os.path.isfile(file_path):
                    os.unlink(file_path)
            except Exception as e:
                print(e)
 
 
 
def setUp():
        driver = webdriver.Chrome(executable_path=r'\\PARDMP14SH\FCPTA2\80-72_MO_OUTCTR\OUTILS DE CONTROLE NEW\EXTRA\2 - Projets\COBALT\COBALT_EXCEL\chromedriver')
        driver.implicitly_wait(30)
        base_url = "https://google.com/"
        driver.get("https://dmt.finance.*****/*****/dg/index.jsp")
        driver.find_element_by_id("ab-login-dialog-username").click()
        driver.find_element_by_id("ab-login-dialog-username").clear()
        driver.find_element_by_id("ab-login-dialog-username").send_keys("******")
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Password:'])[1]/following::input[1]").click()
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Password:'])[1]/following::input[1]").clear()
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Password:'])[1]/following::input[1]").send_keys("****")
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Password:'])[1]/following::span[1]").click()
        time.sleep(5)
        driver.find_element_by_id("documentLibrary").click()
        time.sleep(5)
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='... more'])[1]/following::i[1]").click()
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='... more'])[17]/following::i[1]").click()
        driver.find_element_by_xpath("//a[starts-with(normalize-space(text()),'Excel_Data_Controls.')]").click()
        driver.find_element_by_xpath("//a[starts-with(normalize-space(text()),'Excel_Group_Data_Dictionary.')]").click()
        driver.find_element_by_id("abLogoutLink").click()
        driver.quit()
 
 
def partie3():
        path = "C:\Users\\" + UID + '\Downloads'
 
        files = os.listdir(path)
        doclist=[]
        for name in files:
            if name !='desktop.ini':
                doclist.append(name)
        docex1 = doclist[0] 
        docex2 = doclist[1]
 
        path2 = r'\\PARDMP14SH\FCPTA2\80-72_MO_OUTCTR\OUTILS DE CONTROLE NEW\EXTRA\3 - Documentation\3.6 Dictionnaire\RADAR\Sourcing DICOGLOB' 
        files = os.listdir(path2)
        doclist2=[]
        for name in files:
            doclist2.append(name)
        docex3 = doclist2[1] 
        docex4 = doclist2[0]
 
        if docex1 == docex4:
           print('true')
        else:
            shutil.copy('C:\Users\c92434\Downloads'+'/'+docex1,r'\\PARDMP14SH\FCPTA2\80-72_MO_OUTCTR\OUTILS DE CONTROLE NEW\EXTRA\3 - Documentation\3.6 Dictionnaire\RADAR\Sourcing DICOGLOB')   
            os.unlink(os.path.join(r'\\PARDMP14SH\FCPTA2\80-72_MO_OUTCTR\OUTILS DE CONTROLE NEW\EXTRA\3 - Documentation\3.6 Dictionnaire\RADAR\Sourcing DICOGLOB',docex4))
 
        if docex2 == docex3:
            print('true')
        else:    
            shutil.copy('C:\Users\c92434\Downloads'+'/'+docex2,r'\\PARDMP14SH\FCPTA2\80-72_MO_OUTCTR\OUTILS DE CONTROLE NEW\EXTRA\3 - Documentation\3.6 Dictionnaire\RADAR\Sourcing DICOGLOB')   
            os.unlink(os.path.join(r'\\PARDMP14SH\FCPTA2\80-72_MO_OUTCTR\OUTILS DE CONTROLE NEW\EXTRA\3 - Documentation\3.6 Dictionnaire\RADAR\Sourcing DICOGLOB',docex3))
 
def maestro():
 
 
    UID = entry.get()
    partie1()
    setUp()
    partie3()  
    rquit()
 
 
def rquit():
    root.destroy()