issue77:tutoriel_-_python_47
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue77:tutoriel_-_python_47 [2014/02/25 17:53] – [8] auntiee | issue77:tutoriel_-_python_47 [2014/03/07 12:13] (Version actuelle) – [8] fredphil91 | ||
---|---|---|---|
Ligne 60: | Ligne 60: | ||
We want to get the episode number of each file and put it into the elist list. Once we are done with all the files within the folder we are currently in, we can then make the assumption that we have been pretty much keeping up with the files and the highest numbered episode is the latest one available. As we discussed last month, we can then create a set that is numbered from 1 to the last episode, and convert the list to a set and pull a difference. While that is great in theory, there is a bit of a “hitch in our git-a-long” when it comes down to actual practice. We don’t actually get a nice and neat indication as to when we are done with any particular folder. What we do have though, is the knowledge that when we get done with each file, the code right after the “for file in [...” gets run. If we know the name of the last folder visited, and the current folder name, we can compare the two and, if they are different, we have finished a folder and our episode list should be complete. That’s what the ‘lastroot’ variable is for.** | We want to get the episode number of each file and put it into the elist list. Once we are done with all the files within the folder we are currently in, we can then make the assumption that we have been pretty much keeping up with the files and the highest numbered episode is the latest one available. As we discussed last month, we can then create a set that is numbered from 1 to the last episode, and convert the list to a set and pull a difference. While that is great in theory, there is a bit of a “hitch in our git-a-long” when it comes down to actual practice. We don’t actually get a nice and neat indication as to when we are done with any particular folder. What we do have though, is the knowledge that when we get done with each file, the code right after the “for file in [...” gets run. If we know the name of the last folder visited, and the current folder name, we can compare the two and, if they are different, we have finished a folder and our episode list should be complete. That’s what the ‘lastroot’ variable is for.** | ||
- | Ensuite (ci-dessous), | + | Ensuite (ci-dessous), |
Nous voulons obtenir le numéro d' | Nous voulons obtenir le numéro d' | ||
Ligne 86: | Ligne 86: | ||
Ensuite, nous devons changer deux lignes et ajouter une ligne de code dans le morceau de code « if estok » quelques lignes plus bas. Encore une fois, les lignes noires sont le code existant : | Ensuite, nous devons changer deux lignes et ajouter une ligne de code dans le morceau de code « if estok » quelques lignes plus bas. Encore une fois, les lignes noires sont le code existant : | ||
- | Ici, nous venons de revenir de la routine RecupereSaisonEpisode | + | Ici, nous venons de revenir de la routine RecupereSaisonEpisode. Si nous avions un nom de fichier analysable, nous voulons obtenir le nom de l' |
Nous en avons fini avec cette partie du code. Maintenant, tout ce qui nous reste à faire est d' | Nous en avons fini avec cette partie du code. Maintenant, tout ce qui nous reste à faire est d' | ||
Ligne 112: | Ligne 112: | ||
C'est tout. La seule faille dans cette logique est qu' | C'est tout. La seule faille dans cette logique est qu' | ||
- | J'ai mis les deux routines sur pastebin au cas où vous voudriez juste faire un remplacement rapide dans votre code. Vous pouvez les consulter ici : http:// | + | J'ai mis les deux routines sur pastebin au cas où vous voudriez juste faire un remplacement rapide dans votre code. Vous pouvez les consulter ici : http:// |
Passez un bon mois et nous vous reverrons bientôt. | Passez un bon mois et nous vous reverrons bientôt. | ||
+ | |||
+ | ====== Morceaux de code dans les encadrés ====== | ||
+ | |||
+ | ==== page 7 en haut ==== | ||
+ | |||
+ | for racine, reps, fichiers in os.walk(chemin, | ||
+ | for fic in [f for f in fichiers if f.endswith ((' | ||
+ | |||
+ | ==== page 7 juste en dessous ==== | ||
+ | |||
+ | # Combine chemin et nom de fichier pour creer une seule variable | ||
+ | fn = join(racine, | ||
+ | NomFicOriginal, | ||
+ | fl = fic | ||
+ | estok, | ||
+ | |||
+ | ==== page 7 en bas ==== | ||
+ | |||
+ | if estok: | ||
+ | nomEmission = data[0] | ||
+ | saison = data[1] | ||
+ | episode = data[2] | ||
+ | print(" | ||
+ | |||
+ | ==== page 8 en haut ==== | ||
+ | |||
+ | for fic in [f for f in fichiers if f.endswith ((' | ||
+ | # Combine chemin et nom de fichier pour creer une seule variable | ||
+ | if derniere_racine != racine: | ||
+ | derniere_racine = racine | ||
+ | if len(ep_liste) > 0: | ||
+ | Manquants(ep_liste, | ||
+ | ep_liste = [] | ||
+ | emission_courante = '' | ||
+ | saison_courante = '' | ||
+ | fn = join(racine, | ||
+ | |||
+ | ==== page 8 juste en dessous ==== | ||
+ | |||
+ | estok, | ||
+ | if estok: | ||
+ | emission_courante = nomEmission = data[0] | ||
+ | saison_courante = saison = data[1] | ||
+ | episode = data[2] | ||
+ | ep_liste.append(int(episode)) | ||
+ | else: | ||
+ | |||
+ | ==== page 8 en bas ==== | ||
+ | |||
+ | # | ||
+ | def Manquants(episode_liste, | ||
+ | temp = set(range(1, | ||
+ | ret = list(temp-set(episode_liste)) | ||
+ | if len(ret) > 0: | ||
+ | print(' | ||
+ | |||
issue77/tutoriel_-_python_47.1393347233.txt.gz · Dernière modification : 2014/02/25 17:53 de auntiee