2016-07-05 13 views
-2

実行すると何も起こることはありませんが、エラーは発生しません。何をすればいいのでしょうか?ミラノの番号をデータベースから取得し、 dbをポータブルデバイスに転送します。なぜそれが実行されていない任意のアイデア???Pythonプログラムが期待どおり実行されていない

#!/usr/bin/python 
import sqlite3 
import os 
import shutil 

get_albums = [] 

def makedatabase(dbname): 
    #dbname = 'mp3_database.db' 

    if not os.path.exists(dbname): 
     print"Creating new database", dbname, "and tables", "in dir", os.getcwd() 

     connection = sqlite3.connect(dbname) 
      cursor = connection.cursor() 
      cursor.execute("""CREATE TABLE albums (music_location TEXT, genre TEXT, artist TEXT, album TEXT, album_number int)""") 
      connection.commit() 
      connection.close() 
      print"\nDatabase creation complete proceeding to program" 


    else: 
     print"Database name already exists!!!!!" 




def album_input(selection): 
    while True: 
     response = int(raw_input(selection)) 
     get_albums.append(response) 
     if response == 0: 
      print 'continuing' 


def process_albums(): 

    for num in get_albums: 

     connection = sqlite3.connect(dbname) 
     cursor = connection.cursor() 
     connection.text_factory = str 
     album_results = cursor.execute("SELECT genre, music_location, artist, album FROM albums where album_number =?", (num,)) 
     (genre, music_location, artist, album) = album_results.fetchone() 
     connection.commit() 
     connection.close() 


     print genre 
     print album 
     genre_dir = os.path.join(dest_dir, genre) 
     artist_dir = os.path.join(genre_dir, artist) 
     album_dir = os.path.join(artist_dir, album) 

     if not os.path.isdir(genre_dir): 
      os.makedirs(genre_dir) 

     if not os.path.isdir(artist): 
      os.makedirs(artist) 

     if not os.path.isdir(album): 
      os.makedirs(album) 

     songs = [] 

     for root, dirs, files in os.walk(music_location): 
      for fname in files: 
       songs.append(fname) 
     sorted_songs = songs.sort 

     for test in sorted_songs: 
      finished_song = os.path.join(music_location, test) 
      new_finished_song = os.path.join(artist, test) 
      shutil.copyfile(finished_song, new_finished_song) 




#main 

dest_dir = raw_input("Enter the destination directory to move files to: ") 
start_database = makedatabase("mp3database.db") 
get_selections = album_input("Enter album numbers, Press 0 to process: ") 
start = process_albums 
finished = raw_input("Press Enter to exit") 
+1

'process_albums'の代わりに' process_albums() 'が必要です – zondo

+0

私はそれを修正し、print 'continueing'ステートメントを出してそこにbreakステートメントを置いています。定義されていません – bigclampx

+1

'sorted_songs = songs.sort'は' list.sort'メソッドへの参照にsorted_songsを割り当てています。正しく呼んだとしてもsorted_songsをNoneに設定すると、.'list.sort() 'isインプレイスメソッドはリスト上で呼び出してリストを繰り返し処理するか、 'sorted_songs = sorted(songs) 'を使用します。 –

答えて

0

2つのこと:

  1. プロセスのアルバムは、あなたが括弧を必要とするので、それを呼び出すために、関数です。 process_albumsをprocess_albums()で置き換えます。
  2. dbname is process_albums()を使用しました。これはmakedatabasename()メソッドのスコープ内でのみ定義されているので、これを使うことはできません。グローバル変数としてdbnameを使用することも、process_albumsのパラメータとして設定することもできます。
+0

私はこれらの問題の両方を修正し、ソートを修正しましたが、まだファイルをコピーしていませんか? – bigclampx

+0

現在、ファイルを移動しないで、ディレクトリを正しく作成しています。さらに、0を配列の一部として処理しようとしているようです。 – bigclampx

+0

誰かが興味を持っている場合は、すべての問題が働いているだけですが、問題は今はシロップとして遅いです。 – bigclampx

関連する問題