[Cpan-forum-commit] rev 259 - in trunk: . bin lib/CPAN/Forum/DB templates
svn at pti.co.il
svn at pti.co.il
Thu Jul 19 17:05:42 EEST 2007
Author: gabor
Date: 2007-07-19 17:05:42 +0300 (Thu, 19 Jul 2007)
New Revision: 259
Modified:
trunk/
trunk/bin/create_feed.pl
trunk/lib/CPAN/Forum/DB/Posts.pm
trunk/lib/CPAN/Forum/DB/Tags.pm
trunk/templates/faq.tmpl
Log:
clean up creation of csv feed of posts
add feed of list of tags
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4225
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
+ 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4226
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
Modified: trunk/bin/create_feed.pl
===================================================================
--- trunk/bin/create_feed.pl 2007-07-19 14:05:24 UTC (rev 258)
+++ trunk/bin/create_feed.pl 2007-07-19 14:05:42 UTC (rev 259)
@@ -9,39 +9,59 @@
use CPAN::Forum::DBI;
use CPAN::Forum::DB::Posts;
+use CPAN::Forum::DB::Tags;
my %opts;
-GetOptions(\%opts, 'help', 'dir=s', 'csv=s') or usage();
+GetOptions(\%opts, 'help', 'dbdir=s', 'out=s') or usage();
usage() if $opts{help};
-usage() if not $opts{dir} or not $opts{csv};
+usage() if not $opts{dbdir} or not $opts{out};
-my $dbfile = "$opts{dir}/forum.db";
+my $dbfile = "$opts{dbdir}/forum.db";
CPAN::Forum::DBI->myinit("dbi:SQLite:$dbfile");
-my $csv = Text::CSV_XS->new();
+posts_count_csv();
+tags();
+exit;
-;
-open my $out, '>', $opts{csv} or die $!;
-foreach my $entry (CPAN::Forum::DB::Posts->search_stat_posts(5000)) {
- if ($csv->combine($entry->{gname}, $entry->{cnt})) {
- print {$out} $csv->string(), "\n";
- } else {
- warn "Invalid row";
+sub posts_count_csv {
+ my $csv = Text::CSV_XS->new();
+
+ open my $out, '>', "$opts{out}/cpanforum.csv" or die $!;
+ my $ar = CPAN::Forum::DB::Posts->list_counted_posts;
+ foreach my $entry (@$ar) {
+ if ($csv->combine($entry->{gname}, $entry->{cnt})) {
+ print {$out} $csv->string(), "\n";
+ } else {
+ warn "Invalid row";
+ }
}
}
+sub tags {
+ my $ar = CPAN::Forum::DB::Tags->list_modules_and_tags;
+ my %data;
+ foreach my $hr (@$ar) {
+ push @{ $data{ $hr->{module} } }, $hr->{tag};
+ }
+ open my $out, '>', "$opts{out}/module_tags.csv" or die $!;
+ foreach my $module (sort keys %data) {
+ print $out join ",", $module, @{ $data{$module} };
+ print $out "\n";
+ }
+ close $out;
+ system "/bin/bzip2 -f $opts{out}/module_tags.csv";
+}
-
sub usage {
print <<"END_USAGE";
Usage: $0
--help this help
- --dir DIR directory of forum.db file
- --csv FILENAME path to the output csv file
+ --dbdir DIR directory of forum.db file
+ --out DIR path to the output directory
END_USAGE
exit;
}
Modified: trunk/lib/CPAN/Forum/DB/Posts.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Posts.pm 2007-07-19 14:05:24 UTC (rev 258)
+++ trunk/lib/CPAN/Forum/DB/Posts.pm 2007-07-19 14:05:42 UTC (rev 259)
@@ -126,5 +126,15 @@
);
}
+sub list_counted_posts {
+ my ($self) = @_;
+ my $sql = "SELECT groups.name gname, COUNT(*) cnt
+ FROM posts, groups
+ WHERE posts.gid=groups.id
+ GROUP BY gname
+ ORDER BY cnt DESC";
+ return $self->_fetch_arrayref_of_hashes($sql);
+}
+
1;
Modified: trunk/lib/CPAN/Forum/DB/Tags.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Tags.pm 2007-07-19 14:05:24 UTC (rev 258)
+++ trunk/lib/CPAN/Forum/DB/Tags.pm 2007-07-19 14:05:42 UTC (rev 259)
@@ -119,6 +119,13 @@
return $self->_fetch_arrayref_of_hashes($sql, $tag_name);
}
+sub list_modules_and_tags {
+ my ($self) = @_;
+ my $sql = "SELECT groups.name module, tags.name tag
+ FROM groups, tags, tag_cloud
+ WHERE tag_cloud.group_id=groups.id AND tag_cloud.tag_id=tags.id";
+ return $self->_fetch_arrayref_of_hashes($sql);
+}
=head1 Design
Modified: trunk/templates/faq.tmpl
===================================================================
--- trunk/templates/faq.tmpl 2007-07-19 14:05:24 UTC (rev 258)
+++ trunk/templates/faq.tmpl 2007-07-19 14:05:42 UTC (rev 259)
@@ -13,6 +13,7 @@
<li><a href="#whyweb">OK, but why web forum? Why not a mailing list with topics?</a></li>
<!-- <li><a href="#perlmonks">So what about Perl Monks? That is a web forum!</a></li>-->
<li><a href="#tags">Add tags to CPAN modules</a></li>
+ <li><a href="#data">Data supplied by CPAN::Forum</a></li>
</ol>
<hr />
<dl>
@@ -144,6 +145,17 @@
Soon you'll be able to see all the tags you created and all the modules
you tagged. You'll also be able to see tags created by others.
</dd>
+
+ <dt><a name="data">Data supplied by CPAN::Forum</a></dt>
+ <dd>
+ If other sites wouldlike to include data collected by CPAN::Forum,
+ this is what we have:
+ <br />
+ <a href="/cpanforum.csv">Number of posts per module</a> In format: <i>Module,42</i>
+ <br />
+ <a href="/module_tags.csv.bz2">List of tags on each module</a>In format: <i>Module,tag1,tag2,tag3</i>
+ </dd>
+
</dl>
</div>
<TMPL_INCLUDE NAME="footer.tmpl">
More information about the Cpan-forum-commit
mailing list