forked from xdtianyu/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cache/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#Sticker | ||
|
||
```shell | ||
pip3 install -r requirements.txt | ||
``` | ||
|
||
## Usage | ||
|
||
```shell | ||
./sticker.py https://store.line.me/stickershop/product/1271679/en | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lxml == 3.5.0 | ||
requests == 2.9.1 | ||
urllib3 == 1.13.1 | ||
Pillow == 3.3.1 | ||
beautifulsoup4 == 4.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import urllib.request | ||
from PIL import Image | ||
|
||
import requests | ||
from urllib3.exceptions import HTTPError | ||
|
||
|
||
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/50.0.2661.75 Safari/537.36' | ||
|
||
header = {'User-Agent': user_agent} | ||
|
||
cache_dir = 'cache/' | ||
|
||
|
||
def fetch(url, headers, cookies): | ||
print('fetch: ' + url) | ||
|
||
r = requests.get(url, headers=headers, cookies=cookies) | ||
from bs4 import BeautifulSoup | ||
import lxml | ||
|
||
bs = BeautifulSoup(r.text, lxml.__name__) | ||
|
||
name = bs.find('title').text.split(' -')[0] | ||
|
||
print('name: ' + name) | ||
|
||
import re | ||
|
||
spans = bs.find_all('span', style=re.compile('129px;')) | ||
|
||
for span in spans: | ||
link = re.match('.*(https.*png)', span.get('style')).group(1) | ||
download(name, link) | ||
|
||
if spans: | ||
pass | ||
else: | ||
print('Error html content!') | ||
print(r.text) | ||
|
||
|
||
def download(dir_name, url): | ||
print('download: ' + url) | ||
|
||
if not os.path.exists(cache_dir + dir_name): | ||
os.makedirs(cache_dir + dir_name) | ||
|
||
res = None | ||
try: | ||
res = urllib.request.urlopen(url) | ||
except HTTPError: | ||
print('download error.') | ||
|
||
file_name = url.split('/')[-1] | ||
|
||
path = cache_dir + dir_name + '/' + file_name | ||
|
||
with open(path, 'b+w') as f: | ||
f.write(res.read()) | ||
|
||
scale(path) | ||
|
||
|
||
def scale(file): | ||
print('scale: ' + file) | ||
img = Image.open(file) | ||
width = 512 | ||
p = (width / float(img.size[0])) | ||
height = int((float(img.size[1]) * float(p))) | ||
img.resize((width, height), Image.CUBIC).save(file.split('.')[0]+"_big.png") | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
|
||
if len(sys.argv) > 1 and sys.argv[1]: | ||
fetch(sys.argv[1], header, {}) | ||
else: | ||
print('Error parameter.') | ||
|
||
|
||
|