commit bce67314945c5f7a04daba51724d077b3e2e6792 Author: Alexander Popov Date: Fri Oct 28 00:29:36 2016 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9facd35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pip +*.jpg diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..cf1ab25 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/images/.stanis-tits.latest b/images/.stanis-tits.latest new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/images/.stanis-tits.latest @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..efa6710 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.11.1 +beautifulsoup4==4.5.1 diff --git a/stanis-tits.py b/stanis-tits.py new file mode 100644 index 0000000..b507597 --- /dev/null +++ b/stanis-tits.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append('./.pip') +import requests +from bs4 import BeautifulSoup +import re +import shutil +import os.path + +__author__ = 'Alexander Popov' +__version__ = '0.0.1' +__license__ = 'Unlicense' + +IMAGES_DIR = './images' +COOKIES = dict(block='951') +URL = 'http://blog.stanis.ru/?back=%d' +PAGE = 0 +with open('%s/.stanis-tits.latest' % IMAGES_DIR, 'r') as f: + LATEST_FILE = f.read() +STOP = False +NEXT_LATEST = None + +while STOP == False: + print('Loading page %d' % PAGE) + + r = requests.get(URL % PAGE, cookies=COOKIES) + + + soup = BeautifulSoup(r.text.encode('cp1251'), + "html.parser", from_encoding="windows-1251") + images = soup.findAll('img', src=re.compile('img/*')) + + for image in images: + if int(image['src'].split('/')[1].split('.')[0]) == int(LATEST_FILE): + STOP = True + + if PAGE == 0: + if NEXT_LATEST == None: + NEXT_LATEST = str(image['src'].split('/')[1].split('.')[0]) + with open('%s/.stanis-tits.latest' % IMAGES_DIR, 'w+') as f: + f.write(NEXT_LATEST) + + if not os.path.exists('%s/%s' % (IMAGES_DIR, image['src'].split('/')[1],)): + print('\tDownload %s' % image['src'].split('/')[1]) + response = requests.get('http://blog.stanis.ru/%s' % image['src'], stream=True) + + with open('%s/%s' % (IMAGES_DIR, image['src'].split('/')[1]), 'wb') as out_image: + shutil.copyfileobj(response.raw, out_image,) + + PAGE += 1 +