Advertisement
bolverk

radio_arxiv

Aug 9th, 2021
2,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. def get_input():
  2.  
  3.     from argparse import ArgumentParser
  4.     parser = ArgumentParser(description='get data from arxiv entry')
  5.     parser.add_argument('arxiv_id', type=str)
  6.     args = parser.parse_args()
  7.  
  8.     return args.arxiv_id
  9.  
  10. def main():
  11.  
  12.     import arxiv
  13.     import os
  14.     import shutil
  15.     import requests
  16.     import tarfile
  17.     from glob import glob
  18.     import pyttsx3
  19.  
  20.     arxiv_id = get_input()
  21.     paper = arxiv.query(id_list=[arxiv_id])[0]
  22.     if os.path.isdir(arxiv_id):
  23.         shutil.rmtree(arxiv_id)
  24.     os.mkdir(arxiv_id)
  25.     with open(arxiv_id+'/title.txt','w') as f:
  26.         f.write(paper['title'].rstrip().replace('\r', '').replace('\n', ''))
  27.     with open(arxiv_id+'/abstract.txt','w') as f:
  28.         f.write(paper['summary'].rstrip().replace('\r', '').replace('\n', ''))
  29.     # Download source
  30.     url = 'https://arxiv.org/e-print/'+arxiv_id
  31.     r = requests.get(url, allow_redirects=True)
  32.     open(arxiv_id+'/source.tar.gz', 'wb').write(r.content)
  33.  
  34.     os.chdir(arxiv_id)
  35.     tf = tarfile.open('source.tar.gz')
  36.     tf.extractall()
  37.     tex_files = glob('*.tex')
  38.     if len(tex_files)==1:
  39.         tex_file = tex_files[0]
  40.     else:
  41.         print('Multiple files found')
  42.         [print(str(n)+') '+fname) for n, fname in enumerate(tex_files)]
  43.         inp = input('Choose file\n')
  44.         if inp=='q':
  45.             exit()
  46.         tex_file = tex_files[int(inp)]
  47.     #tex_file = tex_files[0]
  48.     os.system('..\detex.exe '+tex_file+' > output.txt')
  49.     engine = pyttsx3.init()
  50.     engine.save_to_file(open('./output.txt','r').read().rstrip().replace('\n',' '),
  51.                         arxiv_id+'.mp3')
  52.     engine.runAndWait()
  53.     os.chdir('..')
  54.  
  55. if __name__ == '__main__':
  56.  
  57.     main()
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement