<s> """<STR_LIT>""" <EOL> import urllib <EOL> import urllib2 <EOL> import re <EOL> import sys <EOL> import os <EOL> from optparse import OptionParser <EOL> from getpass import getpass <EOL> VERSION = "<STR_LIT>" <EOL> class Instapaper : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , user , password ) : <EOL> self . user = user <EOL> self . password = password <EOL> self . authurl = "<STR_LIT>" <EOL> self . addurl = "<STR_LIT>" <EOL> def add_item ( self , url , title = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> parameters = { '<STR_LIT:username>' : self . user , '<STR_LIT:password>' : self . password , <EOL> '<STR_LIT:url>' : url , '<STR_LIT:title>' : title } <EOL> headerdata = urllib . urlencode ( parameters ) <EOL> try : <EOL> request = urllib2 . Request ( self . addurl , headerdata ) <EOL> response = urllib2 . urlopen ( request ) . read ( ) <EOL> if ( int ( response ) == <NUM_LIT> ) : <EOL> return <NUM_LIT:0> <EOL> elif ( int ( response ) == <NUM_LIT> ) : <EOL> return - <NUM_LIT:2> <EOL> elif ( int ( response ) == <NUM_LIT> ) : <EOL> return - <NUM_LIT:3> <EOL> else : <EOL> return - <NUM_LIT:1> <EOL> except IOError : <EOL> return - <NUM_LIT:1> <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> return_values = { <EOL> - <NUM_LIT:1> : "<STR_LIT>" , <EOL> - <NUM_LIT:2> : "<STR_LIT>" , <EOL> - <NUM_LIT:3> : "<STR_LIT>" <EOL> } <EOL> usage = "<STR_LIT>" <EOL> parser = OptionParser ( usage , version = "<STR_LIT>" + VERSION ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT:user>" , <EOL> metavar = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT:password>" , <EOL> metavar = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , dest = "<STR_LIT:title>" , <EOL> metavar = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if not options . title : <EOL> title = "<STR_LIT>" <EOL> else : <EOL> title = options . title <EOL> if not len ( args ) > <NUM_LIT:0> : <EOL> parser . error ( "<STR_LIT>" ) <EOL> if not options . user : <EOL> login = re . compile ( "<STR_LIT>" ) <EOL> try : <EOL> config = open ( os . path . expanduser ( "<STR_LIT>" ) + "<STR_LIT>" ) <EOL> for line in config : <EOL> matches = login . match ( line ) <EOL> if matches : <EOL> user = matches . group ( <NUM_LIT:1> ) . strip ( ) <EOL> password = matches . group ( <NUM_LIT:2> ) . strip ( ) <EOL> except IOError : <EOL> parser . error ( "<STR_LIT>" ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> else : <EOL> user = options . user <EOL> if not options . password : <EOL> password = getpass ( ) <EOL> else : <EOL> password = options . password <EOL> inst = Instapaper ( user , password ) <EOL> result = inst . add_item ( args [ <NUM_LIT:0> ] , title ) <EOL> print return_values . get ( result ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
