Three new scripts give bespoke configuration for specific extensions

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os

path = "/home/chris/Dropbox/K6_primo/ssml/"
def fcount(path):
    """ Counts the number of files in a directory """
    count = 0
    for f in os.listdir(path):
        if os.path.isfile(os.path.join(path, f)):
            count += 1
    return (count)

count_files = (fcount(path))

zero = open("/home/chris/Dropbox/K6_primo/ssml/0.xml", "w")

zero.write("""<?xml version="1.0" encoding="UTF-8"?>
You have dialed zero. <break time="1000ms"></break>
You may dial any number between 101 and 10""""""%d""""""
.</xml>""" %count_files)

zero.close()
 
poemnumber = open("/home/chris/Dropbox/K6_primo/poemnumber.txt", "w")

poemnumber.write("%d" %count_files)

poemnumber.close()

number_as_string = str(count_files)

print("ssml files %d" %count_files)

0.py – for calls to operator

note the requirement to specify encoding as UTF 8 in order for XML to be rendered correctly and note the crazy number of quote marks required

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os

path = "/home/chris/Dropbox/K6_primo/audio/stories/"
map = {}
def fcount(path, map = {}):
  count = 0
  for f in os.listdir(path):
    child = os.path.join(path, f)
    if os.path.isdir(child):
      child_count = fcount(child, map)
      count += child_count + 1 # unless include self
  map[path] = count
  return count

count_files = ((fcount(path))+201) 

twohundred = open("/home/chris/Dropbox/K6_primo/ssml/200.xml", "w")

twohundred.write("""<?xml version="1.0" encoding="UTF-8"?>
You have dialed 200. <break time="1000ms"></break>
To leave your story dial """"""%d""""""
.</xml>""" %count_files)

twohundred.close()

storynumber = open("/home/chris/Dropbox/K6_primo/storynumber.txt", "w")

storynumber.write("%d" %count_files)

storynumber.close()

number_as_string = str(count_files)

print("stories %d" %count_files)

# make folder for story files to be stored

os.mkdir("/home/chris/Dropbox/K6_primo/audio/stories/%d" %count_files)

200.py – this deals with user recordings – note it generates the directory ready for PD to make the recording – there has got to be a better way to do this

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
path = "/home/chris/Dropbox/K6_primo/ssml/"
def fcount(path):
    """ Counts the number of files in a directory """
    count = 0
    for f in os.listdir(path):
        if os.path.isfile(os.path.join(path, f)):
            count += 1
    return (count) 

count_files = (fcount(path))

print count_files

threehundred = open("/home/chris/Dropbox/K6_primo/ssml/300.xml", "w")

threehundred.write("Thank you for picking up. There are %d in the ssml folder" %count_files)

threehundred.close()

poemnumber = open("/home/chris/Dropbox/K6_primo/poemnumber.txt", "w")

poemnumber.write('%d' %count_files)

poemnumber.close()

number_as_string = str(count_files)

print("ssml files %d" %count_files)

300.py – deals with users picking up when the phone rings

Leave a Reply

Your email address will not be published.