Small update
[Python-Scripts.git] / MiniScripts / miss-bone.py
blob730c44f1688cba03c4ad627a5e1eb82b07f8282c
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
20 import os
21 import sys
22 import urllib
23 import urllib2
24 import cookielib
25 import StringIO
26 import gzip
27 import time
28 import datetime
29 import argparse
30 import urlparse
32 fakeua = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
33 geturls_cj = cookielib.CookieJar()
34 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(geturls_cj))
35 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"),
36 ("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")]
37 sfcountsub = 0
38 sfcountfull = 0
39 i = 1
40 il = 15
41 while(i < il):
42 print(str(i)+" Reading URL: http://www.emoticonplus.com/miss-bone/page/"+str(i))
43 geturls_text = geturls_opener.open(
44 "http://www.emoticonplus.com/miss-bone/page/"+str(i))
45 if(geturls_text.info().get("Content-Encoding") == "gzip" or geturls_text.info().get("Content-Encoding") == "deflate"):
46 strbuf = StringIO.StringIO(geturls_text.read())
47 gzstrbuf = gzip.GzipFile(fileobj=strbuf)
48 out_text = gzstrbuf.read()[:]
49 if(geturls_text.info().get("Content-Encoding") != "gzip" and geturls_text.info().get("Content-Encoding") != "deflate"):
50 out_text = geturls_text.read()[:]
51 regex_text = re.escape("<a class=\"emoticon-list\" href=\"#\" data=\"")+"(.*?)" + \
52 re.escape("\" im=\"")+"([0-9]+)" + \
53 re.escape("\" category=\"miss-bone\">")
54 post_text = re.findall(regex_text, out_text)
55 isub = 0
56 ilsub = len(post_text)
57 print(str(i)+" Found "+str(ilsub)+" GIF Images.")
58 while(isub < ilsub):
59 getsub2xurls_cj = geturls_cj
60 getsub2xurls_opener = urllib2.build_opener(
61 urllib2.HTTPCookieProcessor(getsub2xurls_cj))
62 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"),
63 ("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")]
64 print(str(i)+","+str(isub+1)+" Start Downloading Image File: " +
65 str(isub+1)+" of "+str(ilsub))
66 print(str(i)+","+str(isub+1)+" Downloading Image: "+post_text[isub][0])
67 getsub2xurls_text = getsub2xurls_opener.open(post_text[isub][0])
68 gif_file_name = os.path.basename(
69 urlparse.urlparse(post_text[isub][0]).path)
70 print(str(i)+","+str(isub+1) +
71 " Finished Downloading Image: "+post_text[isub][0])
72 print(str(i)+","+str(isub+1)+" Saving File: ./"+gif_file_name)
73 gifsf = open("./"+gif_file_name, "wb")
74 gifsf.write(getsub2xurls_text.read())
75 gifsf.close()
76 isub = isub+1
77 sfcountsub = sfcountsub+1
78 print(str(i)+" Downloaded "+str(sfcountsub)+" GIF Images")
79 sfcountfull = sfcountfull+sfcountsub
80 sfcountsub = 0
81 i = i+1
82 print("Downloaded "+str(sfcountfull)+" GIF Images")
83 sfcountfull = 0