Last active
December 17, 2015 05:39
-
-
Save dnsfdv/5559637 to your computer and use it in GitHub Desktop.
./brads-as-text.py | say -v Milena -o book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
#coding=utf-8 | |
import sys | |
import os | |
import re | |
import math | |
from pytils import numeral | |
output_file =r'output.txt' | |
func = {'sin':0, 'cos':1, 'tg':2, 'ctg':3} | |
func_words = {0:'синус', 1:'косинус', 2:'тангенс', 3:'котангенс'} | |
def print_to_file(): | |
fw = open(output_file, 'w') | |
fw.write('') | |
fw.close() | |
fw = open(output_file, 'a') | |
for line in gen(): | |
fw.write(line+'\n') | |
fw.close() | |
print 'done' | |
def print_to_console(): | |
for line in gen(): | |
print line | |
def gen(): | |
for count in range(4): | |
yield func_words[count]+'ы,' | |
for angle in range(90): | |
angle+=1 | |
yield func_words[count]+ ' ' + digit_to_word_first(angle) + digit_to_word(calc(angle, count)) | |
def calc(angle, function): | |
return { | |
0 : math.sin(math.radians(angle)), | |
1 : math.sin(math.radians(90-angle)), | |
2 : math.tan(math.radians(angle)), | |
3 : math.tan(math.radians(90-angle)), | |
}[function] | |
def digit_to_word(number): | |
number=float('%.4f' % number) | |
if(number<10**11): | |
return numeral.in_words(number).encode('utf-8')+',' | |
else: | |
return 'стремится к бесконечности,' | |
def digit_to_word_first(number): | |
assert number<=90 | |
less20 = [u'нуля', u'одного', u'двух', u'трех', u'четырёх', u'пяти', u'шести', u'семи', u'восьми', u'девяти', u'десяти', | |
u'одиннадцати', u'двенадцати', u'тринадцати', u'четырнадцати', u'пятнадцати', | |
u'шестнадцати', u'семнадцати', u'восемнадцати', u'девятнадцати'] | |
more20 = [u'0',u'1', u'двадцати', u'тридцати', u'сорока', u'пятидесяти', u'шестидесяти', u'семидесяти', u'восьмидесяти', u'девяноста'] | |
if number<20: | |
string=(less20[number]) | |
if number>=20: | |
first=number/10 | |
second=number%10 | |
if second==0: | |
string=(more20[first]) | |
else: | |
string=(more20[first]+' '+less20[second]) | |
return string.encode('utf-8')+', ' | |
if __name__ == '__main__': | |
if len(sys.argv) >= 2: | |
if sys.argv[1] == r'-h': | |
print r'Usage: bradis [-f file]' | |
if sys.argv[1] == r'-f': | |
if len(sys.argv) >= 3: | |
output_file=sys.argv[2] | |
print_to_file() | |
if len(sys.argv) == 1: | |
print_to_console() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment