Small bug.
[Python-Scripts.git] / MiniScripts / miss-bone.py
blobef9d2503fef5329ec68cdf534c152193c68b0577
1 #!/usr/bin/env python
3 '''
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2014 Cool Dude 2k - http://idb.berlios.de/
13 Copyright 2014 Game Maker 2k - http://intdb.sourceforge.net/
14 Copyright 2014 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: miss-bone.py - Last Update: 6/12/2014 Ver. 1.0.0 RC 2 - Author: cooldude2k $
17 '''
19 import re, os, sys, urllib, urllib2, cookielib, StringIO, gzip, time, datetime, argparse, urlparse;
21 fakeua = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0";
22 geturls_cj = cookielib.CookieJar();
23 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(geturls_cj));
24 geturls_opener.addheaders = [("Referer", "http://www.emoticonplus.com/miss-bone/"), ("User-Agent", fakeua), ("Accept-Encoding", "gzip, deflate"), ("Accept-Language", "en-US,en-CA,en-GB,en-UK,en-AU,en-NZ,en-ZA,en;q=0.5"), ("Accept-Charset", "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7"), ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), ("Connection", "close")];
25 sfcountsub=0;
26 sfcountfull=0;
27 i = 1;
28 il = 15;
29 while(i < il):
30 print(str(i)+" Reading URL: http://www.emoticonplus.com/miss-bone/page/"+str(i));
31 geturls_text = geturls_opener.open("http://www.emoticonplus.com/miss-bone/page/"+str(i));
32 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
33 strbuf = StringIO.StringIO(geturls_text.read());
34 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
35 out_text = gzstrbuf.read()[:];
36 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
37 out_text = geturls_text.read()[:];
38 regex_text = re.escape("<a class=\"emoticon-list\" href=\"#\" data=\"")+"(.*?)"+re.escape("\" im=\"")+"([0-9]+)"+re.escape("\" category=\"miss-bone\">");
39 post_text = re.findall(regex_text, out_text);
40 isub=0;
41 ilsub=len(post_text);
42 print(str(i)+" Found "+str(ilsub)+" GIF Images.");
43 while(isub < ilsub):
44 getsub2xurls_cj = geturls_cj;
45 getsub2xurls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(getsub2xurls_cj));
46 getsub2xurls_opener.addheaders = [("Referer", "http://www.emoticonplus.com/miss-bone/page/"+str(i)), ("User-Agent", fakeua), ("Accept-Encoding", "gzip, deflate"), ("Accept-Language", "en-US,en-CA,en-GB,en-UK,en-AU,en-NZ,en-ZA,en;q=0.5"), ("Accept-Charset", "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7"), ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), ("Connection", "close")];
47 print(str(i)+","+str(isub+1)+" Start Downloading Image File: "+str(isub+1)+" of "+str(ilsub));
48 print(str(i)+","+str(isub+1)+" Downloading Image: "+post_text[isub][0]);
49 getsub2xurls_text = getsub2xurls_opener.open(post_text[isub][0]);
50 gif_file_name = os.path.basename(urlparse.urlparse(post_text[isub][0]).path);
51 print(str(i)+","+str(isub+1)+" Finished Downloading Image: "+post_text[isub][0]);
52 print(str(i)+","+str(isub+1)+" Saving File: ./"+gif_file_name);
53 gifsf = open("./"+gif_file_name, "wb");
54 gifsf.write(getsub2xurls_text.read());
55 gifsf.close();
56 isub=isub+1;
57 sfcountsub=sfcountsub+1;
58 print(str(i)+" Downloaded "+str(sfcountsub)+" GIF Images");
59 sfcountfull=sfcountfull+sfcountsub;
60 sfcountsub=0;
61 i=i+1;
62 print("Downloaded "+str(sfcountfull)+" GIF Images");
63 sfcountfull=0;