diff --git a/button.py b/button.py index 93e682a..10d1570 100644 --- a/button.py +++ b/button.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 import time import RPi.GPIO as GPIO diff --git a/changes.txt b/changes.txt index 0b9d786..ece4641 100644 --- a/changes.txt +++ b/changes.txt @@ -1,15 +1,15 @@ +v0.2.5 * Changed readmp3s routine to clockytracklist (merge) - +v0.2.0 * Adjusted code for python 3 -0.1.0: +v0.1.0 * added max7219 support, added signal handling * Added additional logging messages for end of alarm * implemented SIGINT (Ctrl-C) handling to exit gracefully -0.0.5: - * initial working version +v0.0.5 * initial working version * show alarmtime in startup ------------------------------------------------------------ @@ -24,5 +24,5 @@ issues todo ---- -add SIGHUP handling for reload config changes config file format to json +add SIGHUP handling for reload config and intergrate reloading of changes to tracklist or config diff --git a/clocky.py b/clocky.py index 9038f70..912463c 100755 --- a/clocky.py +++ b/clocky.py @@ -11,16 +11,17 @@ from time import sleep,strftime import RPi.GPIO as GPIO import button import signal +import clockytracklist settings= {} looptype=0 quit=0 -print("\n +----------+\n | Clocky |\n | v0.2.0 |\n +----------+\n") +print("\n +----------+\n | Clocky |\n | v0.2.5 |\n +----------+\n") o_configfilename = "clocky.conf" -o_defaultalarmtime = 60*13+24 # hh*60+mm +o_defaultalarmtime = 60*14+10 # hh*60+mm o_showalarmtime=3 # time that the alarmtime shows after short press o_showtracktime=2 # note that this is per track, so total time is 10 times longer o_editdelaytime=3 # time it takes to qualify as longpress @@ -51,24 +52,6 @@ def writesettings(): pickle.dump(settings, handle) handle.close() -def readmp3list(): - c=0 - mp3s=[] - dirs=os.listdir('.') - - for ent in os.listdir('.'): - if ent.lower().endswith(".mp3") and os.access(ent,os.R_OK): - mp3s.append(ent) - mp3s.sort() - for m in mp3s: - c+=1 - if c>99: break - - if c: - return(mp3s) - else: - return(0) - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # looptype=0 @@ -94,7 +77,8 @@ display.SetBrightnessRaw(o_defaultbrightness) print("") print("reading mp3s from directory:") -allmp3s=readmp3list() +tracks=clockytracklist.ClockyTracklist("mp3",recursive=True,verbose=True) +allmp3s=tracks.tracklist if allmp3s==0: print("ERROR: No mp3's found!") display.showclock(" E rr") @@ -585,6 +569,11 @@ while quit!=True: settings['starttrack']=track; writesettings() +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + if count % 40 == 0: + print("#") + tracks.CheckTrackList() #------------------------------------------------------------------ if pygame.mixer.get_init(): diff --git a/clockytracklist.py b/clockytracklist.py index 37137a8..3b7e271 100644 --- a/clockytracklist.py +++ b/clockytracklist.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from pathlib import Path @@ -6,7 +6,7 @@ EXTENSIONS=(".mp3",".ogg",".wav",".mpa",".m4a",".flac") class ClockyTracklist: """read and monitor directory with audio files""" - def __init__(self,path=".",recursive=False,verbose=False): + def __init__(self,path=".",recursive=False,sort=False,verbose=False): """Read (current or supplied) path for all audio files. Add recursive=True to check all subdirectories too""" self.recursive=recursive self.path=path @@ -18,6 +18,8 @@ class ClockyTracklist: exit(); self.__ReadTrackList() + if sort: + self.tracklist.sort() if(self.__verbose): self.ShowTrackList() diff --git a/max7219.py b/max7219.py index 5f6bad2..5b158fc 100644 --- a/max7219.py +++ b/max7219.py @@ -1,8 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2017-18 Richard Hull and contributors -# See LICENSE.rst for details. - +#!/usr/bin/env python3 import re import time diff --git a/tracktest.py b/tracktest.py old mode 100644 new mode 100755 index 6885c38..eb7f3d3 --- a/tracktest.py +++ b/tracktest.py @@ -1,23 +1,22 @@ -#!/usr/bin/python +#!/usr/bin/python3 import time import clockytracklist print("-------------------------------------") print("-------------------------------------") -t1=clockytracklist.ClockyTracklist("mp3",True,True) -t1.ShowTrackList() +tl=clockytracklist.ClockyTracklist("mp3",recursive=True,sort=False,verbose=True) +tl.ShowTrackList() print("-------------------------------------") -t2=clockytracklist.ClockyTracklist("C:\data",True,True) -t2.ShowTrackList() +for e in tl.tracklist: + print(e); t=0 while True: t+=1 - t1.CheckTrackList() - t2.CheckTrackList() + tl.CheckTrackList() time.sleep(1) if(t>30):