<s> import datetime <EOL> import logging <EOL> from google . appengine . api import taskqueue <EOL> from base . constants import CONSTANTS <EOL> import base . handlers <EOL> import data <EOL> _FREQUENCY_DISPLAY_NAMES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> class MainHandler ( base . handlers . BaseHandler ) : <EOL> def get ( self ) : <EOL> self . _write_template ( '<STR_LIT>' ) <EOL> class AdvanceCronHandler ( base . handlers . BaseHandler ) : <EOL> def get ( self ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> frequency = self . request . get ( '<STR_LIT>' ) <EOL> frequency_modulo = int ( self . request . get ( '<STR_LIT>' ) ) <EOL> current_modulo = data . get_modulo_for_frequency ( frequency ) <EOL> if current_modulo != frequency_modulo : <EOL> logging . info ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( frequency_modulo , current_modulo ) ) <EOL> return <EOL> subscriptions = data . get_subscriptions_with_frequency_and_modulo ( <EOL> frequency , frequency_modulo ) <EOL> for subscription in subscriptions : <EOL> taskqueue . add ( <EOL> queue_name = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : subscription . id } ) <EOL> logging . info ( '<STR_LIT>' % len ( subscriptions ) ) <EOL> self . response . out . write ( '<STR_LIT:OK>' ) <EOL> class AdvanceTaskHandler ( base . handlers . BaseHandler ) : <EOL> def post ( self ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> subscription_id = self . request . get ( '<STR_LIT>' ) <EOL> subscription = data . get_subscription_by_id ( subscription_id ) <EOL> subscription . advance ( ) <EOL> self . response . out . write ( '<STR_LIT:OK>' ) <EOL> class PreviewHandler ( base . handlers . BaseHandler ) : <EOL> def get ( self ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> url = self . request . get ( '<STR_LIT:url>' ) . strip ( ) <EOL> if not url : <EOL> self . _write_input_error ( '<STR_LIT>' ) <EOL> return <EOL> try : <EOL> start_date = datetime . datetime . strptime ( <EOL> self . request . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> except ValueError : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . _write_json ( { <EOL> '<STR_LIT>' : data . get_start_item_contents ( url , start_date ) . as_json_dict ( ) , <EOL> } ) <EOL> class CreateHandler ( base . handlers . BaseHandler ) : <EOL> def post ( self ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> url = self . request . get ( '<STR_LIT:url>' ) . strip ( ) <EOL> if not url : <EOL> self . _write_input_error ( '<STR_LIT>' ) <EOL> return <EOL> try : <EOL> start_date = datetime . datetime . strptime ( <EOL> self . request . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> except ValueError : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> frequency = self . request . get ( '<STR_LIT>' ) <EOL> subscription = data . create_subscription ( <EOL> url , <EOL> start_date , <EOL> frequency ) <EOL> feed_info = data . get_feed_info_from_feed_url ( url ) <EOL> feed_title = feed_info . title <EOL> subscription_html_url = '<STR_LIT>' % ( <EOL> CONSTANTS . APP_URL , subscription . id ) <EOL> subscription . create_reader_stream ( <EOL> intro_html_url = subscription_html_url , <EOL> intro_title = '<STR_LIT>' % feed_title , <EOL> intro_body = self . _render_template ( <EOL> '<STR_LIT>' , { <EOL> '<STR_LIT>' : subscription_html_url , <EOL> '<STR_LIT>' : url , <EOL> '<STR_LIT>' : feed_title , <EOL> '<STR_LIT>' : len ( feed_info . item_ids ) - subscription . position , <EOL> '<STR_LIT>' : _FREQUENCY_DISPLAY_NAMES [ frequency ] , <EOL> } ) ) <EOL> self . _write_json ( subscription . as_json_dict ( ) ) <EOL> class FeedInfoHandler ( base . handlers . BaseHandler ) : <EOL> def get ( self ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> url = self . request . get ( '<STR_LIT:url>' ) . strip ( ) <EOL> if not url : <EOL> self . _write_input_error ( '<STR_LIT>' ) <EOL> return <EOL> feed_info = data . get_feed_info ( url ) <EOL> if feed_info : <EOL> self . _write_json ( feed_info . as_json_dict ( ) ) <EOL> else : <EOL> self . _write_input_error ( '<STR_LIT>' ) <EOL> class SubscriptionHandler ( base . handlers . BaseHandler ) : <EOL> def get ( self , subscription_id ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> subscription = data . get_subscription_by_id ( subscription_id ) <EOL> if not subscription : <EOL> self . _write_not_found ( ) <EOL> return <EOL> feed_info = data . get_feed_info_from_feed_url ( subscription . feed_url ) <EOL> self . _write_template ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : feed_info . title , <EOL> '<STR_LIT>' : subscription . feed_url , <EOL> '<STR_LIT>' : subscription_id , <EOL> '<STR_LIT>' : subscription . get_subscription_feed_url ( ) , <EOL> '<STR_LIT>' : subscription . get_subscription_reader_url ( ) , <EOL> '<STR_LIT>' : subscription . position + <NUM_LIT:1> , <EOL> '<STR_LIT>' : len ( feed_info . item_ids ) , <EOL> '<STR_LIT>' : _FREQUENCY_DISPLAY_NAMES [ subscription . frequency ] <EOL> } ) <EOL> class SubscriptionAdvanceHandler ( base . handlers . BaseHandler ) : <EOL> def post ( self ) : <EOL> self . _write_error ( <NUM_LIT> ) <EOL> return <EOL> subscription_id = self . request . get ( '<STR_LIT>' ) <EOL> subscription = data . get_subscription_by_id ( subscription_id ) <EOL> subscription . advance ( ) <EOL> self . redirect ( '<STR_LIT>' % subscription_id ) </s>
