forked from applications4android/ComicReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_all_gocomics_mod.pl
executable file
·130 lines (118 loc) · 3.51 KB
/
list_all_gocomics_mod.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
sub cleanupComicFileName {
my $name = shift;
if($name eq '(th)ink') {
return 'Think';
}
$name =~ s/1/One/gs;
$name =~ s/2/Two/gs;
$name =~ s/3/Three/gs;
$name =~ s/4/Four/gs;
$name =~ s/5/Five/gs;
$name =~ s/6/Six/gs;
$name =~ s/7/Seven/gs;
$name =~ s/8/Eight/gs;
$name =~ s/9/Nine/gs;
$name =~ s/0/Zero/gs;
$name =~ s/\@/at/gs;
$name =~ s/\&/n/gs;
$name =~ s/[!'"\s.-]//gs;
return $name;
}
sub cleanupPrefName {
my $name = shift;
$name =~ s/\@/At/gs;
$name =~ s/\&/n/gs;
$name =~ s/[!'"\s.-]//gs;
return $name;
}
my $isEditorial = ((scalar(@ARGV) == 1) && ($ARGV[0] eq '-editorial'));
my $url = "http://www.gocomics.com";
my $mainurl = $isEditorial? "http://www.gocomics.com/explore/editorial_list" : "http://www.gocomics.com/features";
my $mainpage = "gocomics.mainpage";
my $allcomics = $isEditorial? "all_gocomics_editorial.txt" : "all_gocomics.txt";
my @comicslist;
my $cname;
my $fname;
my $actname;
my $yr;
my $mon;
my $dat;
my $JSON = $isEditorial? "classes_editorial.json" : "classes.json";
open JSON, ">$JSON";
print "Getting all comics page...\n";
system("rm -f $mainpage $allcomics");
system("wget '$mainurl' -O $mainpage --quiet");
print "Getting all comics list...\n";
open(ALL, "<$mainpage") or die("Failed to open '$mainpage' for reading!");
while(my $line = <ALL>) {
chomp($line);
$line =~ s/^\s+//;
$line =~ s/\s+$//;
if($line =~ /^<a href=\"(.*?)\" class=\"alpha_list.*\">(.*?)<\/a>/) {
my $link = $url . $1;
my $name = $2;
push(@comicslist, [$link, $name, 0, 0]);
}
}
close(ALL);
print "Getting all comics' feature-ID...\n";
my $temp_file_comic = "gocomic.temp.feature.id";
foreach my $comic (@comicslist) {
print " Working on '$comic->[1]'... ";
system("rm -f $temp_file_comic");
my $link = $comic->[0];
system("wget '$link' -O $temp_file_comic --quiet");
# feature-id
$comic->[2] = 0;
# first strip date
my $first = `grep -i 'minDate' $temp_file_comic`;
chomp($first);
$first =~ s/.*minDate:\"//;
$first =~ s/\",.*//;
$yr=substr($first, 0, 4);
$mon=substr($first, 5, 2);
$dat=substr($first, 8, 2);
$mon=$mon-1;
$dat=$dat-1;
$dat=$dat+1;
$comic->[3] = "$yr/$mon/$dat";
print " feature ID = $comic->[2] first = $comic->[3]\n";
$cname = $link;
$cname =~ s/.*com\///;
$fname = cleanupComicFileName($comic->[1]);
$actname = $comic->[1];
$fname =~ s/ //g;
$comic->[3] =~ s/\//, /g;
my $prefname = cleanupPrefName($cname);
if($isEditorial) {
print JSON " {\"class\":\"GoComics.$fname\", \"name\":\"Editorial : $actname\", \"pref\":\"${prefname}Pref\"},\n";
}
else {
print JSON " {\"class\":\"GoComics.$fname\", \"name\":\"$actname\", \"pref\":\"${prefname}Pref\"},\n";
}
open CFILE, ">${fname}.java";
print CFILE "package com.blogspot.applications4android.comicreader.comics.GoComics;
import java.util.Calendar;
import com.blogspot.applications4android.comicreader.comictypes.DailyGoComicsCom;
public class $fname extends DailyGoComicsCom {
public $fname() {
super();
mComicName = \"$cname\";
mFirstCal = Calendar.getInstance();
mFirstCal.set($comic->[3]);
}
}
";
close CFILE;
}
print "Storing all comics' info...\n";
open(ID, ">$allcomics") or die("Failed to open '$allcomics' for writing!");
print ID Dumper(\@comicslist);
close(ID);
close JSON;
print "Cleaning up...\n";
system("rm -f $mainpage $temp_file_comic");