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/24 13:39] – [6] fredphil91 | issue77:tutoriel_-_python_47 [2014/03/07 12:13] (Version actuelle) – [8] fredphil91 | ||
---|---|---|---|
Ligne 49: | Ligne 49: | ||
In the line above right, we call the GetSeasonEpisode routine to pull the series name, season number and episode number from the filename. If everything parses correctly, the variable isok is set to true, and the data we are looking for is placed into a list and then returned to us.** | In the line above right, we call the GetSeasonEpisode routine to pull the series name, season number and episode number from the filename. If everything parses correctly, the variable isok is set to true, and the data we are looking for is placed into a list and then returned to us.** | ||
- | Jetons un coup d' | + | Jetons un coup d’œil |
- | Les deux premières lignes ici initialisent les choses pour la routine ParcourirChemin, | + | Les deux premières lignes ici initialisent les choses pour la routine ParcourirChemin, |
Dans la ligne en haut à droite, nous appelons la routine RecupereSaisonEpisode pour récupérer le nom de la série et les numéros de la saison et de l' | Dans la ligne en haut à droite, nous appelons la routine RecupereSaisonEpisode pour récupérer le nom de la série et les numéros de la saison et de l' | ||
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' |
====== 5 ====== | ====== 5 ====== | ||
Ligne 75: | Ligne 75: | ||
Voici la logique du nouveau code, ligne par ligne : | Voici la logique du nouveau code, ligne par ligne : | ||
- | Tout d' | + | Tout d' |
====== 6 ====== | ====== 6 ====== | ||
Ligne 91: | Ligne 91: | ||
====== 7 ====== | ====== 7 ====== | ||
- | Again, it is a very simple set of code and we pretty much went over it last month, but we’ll walk through it just in case you missed it. | + | **Again, it is a very simple set of code and we pretty much went over it last month, but we’ll walk through it just in case you missed it. |
We define the function and set up four parameters. We will be passing the episode list (eplist), the number of episodes we should expect (shouldhave) which is the highest episode number in the episode list, the season number (season), and the show name (showname). | We define the function and set up four parameters. We will be passing the episode list (eplist), the number of episodes we should expect (shouldhave) which is the highest episode number in the episode list, the season number (season), and the show name (showname). | ||
- | Next, we create a set that contains a list of numbers using the range built-in function, starting with 1 and going to the value in shouldhave + 1. We then call the difference function – on this set and a converted set from the episode list (temp-set(eplist)) – and convert it back to a list. We then check to see if there is anything in the list – so we don’t print a line with an empty list, and if there’s anything there, we print it out. | + | Next, we create a set that contains a list of numbers using the range built-in function, starting with 1 and going to the value in shouldhave + 1. We then call the difference function – on this set and a converted set from the episode list (temp-set(eplist)) – and convert it back to a list. We then check to see if there is anything in the list – so we don’t print a line with an empty list, and if there’s anything there, we print it out.** |
+ | |||
+ | Encore une fois, c'est du code très simple et nous l' | ||
+ | |||
+ | Nous définissons la fonction et mettons en place quatre paramètres. Nous passerons la liste des épisodes (episode_liste), | ||
+ | |||
+ | Ensuite, nous créons un ensemble qui contient une liste de numéros en utilisant la fonction intégrée « range », en allant de 1 à la valeur nombre_therorique + 1. Nous appelons ensuite la fonction de différence - sur cet ensemble et un ensemble converti depuis la liste des épisodes (temp - set(episode_liste)) - et le reconvertissons en liste. Nous vérifions ensuite s'il y a quelque chose dans la liste - afin de ne pas afficher une ligne avec une liste vide, et s'il y a quelque chose, nous l' | ||
====== 8 ====== | ====== 8 ====== | ||
Ligne 103: | Ligne 109: | ||
Have a good month and we’ll see you soon.** | Have a good month and we’ll see you soon.** | ||
+ | |||
+ | 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:// | ||
+ | |||
+ | 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(' | ||
- | code en français : | ||
- | http:// |
issue77/tutoriel_-_python_47.1393245594.txt.gz · Dernière modification : 2014/02/24 13:39 de fredphil91