Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import pysftp
  2. import time
  3. import os
  4. import subprocess
  5.  
  6.  
  7. def send_audio_file(path):
  8.     with pysftp.Connection('192.168.0.103', username='pi', password='raspberry') as sftp:
  9.         with sftp.cd('/home/pi/play_this'):
  10.             with open(path + '.ready', 'w') as lockfile:
  11.                 lockfile.close()
  12.             sftp.put(path)
  13.             sftp.put(path + '.ready')
  14.  
  15.  
  16. def receive():
  17.     p = subprocess.Popen(['echo', 'Running dumbstreamer'])
  18.     running = ''
  19.     while True:
  20.         if p.poll() is not None:  # not playing the audio
  21.             if running is not '':  # something just finished
  22.                 os.remove(running)
  23.                 os.remove(running + '.ready')
  24.                 running = ''
  25.  
  26.             for file in os.listdir('/home/pi/play_this'):
  27.                 if '.ready' in file:
  28.                     file = file.replace('.ready', '')
  29.                     p = subprocess.Popen(['mpg123', file])
  30.                     running = file
  31.         time.sleep(3)
  32.  
  33. receive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement