Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*Write the contents of HTML documents from memory to individual files* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import str 

10import sys 

11import os 

12os.environ['TERM'] = 'vt100' 

13from fundamentals import tools 

14 

15def _dump_files_to_local_drive(bodies, theseUrls, log): 

16 """ 

17 *takes the files stored in memory and dumps them to the local drive* 

18 

19 **Key Arguments** 

20 

21  

22 - ``bodies`` -- array of file data (currently stored in memory) 

23 - ``theseUrls`` -- array of local files paths to dump the file data into 

24 - ``log`` -- the logger 

25 

26 **Return** 

27 

28  

29 - ``None`` 

30 """ 

31 j = 0 

32 log.debug("attempting to write file data to local drive") 

33 log.debug('%s URLS = %s' % (len(theseUrls), str(theseUrls),)) 

34 for body in bodies: 

35 try: 

36 if theseUrls[j]: 

37 with open(theseUrls[j], 'wb') as f: 

38 f.write(body) 

39 f.close() 

40 j += 1 

41 except Exception as e: 

42 log.error( 

43 "could not write downloaded file to local drive - failed with this error %s: " % 

44 (str(e),)) 

45 return -1 

46 return