| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright (c) 2021 Mike Webb |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
# -- |
| 19 |
|
| 20 |
#https://stackoverflow.com/questions/16953842/using-os-walk-to-recursively-traverse-directories-in-python |
| 21 |
#given a folder name, walk through its entire hierarchy |
| 22 |
|
| 23 |
import os, time, http.client, urllib |
| 24 |
now = time.time() |
| 25 |
nowLess24h = time.time() - (48*60*60) #48 hours |
| 26 |
podList = [] |
| 27 |
|
| 28 |
def recursive_walk(folder): |
| 29 |
global podList |
| 30 |
for folderName, subfolders, filenames in os.walk(folder): |
| 31 |
if subfolders: |
| 32 |
for subfolder in subfolders: |
| 33 |
recursive_walk(subfolder) |
| 34 |
created = os.path.getctime(folderName) |
| 35 |
if created <= now and created >= nowLess24h: |
| 36 |
#print(folderName, created) |
| 37 |
lenFolderName = len(folderName) |
| 38 |
folderName = (folderName[13:lenFolderName]) |
| 39 |
if folderName != ".LOG" and folderName != "m3u-tmp": |
| 40 |
#print(folderName) |
| 41 |
podList.append(folderName) |
| 42 |
|
| 43 |
recursive_walk('/home/pi/POD/') #where your podcast's are located) |
| 44 |
|
| 45 |
podsStr = "<font color='#ff8000'><b>Last 48h pod Casts</b></font>" + chr(int(10)) + ''.join(str(e) + chr(int(10)) for e in podList) #the font etc stuff is to give a coloured heading to the Pushover list of podcasts |
| 46 |
#print(podsStr) |
| 47 |
PUSH_MSG = podsStr |
| 48 |
|
| 49 |
#setup pushover API |
| 50 |
app_key = "xxx" |
| 51 |
user_key = "yyy" |
| 52 |
|
| 53 |
#This function sends the push message using Pushover. |
| 54 |
def sendPush(PUSH_MSG): |
| 55 |
conn = http.client.HTTPSConnection("api.pushover.net:443") |
| 56 |
conn.request("POST", "/1/messages.json", |
| 57 |
urllib.parse.urlencode({ |
| 58 |
"token": app_key, |
| 59 |
"user": user_key, |
| 60 |
"message": PUSH_MSG, |
| 61 |
"html": 1, |
| 62 |
"sound": "tugboat" |
| 63 |
}), { "Content-type": "application/x-www-form-urlencoded" }) |
| 64 |
|
| 65 |
conn.getresponse() |
| 66 |
return |
| 67 |
|
| 68 |
# Run function to send message to Pushover |
| 69 |
sendPush(PUSH_MSG) |
| 70 |
|