<s> import os <EOL> import sys <EOL> import json <EOL> import flask <EOL> from flask import request , Response <EOL> from boto import dynamodb2 <EOL> from boto . dynamodb2 . table import Table <EOL> from boto . dynamodb2 . items import Item <EOL> from boto . dynamodb2 . exceptions import ConditionalCheckFailedException <EOL> from boto import sns <EOL> THEME = '<STR_LIT:default>' if os . environ . get ( '<STR_LIT>' ) is None else os . environ . get ( '<STR_LIT>' ) <EOL> FLASK_DEBUG = '<STR_LIT:false>' if os . environ . get ( '<STR_LIT>' ) is None else os . environ . get ( '<STR_LIT>' ) <EOL> application = flask . Flask ( __name__ ) <EOL> application . config . from_object ( __name__ ) <EOL> application . config . from_envvar ( '<STR_LIT>' , silent = True ) <EOL> application . debug = application . config [ '<STR_LIT>' ] in [ '<STR_LIT:true>' , '<STR_LIT:True>' ] <EOL> ddb_conn = dynamodb2 . connect_to_region ( application . config [ '<STR_LIT>' ] ) <EOL> ddb_table = Table ( table_name = application . config [ '<STR_LIT>' ] , <EOL> connection = ddb_conn ) <EOL> sns_conn = sns . connect_to_region ( application . config [ '<STR_LIT>' ] ) <EOL> @ application . route ( '<STR_LIT:/>' ) <EOL> def welcome ( ) : <EOL> theme = application . config [ '<STR_LIT>' ] <EOL> return flask . render_template ( '<STR_LIT>' , theme = theme , flask_debug = application . debug ) <EOL> @ application . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def signup ( ) : <EOL> signup_data = dict ( ) <EOL> for item in request . form : <EOL> signup_data [ item ] = request . form [ item ] <EOL> try : <EOL> store_in_dynamo ( signup_data ) <EOL> publish_to_sns ( signup_data ) <EOL> except ConditionalCheckFailedException : <EOL> return Response ( "<STR_LIT>" , status = <NUM_LIT> , mimetype = '<STR_LIT:application/json>' ) <EOL> return Response ( json . dumps ( signup_data ) , status = <NUM_LIT> , mimetype = '<STR_LIT:application/json>' ) <EOL> def store_in_dynamo ( signup_data ) : <EOL> signup_item = Item ( ddb_table , data = signup_data ) <EOL> signup_item . save ( ) <EOL> def publish_to_sns ( signup_data ) : <EOL> try : <EOL> sns_conn . publish ( application . config [ '<STR_LIT>' ] , json . dumps ( signup_data ) , "<STR_LIT>" % signup_data [ '<STR_LIT:email>' ] ) <EOL> except Exception as ex : <EOL> sys . stderr . write ( "<STR_LIT>" % ex . message ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> application . run ( host = '<STR_LIT>' ) </s>
