Created
December 26, 2016 22:51
-
-
Save onlurking/5185abd22f89592057ce3b962f89ad72 to your computer and use it in GitHub Desktop.
This file contains 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
import asyncio | |
from os import devnull | |
from urllib.request import urlopen | |
from urllib.parse import quote | |
from subprocess import call | |
async def produce_lines(filename): | |
try: | |
with open(filename, 'r') as file: | |
for line in file: | |
yield line.rstrip('\n') | |
await asyncio.sleep(1) | |
except FileNotFoundError: | |
with open("poe.txt", 'w', encoding='utf8') as file: | |
file.write( | |
(urlopen("http://www.gutenberg.org/dirs/2/1/4/2147/2147-8.txt") | |
.read() | |
.decode("iso8859"))) | |
print("Hi, I've downloaded the The Works of Edgar Allan Poe (Volume 1) for you.\nPlease, re-run this program, shall you..?") | |
async def print_lines(filename): | |
async for line in produce_lines(filename): | |
if line: | |
with open(devnull, 'wb'): | |
call(['mpv', 'http://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q={}&tl=En-gb'.format( | |
quote(line, safe=""))], stdout=open(devnull, 'wb')) | |
def main(): | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(print_lines("poe.txt")) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment