-1

現在、再生中の曲に関する iTunes からの情報を解析して出力するスクリプトがあります。曲が変更された場合にのみ印刷されます。曲の1分が経過した場合にのみ印刷したいと思いますが、これを行う方法がわかりません。

これは私が現在持っているコードです:

def giveData():
    last_title, last_artist, last_album = None, None, None
    while True:
       template = '"%s" by %s (%d)\n from %s'
       info = ''

iTunesCount = app('System Events').processes[its.name == 'iTunes'].count()
if iTunesCount > 0:
  iTunes = app('iTunes')
  if iTunes.player_state.get() == k.playing:
    track = iTunes.current_track.get()
    artist = track.artist.get()
    title = track.name.get()
    album = track.album.get()
    stars = track.rating.get()/20

     if title != last_title or artist != last_artist or album != last_album:

      last_title, last_artist, last_album = title, artist, album
      info = template % (title, artist, stars, album)

    # Trying new solution, still printing songs that haven't been playing
    # for 60s, just delaying printing them by 60s:

      now = time.time()
      future = now + 60
      while time.time() < future:
        pass

      song_info = title + " - " + artist
      print song_info`
4

1 に答える 1

0

タイムカウンターを追加するだけではどうですか?

import time

now = time.time()
future = now + 60
while time.time() < future:
    pass

print '60 seconds have passed'

または@Undeterminantが指摘したように、単に使用します

time.sleep(60)
于 2015-01-08T23:08:31.817 に答える