<s> import csv <EOL> import os <EOL> SPREADSHEET_DIR = None <EOL> PLAINTEXT_DIR = None <EOL> def spreadsheet_dir ( request ) : <EOL> global SPREADSHEET_DIR <EOL> if not SPREADSHEET_DIR : <EOL> SPREADSHEET_DIR = os . path . join ( request . folder , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return SPREADSHEET_DIR <EOL> def plaintext_dir ( request ) : <EOL> global PLAINTEXT_DIR <EOL> if not PLAINTEXT_DIR : <EOL> PLAINTEXT_DIR = os . path . join ( request . folder , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return PLAINTEXT_DIR <EOL> def save_spreadsheet ( request , name , ssheet ) : <EOL> if not os . path . isdir ( spreadsheet_dir ( request ) ) : <EOL> os . makedirs ( spreadsheet_dir ( request ) ) <EOL> ss_fpath = os . path . join ( spreadsheet_dir ( request ) , name + '<STR_LIT>' ) <EOL> with open ( ss_fpath , '<STR_LIT:wb>' ) as outfile : <EOL> writer = csv . DictWriter ( outfile , fieldnames = ssheet [ <NUM_LIT:0> ] , delimiter = "<STR_LIT:U+002C>" ) <EOL> writer . writeheader ( ) <EOL> for row in ssheet [ <NUM_LIT:1> : ] : <EOL> writer . writerow ( row ) <EOL> def save_plaintext ( request , name , ptext ) : <EOL> if not os . path . isdir ( plaintext_dir ( request ) ) : <EOL> os . makedirs ( plaintext_dir ( request ) ) <EOL> pt_fpath = os . path . join ( plaintext_dir ( request ) , name + '<STR_LIT>' ) <EOL> with open ( pt_fpath , '<STR_LIT:wb>' ) as outfile : <EOL> outfile . write ( ptext ) </s>
