Advertisement
Guest User

Untitled

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