issue70:programmer_en_python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue70:programmer_en_python [2013/03/15 16:47] – créée andre_domenech | issue70:programmer_en_python [2013/06/18 20:50] (Version actuelle) – [8] fredphil91 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Last month, we started our command line version of a library to talk to the TVRAGE web API. This month we will continue adding to that library. If you don’t have the code from last month, please get it now from pastebin (http:// | + | ====== 1 ====== |
- | The way we left the code, you would run the program and enter in the terminal window the name of a TV show you want information on. Remember, | + | **Last month, |
- | The last routine we created in the class was “DisplayShowResult”. Right after that, and before the routine “main,” is where we will put our next routine. The information that will be returned (there is other information, | + | The way we left the code, you would run the program and enter in the terminal window the name of a TV show you want information on. Remember, we used the show Continuum. Once you pressed < |
+ | |||
+ | Le mois dernier, nous avons commencé notre version en ligne de commande d'une bibliothèque pour discuter avec l'API Web TVRage. Ce mois-ci, nous allons continuer à ajouter du code à cette bibliothèque. Si vous n'avez pas le code du mois dernier, veuillez le récupérer sur pastebin (http:// | ||
+ | |||
+ | Dans l' | ||
+ | ====== 2 ====== | ||
+ | |||
+ | **The last routine we created in the class was “DisplayShowResult”. Right after that, and before the routine “main,” is where we will put our next routine. The information that will be returned (there is other information, | ||
• Show ID | • Show ID | ||
• Show Name | • Show Name | ||
Ligne 25: | Ligne 32: | ||
• Air time | • Air time | ||
• Air Day (of week) | • Air Day (of week) | ||
- | • TimeZone | + | • TimeZone** |
- | Shown above is the beginning of the code. | + | La dernière routine que nous avons créée dans la classe était « AfficheResultatsEmission ». Nous allons placer notre prochaine routine juste après, et avant la routine « main ». L' |
+ | • identifiant de l' | ||
+ | • nom de l' | ||
+ | • lien de l' | ||
+ | • pays d' | ||
+ | • nombre de saisons ; | ||
+ | • image de la série ; | ||
+ | • année de démarrage ; | ||
+ | • date de démarrage ; | ||
+ | • date de fin ; | ||
+ | • état (annulé, rediffusion, | ||
+ | • classification (fiction, réalité, etc.) ; | ||
+ | • résumé de la série ; | ||
+ | • genre(s) ; | ||
+ | • durée en minutes ; | ||
+ | • nom de la chaîne qui a diffusé l' | ||
+ | • pays de la chaîne (c'est à peu près la même chose que pays d' | ||
+ | • heure de diffusion ; | ||
+ | • jour de diffusion (dans la semaine) ; | ||
+ | • fuseau horaire. | ||
+ | |||
+ | ====== 3 ====== | ||
+ | |||
+ | **Shown above is the beginning of the code. | ||
You should recognize most of the code from last time. There’s really not much changed. Here’s more code (shown below). | You should recognize most of the code from last time. There’s really not much changed. Here’s more code (shown below). | ||
Ligne 33: | Ligne 63: | ||
As you can see (above), there’s nothing really new in this bit of code either, if you’ve been keeping up with the series. We are using a for loop, checking each tag in the XML file for a specific value. If we find it, we assign it to a dictionary item. | As you can see (above), there’s nothing really new in this bit of code either, if you’ve been keeping up with the series. We are using a for loop, checking each tag in the XML file for a specific value. If we find it, we assign it to a dictionary item. | ||
- | Now things get a bit more complicated. We are going to check for the tag “genres”. This has child tags underneath it with the name of “genre”. For any given show, there can be multiple genres. We’ll have to append the genres to a string as they come up and separate them with a vertical bar and two spaces like this “ | “ (shown top right). | + | Now things get a bit more complicated. We are going to check for the tag “genres”. This has child tags underneath it with the name of “genre”. For any given show, there can be multiple genres. We’ll have to append the genres to a string as they come up and separate them with a vertical bar and two spaces like this “ | “ (shown top right).** |
+ | |||
+ | Ci-dessus, le début du code. | ||
+ | |||
+ | Vous devez reconnaître la plupart du code de la dernière fois. Il n'a vraiment pas beaucoup changé. Voici plus de code (voir ci-dessous). | ||
+ | |||
+ | Comme vous pouvez le voir (ci-dessus), | ||
+ | |||
+ | Maintenant les choses se compliquent un peu. Nous allons chercher la balise « genres ». Elle a des balises enfants en dessous d'elle avec le nom de « genre ». Pour un spectacle donné, il peut y avoir plusieurs genres. Nous devrons ajouter les genres à une chaîne au fur et à mesure qu'ils arrivent et les séparer par une barre verticale et deux espaces comme ceci « | » (voir en haut à droite). | ||
+ | |||
+ | ====== 4 ====== | ||
- | Now we are pretty much back to “normal” code (shown middle right) that you’ve already seen. The only thing that’s a bit different is the tag “network” which has an attribute “country”. We grab the attribute data by looking for “child.attrib[‘attributetag’]” instead of “child.text”. | + | **Now we are pretty much back to “normal” code (shown middle right) that you’ve already seen. The only thing that’s a bit different is the tag “network” which has an attribute “country”. We grab the attribute data by looking for “child.attrib[‘attributetag’]” instead of “child.text”. |
That’s the end of this routine. Now (below) we’ll need some way to display the information we worked so hard to get. We’ll create a routine called “DisplayShowInfo”. | That’s the end of this routine. Now (below) we’ll need some way to display the information we worked so hard to get. We’ll create a routine called “DisplayShowInfo”. | ||
Ligne 41: | Ligne 81: | ||
Now, we must update the “main” routine (next page, shown top right) to support our two new routines. I’m giving the entire routine below, but the new code is shown in black. | Now, we must update the “main” routine (next page, shown top right) to support our two new routines. I’m giving the entire routine below, but the new code is shown in black. | ||
- | Next page, bottom left, is what the output of “DisplayShowInfo” should look like, assuming you chose “Continuum” as the show. | + | Next page, bottom left, is what the output of “DisplayShowInfo” should look like, assuming you chose “Continuum” as the show.** |
- | Please notice that I’m not displaying the time zone information here, but feel free to add it if you wish. | + | Maintenant, nous sommes à peu près revenus au code « normal » (affiché au milieu à droite) que vous avez déjà vu. La seule chose un peu différente, |
+ | |||
+ | C'est la fin de cette routine. Maintenant (ci-dessous), | ||
+ | |||
+ | Maintenant, nous devons mettre à jour la routine « main » (page suivante, en haut à droite) pour prendre en compte nos deux nouvelles routines. Je donne la routine entière ci-dessous, mais le nouveau code est affiché en noir. | ||
+ | |||
+ | En bas à gauche de la page suivante, on voit à quoi devrait ressembler la sortie de « AfficheInfoEmission », en supposant que vous avez choisi « Continuum » comme émission. | ||
+ | |||
+ | ====== 5 ====== | ||
+ | |||
+ | **Please notice that I’m not displaying the time zone information here, but feel free to add it if you wish. | ||
Next, we need to work on the episode list routines for the series. The “worker” routine will be called “GetEpisodeList” and will provide the following information... | Next, we need to work on the episode list routines for the series. The “worker” routine will be called “GetEpisodeList” and will provide the following information... | ||
Ligne 56: | Ligne 106: | ||
• Summary | • Summary | ||
• Rating | • Rating | ||
- | • Screen Capture Image of Episode (if available) | + | • Screen Capture Image of Episode (if available)** |
- | Before we start with the code, it would be helpful to revisit what the episode list request to the API returns. It looks something like that shown on the next page, top right. | + | Veuillez noter que je n' |
+ | |||
+ | Ensuite, nous devons travailler sur la routine qui liste les épisodes pour la série. La routine « qui travaille » sera appelée « TrouveListeEpisodes » et fournira les informations suivantes : | ||
+ | • Saison ; | ||
+ | • numéro de l' | ||
+ | • numéro de l' | ||
+ | • numéro de production ; | ||
+ | • date de diffusion ; | ||
+ | • lien ; | ||
+ | • titre ; | ||
+ | • résumé ; | ||
+ | • évaluation ; | ||
+ | • capture d' | ||
+ | |||
+ | ====== 6 ====== | ||
+ | |||
+ | **Before we start with the code, it would be helpful to revisit what the episode list request to the API returns. It looks something like that shown on the next page, top right. | ||
The information for each episode is in the “episode” tag – which is a child of “Season” – which is a child of “Episodelist” – which is a child of “Show”. We have to be careful how we parse this. As with most of our “worker” routines this time, the first few lines (below) are fairly easy to understand by now. | The information for each episode is in the “episode” tag – which is a child of “Season” – which is a child of “Episodelist” – which is a child of “Show”. We have to be careful how we parse this. As with most of our “worker” routines this time, the first few lines (below) are fairly easy to understand by now. | ||
Ligne 64: | Ligne 130: | ||
Now we need to look for the “name” and “totalseasons” tags below the “root” tag “Show”. Once we’ve dealt with them, we look for the “Episodelist”, | Now we need to look for the “name” and “totalseasons” tags below the “root” tag “Show”. Once we’ve dealt with them, we look for the “Episodelist”, | ||
- | Now that we have that portion of the data, we deal with the episode specific information (shown below). | + | Now that we have that portion of the data, we deal with the episode specific information (shown below).** |
- | All that’s left now (bottom right) is to append the episode specific information (that we’ve put into the dictionary) to our list, and keep going. Once we are done with all the episodes, we return to the calling routine and, as I stated earlier, return three items of data, “ShowName”, | + | Avant que nous commencions avec le code, il serait utile de revenir sur ce que l'API retourne lors de la demande de la liste des épisodes. Cela ressemble à ce qui est en haut à droite de la page suivante. |
- | Next, we need to create our display routine. Again, it’s fairly straightforward. The only thing that you might not recognize is the “if e.has_key(‘keynamehere’)“ lines. This is a check to make sure that there is actually data in the “Rating” and “Summary” variables. Some shows don’t have this information, | + | Les informations pour chaque épisode sont dans la balise « épisode » - qui est un enfant de « saison » - qui est un enfant de « ListeEpisodes » - qui est un enfant de « Emission ». Nous devons faire attention à la façon dont nous analysons ceci. Comme avec la plupart de nos routines « utilitaires » de cette fois-ci, les quelques premières lignes |
- | All that’s left is to update our “main” routine (next page, shown top right). Once again, I’m going to provide the full “main” routine with the newest code in black bold. | + | Maintenant, nous devons chercher les balises « Nom » et « SaisonsTotal » en dessous de la balise racine « Emission ». Une fois que nous les avons traitées, nous cherchrons les balises « ListeEpisodes » et « Saison ». Remarquez ci-dessus que la balise « Saison » a un attribut. Vous remarquerez peut-être (dans le code ci-dessus) que nous n' |
+ | |||
+ | Maintenant que nous avons cette partie des données, nous traitons les informations spécifiques à l' | ||
+ | |||
+ | ====== 7 ====== | ||
+ | |||
+ | **All that’s left now (bottom right) is to append the episode specific information (that we’ve put into the dictionary) to our list, and keep going. Once we are done with all the episodes, we return to the calling routine and, as I stated earlier, return three items of data, “ShowName”, | ||
+ | |||
+ | Next, we need to create our display routine. Again, it’s fairly straightforward. The only thing that you might not recognize is the “if e.has_key(‘keynamehere’)“ lines. This is a check to make sure that there is actually data in the “Rating” and “Summary” variables. Some shows don’t have this information, | ||
+ | |||
+ | Tout ce qui reste à faire (en bas à droite) est d' | ||
+ | |||
+ | Ensuite, nous devons créer notre routine d' | ||
+ | |||
+ | ====== 8 ====== | ||
+ | |||
+ | **All that’s left is to update our “main” routine (next page, shown top right). Once again, I’m going to provide the full “main” routine with the newest code in black bold. | ||
Now, if you save and run the program, the output of the “GetEpisodeList” and “DisplayEpisodeList” will work. Shown bottom right is a snippet of the Episode information. | Now, if you save and run the program, the output of the “GetEpisodeList” and “DisplayEpisodeList” will work. Shown bottom right is a snippet of the Episode information. | ||
Ligne 76: | Ligne 158: | ||
That’s it for this month. As always, you can find the full source code on pastebin at http:// | That’s it for this month. As always, you can find the full source code on pastebin at http:// | ||
- | I’ll see you next time. Enjoy. | + | I’ll see you next time. Enjoy.** |
+ | |||
+ | Tout ce qui reste à faire est de mettre à jour notre routine « main » (en haut à droite de la page suivante). Encore une fois, je vais donner la routine « main » complète avec le nouveau code en caractères gras. | ||
+ | |||
+ | Maintenant, si vous enregistrez et exécutez le programme, la sortie de « TrouveListeEpisodes » et « AfficheListeEpisodes » va fonctionner. En bas à droite se trouve un extrait de l' | ||
+ | |||
+ | C'est tout pour ce mois-ci. Comme toujours, vous pouvez trouver le code source complet sur pastebin : http:// | ||
+ | |||
+ | Je vous verrai la prochaine fois. Amusez-vous bien. |
issue70/programmer_en_python.1363362471.txt.gz · Dernière modification : 2013/03/15 16:47 de andre_domenech