Changeset 540
- Timestamp:
- 10/13/08 01:42:40 (3 months ago)
- Location:
- DisqusExporter/trunk
- Files:
-
- 2 added
- 1 modified
-
samples (added)
-
samples/disqus.yaml (added)
-
tools/disqus-exporter.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
DisqusExporter/trunk/tools/disqus-exporter.pl
r539 r540 12 12 use warnings; 13 13 14 use lib 'lib', '../lib';14 use lib qw( lib ../lib ); 15 15 use MT::Bootstrap; 16 16 17 use constant BLOG_ID => 1; 18 use constant SHORT_NAME => 'your forum short name'; 19 use constant ANONYMOUS_EMAIL => 'nobody@your.domain'; 20 use constant USER_API_KEY => 'your user api key'; 17 our $VERSION = '0.1-dev'; 21 18 22 use constant VERBOSE => 0; 19 use Getopt::Long; 20 use YAML::Tiny; 23 21 24 our $VERSION = '0.1-dev'; 22 sub usage { 23 print "Usage: $0 --config <config.yaml> [ --verbose ]\n"; 24 exit(1); 25 } 26 27 GetOptions( 'config=s', \my $yaml, 'verbose', \my $verbose ) or usage(); 28 usage() unless defined $yaml; 29 my ($cfg) = YAML::Tiny::LoadFile($yaml); 30 for (qw( blog_id forum_name default_email user_api_key)) { 31 die "'$_' is not defined in $yaml" unless defined $cfg->{$_}; 32 } 25 33 26 34 use MT; … … 31 39 use WWW::Disqus; 32 40 33 my $api = WWW::Disqus->new( user_api_key => USER_API_KEY );34 $api->set_forum_api_key_by_forum_name(SHORT_NAME);35 36 41 my $mt = MT->new() or die MT->errstr; 37 my $blog = MT::Blog->load( BLOG_ID)38 or die 'Cannot find MT::Blog(ID:' . BLOG_ID. ')';42 my $blog = MT::Blog->load( $cfg->{blog_id} ) 43 or die 'Cannot find MT::Blog(ID:' . $cfg->{blog_id} . ')'; 39 44 my $iter = MT::Entry->load_iter( 40 45 { 41 blog_id => BLOG_ID,46 blog_id => $cfg->{blog_id}, 42 47 status => MT::Entry::RELEASE, 43 48 }, … … 45 50 join => [ 46 51 'MT::Comment', 'entry_id', 47 { blog_id => BLOG_ID, visible => 1 }, { unique => 1 }52 { blog_id => $cfg->{blog_id}, visible => 1 }, { unique => 1 } 48 53 ], 49 54 } 50 55 ); 56 57 my $api = WWW::Disqus->new( user_api_key => $cfg->{user_api_key} ); 58 $api->set_forum_api_key_by_forum_name( $cfg->{forum_name} ); 51 59 52 60 my %stats = ( … … 62 70 if ($@) { 63 71 $stats{entry_skipped}++; 64 print STDERR "Disqus API error: $@\n" if VERBOSE;72 print STDERR "Disqus API error: $@\n" if $verbose; 65 73 next; 66 74 } … … 70 78 print STDERR "No Disqus thread found for MT::Entry(ID:" 71 79 . $entry->id . ")\n" 72 if VERBOSE;80 if $verbose; 73 81 next; 74 82 } … … 82 90 83 91 # author_email 84 my $author_email = ANONYMOUS_EMAIL;92 my $author_email = $cfg->{default_email}; 85 93 if ( $comment->email && MT::Util::is_valid_email( $comment->email ) ) { 86 94 $author_email = $comment->email; … … 123 131 if ($@) { 124 132 $stats{comment_failed}++; 125 print STDERR "Disqus API error: $@\n" if VERBOSE;133 print STDERR "Disqus API error: $@\n" if $verbose; 126 134 next; 127 135 } … … 133 141 . ") successfully converted to Disqus post(ID:" 134 142 . $post->{id} . ")\n" 135 if VERBOSE;143 if $verbose; 136 144 } 137 145 $stats{entry_processed}++;
![(please configure the [header_logo] section in trac.ini)](/public/chrome/common/trac_banner.png)