<s> """<STR_LIT>""" <EOL> from wordpress_xmlrpc import Client , WordPressPost <EOL> from wordpress_xmlrpc . methods . posts import GetPosts , NewPost <EOL> from wordpress_xmlrpc . methods . users import GetUserInfo <EOL> import codecs <EOL> import credentials as cr <EOL> import json <EOL> import locale <EOL> import logging <EOL> import oauth2 as oauth <EOL> import optparse <EOL> import os <EOL> import sys <EOL> import warnings <EOL> __author__ = '<STR_LIT>' <EOL> __version__ = "<STR_LIT>" <EOL> script_name = os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> usage = '<STR_LIT>' <EOL> description = '''<STR_LIT>''' <EOL> logger = logging . getLogger ( script_name ) <EOL> def convert_comments_to_posts ( video_id , parent_post_id ) : <EOL> token = oauth . Token ( key = cr . token_key , secret = cr . token_secret ) <EOL> consumer = oauth . Consumer ( key = cr . consumer_key , secret = cr . consumer_secret ) <EOL> url = "<STR_LIT>" + str ( video_id ) <EOL> client = oauth . Client ( consumer , token ) <EOL> resp , content = client . request ( url ) <EOL> data = json . loads ( content ) <EOL> process_comments ( video_id , parent_post_id , data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def process_comments ( video_id , parent_post_id , comments ) : <EOL> wp = Client ( cr . wp_url , cr . wp_user , cr . wp_password ) <EOL> for comment in comments : <EOL> if '<STR_LIT>' in comment [ '<STR_LIT:text>' ] : <EOL> process_comment ( wp , video_id , parent_post_id , comment ) <EOL> def get_post_content ( video_id , comment ) : <EOL> text = comment [ '<STR_LIT:text>' ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return '<STR_LIT>' + text + '<STR_LIT>' + video_url ( video_id , text ) + '<STR_LIT>' + comment [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> def process_comment ( wp , video_id , parent_post_id , comment ) : <EOL> post = WordPressPost ( ) <EOL> post . title = comment [ '<STR_LIT:text>' ] [ <NUM_LIT:6> : <NUM_LIT:50> ] <EOL> post . content = get_post_content ( video_id , comment ) <EOL> post . post_type = '<STR_LIT>' <EOL> post . post_status = '<STR_LIT>' <EOL> post . parent_id = parent_post_id <EOL> print "<STR_LIT>" % wp . call ( NewPost ( post ) ) <EOL> def video_url ( video_id , comment_text ) : <EOL> url = '<STR_LIT>' % ( video_id , strip_time ( comment_text ) ) <EOL> logger . debug ( "<STR_LIT>" , url ) <EOL> return url <EOL> def strip_time ( text ) : <EOL> return text [ <NUM_LIT:0> : <NUM_LIT:2> ] + '<STR_LIT:m>' + text [ <NUM_LIT:3> : <NUM_LIT:5> ] + '<STR_LIT:s>' <EOL> def get_options ( argv ) : <EOL> '''<STR_LIT>''' <EOL> parser = optparse . OptionParser ( usage = usage , version = __version__ ) <EOL> parser . description = description <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:count>" , default = <NUM_LIT:0> , <EOL> help = "<STR_LIT>" ) <EOL> options , args = parser . parse_args ( list ( argv ) ) <EOL> script , args = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> : ] <EOL> return options , script , args , parser . format_help ( ) <EOL> def init_logger ( verbosity , stream = sys . stdout ) : <EOL> '''<STR_LIT>''' <EOL> is_not_debug = verbosity <= <NUM_LIT:2> <EOL> level = [ logging . ERROR , logging . WARNING , logging . INFO ] [ verbosity ] if is_not_debug else logging . DEBUG <EOL> format = '<STR_LIT>' if is_not_debug else '<STR_LIT>' <EOL> logging . basicConfig ( level = level , format = format , stream = stream ) <EOL> if is_not_debug : warnings . filterwarnings ( '<STR_LIT:ignore>' ) <EOL> def wrap_stream_for_tty ( stream ) : <EOL> if stream . isatty ( ) : <EOL> locale . setlocale ( locale . LC_ALL , '<STR_LIT>' ) <EOL> lang , encoding = locale . getdefaultlocale ( ) <EOL> logger . debug ( '<STR_LIT>' , lang , encoding ) <EOL> if encoding : <EOL> return codecs . getwriter ( encoding ) ( stream ) <EOL> else : <EOL> logger . warn ( '<STR_LIT>' ) <EOL> return stream <EOL> def main ( * argv ) : <EOL> options , script , args , help = get_options ( argv ) <EOL> init_logger ( options . verbosity ) <EOL> convert_comments_to_posts ( args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( * sys . argv ) ) </s>
