<s> from flask import Flask , render_template , request , redirect , url_for <EOL> from opentok import OpenTok , MediaModes , OutputModes <EOL> from email . utils import formatdate <EOL> import os , time <EOL> try : <EOL> api_key = os . environ [ '<STR_LIT>' ] <EOL> api_secret = os . environ [ '<STR_LIT>' ] <EOL> except Exception : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> app = Flask ( __name__ ) <EOL> opentok = OpenTok ( api_key , api_secret ) <EOL> session = opentok . create_session ( media_mode = MediaModes . routed ) <EOL> @ app . template_filter ( '<STR_LIT>' ) <EOL> def datefmt ( dt ) : <EOL> return formatdate ( time . mktime ( dt . timetuple ( ) ) ) <EOL> @ app . route ( "<STR_LIT:/>" ) <EOL> def index ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def host ( ) : <EOL> key = api_key <EOL> session_id = session . session_id <EOL> token = opentok . generate_token ( session_id ) <EOL> return render_template ( '<STR_LIT>' , api_key = key , session_id = session_id , token = token ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def participant ( ) : <EOL> key = api_key <EOL> session_id = session . session_id <EOL> token = opentok . generate_token ( session_id ) <EOL> return render_template ( '<STR_LIT>' , api_key = key , session_id = session_id , token = token ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def history ( ) : <EOL> page = int ( request . args . get ( '<STR_LIT>' , '<STR_LIT:1>' ) ) <EOL> offset = ( page - <NUM_LIT:1> ) * <NUM_LIT:5> <EOL> archives = opentok . get_archives ( offset = offset , count = <NUM_LIT:5> ) <EOL> show_previous = '<STR_LIT>' + str ( page - <NUM_LIT:1> ) if page > <NUM_LIT:1> else None <EOL> show_next = '<STR_LIT>' + str ( page + <NUM_LIT:1> ) if archives . count > ( offset + <NUM_LIT:5> ) else None <EOL> return render_template ( '<STR_LIT>' , archives = archives , show_previous = show_previous , <EOL> show_next = show_next ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def download ( archive_id ) : <EOL> archive = opentok . get_archive ( archive_id ) <EOL> return redirect ( archive . url ) <EOL> @ app . route ( "<STR_LIT>" , methods = [ '<STR_LIT:POST>' ] ) <EOL> def start ( ) : <EOL> has_audio = '<STR_LIT>' in request . form . keys ( ) <EOL> has_video = '<STR_LIT>' in request . form . keys ( ) <EOL> output_mode = OutputModes [ request . form . get ( '<STR_LIT>' ) ] <EOL> archive = opentok . start_archive ( session . session_id , name = "<STR_LIT>" , <EOL> has_audio = has_audio , has_video = has_video , output_mode = output_mode ) <EOL> return archive . json ( ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def stop ( archive_id ) : <EOL> archive = opentok . stop_archive ( archive_id ) <EOL> return archive . json ( ) <EOL> @ app . route ( "<STR_LIT>" ) <EOL> def delete ( archive_id ) : <EOL> opentok . delete_archive ( archive_id ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> app . debug = True <EOL> app . run ( ) </s>
