issue75:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue75:python [2013/08/13 16:03] – créée andre_domenech | issue75:python [2013/12/22 08:11] (Version actuelle) – fcm_-_ekel | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | This time, we are going to rework our database program from the previous few articles (parts 41, 42 and 43). Then, over the next few articles, we will use QT to create the user interface. | + | **This time, we are going to rework our database program from the previous few articles (parts 41, 42 and 43). Then, over the next few articles, we will use QT to create the user interface. |
First, let's look at how the existing application works. Here's a gross overview: | First, let's look at how the existing application works. Here's a gross overview: | ||
Ligne 10: | Ligne 10: | ||
• Check to see if the episode exists in the database. | • Check to see if the episode exists in the database. | ||
• If it is not there, add it to the database with a “-1” as the TvRage ID. | • If it is not there, add it to the database with a “-1” as the TvRage ID. | ||
- | • Then walk through the database getting show id and status if needed, and update database. | + | • Then walk through the database getting show id and status if needed, and update database.** |
- | We will redesign the database to include another table and modify the existing data table. First, we will create our new table called Series. It will hold all the information about the tv series we have on our system. The new table will include the following fields: | + | Cette fois-ci, nous allons retravailler notre programme de base de données à partir des quelques articles précédents (les parties 41, 42 et 43 dans les numéros 70, 71 et 72). Puis, au cours des prochains articles, nous allons utiliser QT pour créer l' |
+ | |||
+ | Tout d' | ||
+ | Voici un aperçu brut : | ||
+ | • Créer une connexion à la base de données, qui crée la base de données si nécessaire. | ||
+ | • Créer un pointeur sur la base de données. | ||
+ | • Créer la table si elle n' | ||
+ | • Attribuer le(s) dossier(s) vidéo à une variable. | ||
+ | • Rechercher les fichiers vidéo dans le(s) dossier(s) | ||
+ | • Obtenir le nom du fichier, le nom de la série, le numéro de la saison, le numéro de l' | ||
+ | • Vérifiez si l' | ||
+ | • S'il n'y est pas, l' | ||
+ | • Parcourir ensuite la base de données, obtenir l'id de la série et le statut, si nécessaire, | ||
+ | |||
+ | **We will redesign the database to include another table and modify the existing data table. First, we will create our new table called Series. It will hold all the information about the tv series we have on our system. The new table will include the following fields: | ||
• Pkid | • Pkid | ||
• Series Name | • Series Name | ||
Ligne 29: | Ligne 43: | ||
• Time of day it airs | • Time of day it airs | ||
• Path to the series | • Path to the series | ||
+ | ** | ||
- | We can use the existing MakeDataBase routine to create our new table. Before the existing code, add the code shown above right. | + | Nous allons repenser la base de données pour inclure une autre table et modifier la table de données existante. Tout d' |
+ | • PKID. | ||
+ | • Nom de la série. | ||
+ | • ID série TvRage. | ||
+ | • Nombre de saisons. | ||
+ | • Date de début. | ||
+ | • Drapeau de fin. | ||
+ | • Pays d' | ||
+ | • Statut de la série (terminé, courant, etc.). | ||
+ | • Classification (à partir d'un script, « réalité », etc.). | ||
+ | • Résumé de l' | ||
+ | • Genres. | ||
+ | • Durée en minutes. | ||
+ | • Chaîne de diffusion. | ||
+ | • Jour de diffusion dans la semaine. | ||
+ | • Horaire de diffusion. | ||
+ | • Chemin de la série. | ||
+ | |||
+ | |||
+ | **We can use the existing MakeDataBase routine to create our new table. Before the existing code, add the code shown above right. | ||
The SQL statement (“sql = …”) should be all on one line, but is broken out here for ease of your understanding. We’ll leave the modification of the existing table for later. | The SQL statement (“sql = …”) should be all on one line, but is broken out here for ease of your understanding. We’ll leave the modification of the existing table for later. | ||
Ligne 42: | Ligne 76: | ||
with | with | ||
- | sqlquery = ' | + | sqlquery = ' |
- | This (to refresh your memory) will check to see if we have already put the series into the table. Now find the two lines that say: | + | Nous pouvons utiliser la routine FabriquerBase existante pour créer notre nouvelle table. Avant le code existant, ajoutez le code ci-dessus à droite. |
+ | |||
+ | L' | ||
+ | |||
+ | Maintenant, nous devons modifier notre routine ParcourirChemin pour enregistrer le nom de la série et le chemin dans la table de Series. | ||
+ | |||
+ | Remplacez la ligne qui dit | ||
+ | |||
+ | sqlquery = ' | ||
+ | |||
+ | par | ||
+ | |||
+ | sqlquery = ' | ||
+ | |||
+ | **This (to refresh your memory) will check to see if we have already put the series into the table. Now find the two lines that say: | ||
sql = ' | sql = ' | ||
Ligne 52: | Ligne 100: | ||
sql = ' | sql = ' | ||
- | cursor.execute(sql, | + | cursor.execute(sql, |
- | This will insert the series name (showname), path to the series, and a “-1” as the TvRage id. We use the “-1” as a flag to know that we need the series information from TvRage. | + | Cela (pour vous rafraîchir la mémoire) va vérifier si nous avons déjà mis les séries dans la table. |
+ | |||
+ | Maintenant, trouver les deux lignes qui disent : | ||
+ | |||
+ | sql = ' | ||
+ | cursor.execute(sql, | ||
+ | |||
+ | et les remplacer par | ||
+ | |||
+ | sql = ' | ||
+ | cursor.execute(sql, | ||
+ | |||
+ | **This will insert the series name (showname), path to the series, and a “-1” as the TvRage id. We use the “-1” | ||
+ | as a flag to know that we need the series information from TvRage. | ||
Next we will rework the WalkTheDatabase routine to pull those series that we don’t have any information for (SeriesID = -1) and update that record. | Next we will rework the WalkTheDatabase routine to pull those series that we don’t have any information for (SeriesID = -1) and update that record. | ||
Ligne 64: | Ligne 125: | ||
to | to | ||
- | sqlstring = " | + | sqlstring = " |
+ | |||
+ | Ceci va insérer le nom de la série (showname), le chemin de la série, et un « -1 » comme identifiant de TvRage. Nous utilisons le « -1 » comme un drapeau pour savoir que nous avons besoin d' | ||
+ | |||
+ | Ensuite, nous allons retravailler la routine ParcourirBase pour alimenter ces séries pour lesquelles nous n' | ||
+ | |||
+ | Modifiez la chaîne de requête de : | ||
+ | |||
+ | sqlstring = " | ||
+ | |||
+ | en : | ||
+ | |||
+ | sqlstring = " | ||
- | This will create a result-set that we can then use to query TvRage for each series. Now find/ | + | **This will create a result-set that we can then use to query TvRage for each series. Now find/ |
seriesname = x[0] | seriesname = x[0] | ||
Ligne 77: | Ligne 150: | ||
seriesname = x[1] | seriesname = x[1] | ||
+ | |||
+ | searchname = string.capwords(x[1]," | ||
+ | |||
+ | Cela va créer un ensemble de résultats que nous pourrons ensuite utiliser pour interroger TvRage pour chaque série. Maintenant, trouver/ | ||
+ | |||
+ | NomSerie = x[0] | ||
+ | |||
+ | searchname = string.capwords(x[0]," | ||
+ | |||
+ | par : | ||
+ | |||
+ | pkid = x[0] | ||
+ | |||
+ | NomSerie = x[1] | ||
searchname = string.capwords(x[1]," | searchname = string.capwords(x[1]," | ||
- | We will use the pkID for the update statement. Next we have to modify the call to the UpdateDatabase routine to include the pkid. Change the line | + | **We will use the pkID for the update statement. Next we have to modify the call to the UpdateDatabase routine to include the pkid. Change the line |
UpdateDatabase(seriesname, | UpdateDatabase(seriesname, | ||
Ligne 87: | Ligne 174: | ||
and change the line | and change the line | ||
+ | |||
GetShowStatus(seriesname, | GetShowStatus(seriesname, | ||
Ligne 92: | Ligne 180: | ||
GetShowData(seriesname, | GetShowData(seriesname, | ||
- | Which will be a new routine we will create in a moment. | + | Which will be a new routine we will create in a moment.** |
+ | |||
+ | Nous allons utiliser le PKID pour la déclaration de mise à jour. Ensuite, nous devrons modifier l' | ||
+ | |||
+ | Modifiez la ligne : | ||
+ | |||
+ | MettreAJourBase(NomSerie, | ||
+ | |||
+ | en : | ||
+ | MettreAJourBase(NomSerie, | ||
+ | |||
+ | et changez la ligne : | ||
+ | |||
+ | RecupereEtatEmission(NomSerie, | ||
+ | |||
+ | en : | ||
+ | |||
+ | RecupererDonneesEmission(NomSerie, | ||
+ | |||
+ | qui sera une nouvelle routine ; nous allons la créer dans un instant. | ||
+ | | ||
- | Next, change the definition of the UpdateDatabase routine from | + | **Next, change the definition of the UpdateDatabase routine from |
def UpdateDatabase(seriesname, | def UpdateDatabase(seriesname, | ||
Ligne 100: | Ligne 208: | ||
to | to | ||
- | def UpdateDatabase(seriesname, | + | def UpdateDatabase(seriesname, |
- | Next, we need to change the query string from | + | Ensuite, modifiez la définition de la routine de MettreAJourBase de : |
+ | |||
+ | def MettreAJourBase(NomSerie, | ||
+ | |||
+ | à : | ||
+ | |||
+ | def MettreAJourBase(NomSerie, | ||
+ | |||
+ | **Next, we need to change the query string from | ||
sqlstring = ' | sqlstring = ' | ||
Ligne 108: | Ligne 224: | ||
to | to | ||
- | sqlstring = ' | + | sqlstring = ' |
- | Now we need to create the GetShowData routine (top). We’ll grab the information from TvRage and insert it into the Series table. | + | Ensuite, nous devons changer la chaîne de requête de : |
- | Just as a memory refresher, we are creating an instance of the TvRage routines and creating a dictionary that holds the information on our series. We will then create variables to hold the data for updating the table (above). | + | sqlstring = ' |
- | Remember that Genres come in as subelements and contain one or many genre listings. Luckily when we coded the TvRage routines, we created a string that holds all the genres, no matter how many are returned, so we can just use the genre string: | + | en : |
+ | |||
+ | sqlstring = ' | ||
+ | |||
+ | **Now we need to create the GetShowData routine (top). We’ll grab the information from TvRage and insert it into the Series table. | ||
+ | |||
+ | Just as a memory refresher, we are creating an instance of the TvRage routines and creating a dictionary that holds the information on our series. We will then create variables to hold the data for updating the table (above).** | ||
+ | |||
+ | Maintenant, nous devons créer la routine RecupererDonneesEmission (ci-dessus). Nous allons obtenir les informations de TvRage et les insérer dans la table Series. | ||
+ | |||
+ | En guise d' | ||
+ | |||
+ | **Remember that Genres come in as subelements and contain one or many genre listings. Luckily when we coded the TvRage routines, we created a string that holds all the genres, no matter how many are returned, so we can just use the genre string: | ||
genres = dict[' | genres = dict[' | ||
runtime = dict[' | runtime = dict[' | ||
Ligne 122: | Ligne 250: | ||
airday = dict[' | airday = dict[' | ||
- | airtime = dict[' | + | airtime = dict[' |
- | Finally, we create the query string to do the update (bottom). Again, this should all be on one line, but I’ve broken it up here to make it easy to understand. | + | Rappelez-vous que Genres vient en tant que sous-élément et contient une ou plusieurs listes de genres. Heureusement, |
+ | |||
+ | genres = dict[' | ||
+ | runtime = dict[' | ||
+ | network = dict[' | ||
+ | airday = dict[' | ||
+ | airtime = dict[' | ||
+ | |||
+ | **Finally, we create the query string to do the update (bottom). Again, this should all be on one line, but I’ve broken it up here to make it easy to understand. | ||
The {number} portion (just to remind you) is similar to the “%s” formatting option. This creates our query string replacing the {number} with the actual data we want. Since we’ve already defined all of these fields as text, we want to use the double quotes to enclose the data being added. | The {number} portion (just to remind you) is similar to the “%s” formatting option. This creates our query string replacing the {number} with the actual data we want. Since we’ve already defined all of these fields as text, we want to use the double quotes to enclose the data being added. | ||
Ligne 130: | Ligne 266: | ||
And lastly, we write to the database (below). | And lastly, we write to the database (below). | ||
- | That is all for this time. Next time, we’ll continue as I laid out at the beginning of the article. Until next time, Enjoy. | + | That is all for this time. Next time, we’ll continue as I laid out at the beginning of the article. Until next time, Enjoy.** |
+ | |||
+ | Enfin, nous créons la chaîne de requête pour réaliser la mise à jour (en bas). Encore une fois, tout cela doit être sur une seule ligne, mais je l'ai cassée ici pour la rendre facile à comprendre. | ||
+ | |||
+ | La partie {number} (à titre d' | ||
+ | |||
+ | Et enfin, nous écrivons à la base de données (ci-dessous). | ||
+ | |||
+ | C'est tout pour cette fois-ci. La prochaine fois, nous allons continuer comme j'ai expliqué au début de l' |
issue75/python.1376402619.txt.gz · Dernière modification : 2013/08/13 16:03 de andre_domenech