<s> import sys <EOL> import os <EOL> import time <EOL> import datetime <EOL> import argparse <EOL> from twitter import * <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , type = argparse . FileType ( '<STR_LIT:r>' ) ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , type = argparse . FileType ( '<STR_LIT:r>' ) , required = True ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , type = argparse . FileType ( '<STR_LIT:w>' ) , required = True ) <EOL> args = parser . parse_args ( ) <EOL> CONSUMER_KEY = '<STR_LIT>' <EOL> CONSUMER_SECRET = '<STR_LIT>' <EOL> MY_TWITTER_CREDS = os . path . expanduser ( '<STR_LIT>' ) <EOL> if not os . path . exists ( MY_TWITTER_CREDS ) : <EOL> oauth_dance ( "<STR_LIT>" , CONSUMER_KEY , CONSUMER_SECRET , MY_TWITTER_CREDS ) <EOL> oauth_token , oauth_secret = read_token_file ( MY_TWITTER_CREDS ) <EOL> t = Twitter ( auth = OAuth ( oauth_token , oauth_secret , CONSUMER_KEY , CONSUMER_SECRET ) ) <EOL> cache = { } <EOL> if args . partial != None : <EOL> for line in args . partial : <EOL> fields = line . strip ( ) . split ( "<STR_LIT:\t>" ) <EOL> text = fields [ - <NUM_LIT:1> ] <EOL> sid = fields [ <NUM_LIT:0> ] <EOL> cache [ sid ] = text <EOL> for line in args . dist : <EOL> fields = line . strip ( ) . split ( '<STR_LIT:\t>' ) <EOL> sid = fields [ <NUM_LIT:0> ] <EOL> uid = fields [ <NUM_LIT:1> ] <EOL> while not sid in cache : <EOL> try : <EOL> text = t . statuses . show ( _id = sid ) [ '<STR_LIT:text>' ] . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) . replace ( '<STR_LIT:\r>' , '<STR_LIT:U+0020>' ) <EOL> cache [ sid ] = text <EOL> except TwitterError as e : <EOL> if e . e . code == <NUM_LIT> : <EOL> rate = t . application . rate_limit_status ( ) <EOL> reset = rate [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> now = datetime . datetime . today ( ) <EOL> future = datetime . datetime . fromtimestamp ( reset ) <EOL> seconds = ( future - now ) . seconds + <NUM_LIT:1> <EOL> if seconds < <NUM_LIT> : <EOL> sys . stderr . write ( "<STR_LIT>" % ( seconds , future ) ) <EOL> time . sleep ( seconds ) <EOL> else : <EOL> cache [ sid ] = '<STR_LIT>' <EOL> text = cache [ sid ] <EOL> args . output . write ( "<STR_LIT:\t>" . join ( fields + [ text ] ) + '<STR_LIT:\n>' ) </s>
