<s> import csv <EOL> import json <EOL> import os <EOL> import time <EOL> from tabulate import tabulate <EOL> def serve_content ( data , user , format_ = None ) : <EOL> if format_ is not None and len ( data ) > <NUM_LIT:0> : <EOL> directory = '<STR_LIT>' <EOL> if not os . path . exists ( directory ) : <EOL> os . makedirs ( directory ) <EOL> file_ = '<STR_LIT>' . format ( <EOL> directory , user , time . strftime ( '<STR_LIT>' ) , format_ ) <EOL> f = open ( file_ , '<STR_LIT:w>' ) <EOL> if format_ == '<STR_LIT>' : <EOL> f . write ( json . dumps ( data , indent = <NUM_LIT:4> ) ) <EOL> elif format_ == '<STR_LIT>' : <EOL> keys = data [ <NUM_LIT:0> ] . keys ( ) <EOL> dw = csv . DictWriter ( f , fieldnames = keys ) <EOL> dw . writeheader ( ) <EOL> dw . writerows ( data ) <EOL> elif format_ == '<STR_LIT>' : <EOL> f . write ( '<STR_LIT>' % user ) <EOL> for r in data : <EOL> star_str = '<STR_LIT>' if r [ '<STR_LIT>' ] == <NUM_LIT:1> else '<STR_LIT>' <EOL> f . write ( '<STR_LIT>' . format ( r [ '<STR_LIT:name>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> star_str ) ) <EOL> elif format_ == '<STR_LIT>' : <EOL> f . write ( '<STR_LIT>' % user ) <EOL> for r in data : <EOL> star_str = '<STR_LIT>' if r [ '<STR_LIT>' ] == <NUM_LIT:1> else '<STR_LIT>' <EOL> f . write ( '<STR_LIT>' . format ( r [ '<STR_LIT:name>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> star_str ) ) <EOL> elif format_ == '<STR_LIT>' : <EOL> f . write ( '<STR_LIT>' % user ) <EOL> f . write ( tabulate ( data , headers = "<STR_LIT>" ) ) <EOL> f . close ( ) <EOL> else : <EOL> print ( tabulate ( data , headers = "<STR_LIT>" ) ) <EOL> return None <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> serve_content ( [ ] , '<STR_LIT>' ) </s>
