4 ms·
I'm studying Spanish, so I made a little script that fetches Calvin & hobbes cartoons in both Spanish and English and then converts each strip into bilingual st
by vfinn 6y ago
I'm studying Spanish, so I made a little script that fetches Calvin & hobbes cartoons in both Spanish and English and then converts each strip into bilingual strip with ImageMagick. It works well enough (>99%).
#!/bin/bash
for i in {1..1000}; do x=$(date +'%Y/%m/%d' -d "$i days ago");
z=$(date +'%Y-%m-%d' -d "$i days ago");
wget https://www.gocomics.com/calvinandhobbesespanol/$x -O $z-es;
wget https://www.gocomics.com/calvinandhobbes/$x -O $z-en;
y=$(cat $z-es | grep -o -P '.{0}https://assets.amuniversal.com.{0,33}' | tail -1);
f=$(cat $z-en | grep -o -P '.{0}https://assets.amuniversal.com.{0,33}' | tail -1);
wget $y -O $z-es.gif; rm $z-en; sleep 1;
wget $f -O $z-en.gif; rm $z-es; sleep 1;
convert $z-en.gif $z-es.gif -append $z-bi.gif; #ImageMagick
rm $z-es.gif;
rm $z-en.gif;
done;
- lifeisstillgood 6y agoThat's awesome. Seriously make this a company -see how it goes :-)
- vfinn 6y agoThank you. You're most kind. I have many business ideas already, but I'll think about it.
- joshspankit 6y agoHow about just a web front-end that lets people upload other comics?
- vfinn 6y agoYeah, why not. I didn't give it much thought. This script makes some assumptions about the site structure, that's why it's able to be so short. Of course if you were able to get the image links without grepping, then it would be even easier.
- justjonathan 6y agoTried do this on a mac. I had to replace gnu grep with perl: perl -wnle '/(.{0}https://assets.amuniversal.com.{0,33})/ and print $1' I had to replace wget with curl: curl -s https://www.gocomics.com/calvinandhobbesespanol/$x -o $z-es; Then I realized I need gnu date, which had to come as part of coreutils: brew install coreutils So date becomes gdate for i in {1..1000}; do x=$(gdate +'%Y/%m/%d' -d "$i days ago"); z=$(gdate +'%Y-%m-%d' -d "$i days ago"); Hope I din't break other stuff with that. Now it still doesn't work, but I'm giving up, hopefully I saved a little time for somebody...
- vfinn 6y agoAnd you have ImageMagick also installed?
- justjonathan 6y agoI do
- vfinn 6y agoWell, it should be pretty straightforward to first check whether the loop is working at all and then step-by-step echo the variables for example to see what's missing.
- erk__ 6y agoA bit unrelated, but I have been working on a bot that fetches comics mostly Garfield from go comics, and the 32 char url you get back does not seem random, but I have not yet been able to figure out how it is formed.
- vfinn 6y agoI was gonna say you're nuts, but it seems there's a some kind of pattern, so sorry about that :D. These are the filenames for three different Calvin & Hobbes cartoons from Feb 8 to Feb 10. 24 hex similarity, so... you need to reverse 32 bits? 145afe502d7601393f0c005056a9545d.jpg 126fdbc02d7601393f0c005056a9545d.jpg 163e6fa02d7601393f0c005056a9545d.jpg It could be some kind of combined hash for date + comic + service.