initial commit
This commit is contained in:
commit
75d05f8f4a
58
fetch.py
Normal file
58
fetch.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
|
|
||||||
|
args = sys.argv[1:]
|
||||||
|
|
||||||
|
pack = args[0]
|
||||||
|
print(f'fetching pack {pack}')
|
||||||
|
|
||||||
|
try:
|
||||||
|
pack = int(pack)
|
||||||
|
packurl = f'https://store.line.me/stickershop/product/{pack}/en'
|
||||||
|
except ValueError:
|
||||||
|
packurl = pack
|
||||||
|
|
||||||
|
try:
|
||||||
|
res = requests.get(packurl)
|
||||||
|
except:
|
||||||
|
print('> failed:')
|
||||||
|
print(res.contenf)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(res.text, 'html.parser')
|
||||||
|
title = soup.title.text.replace(' – LINE stickers | LINE STORE','')
|
||||||
|
author = soup.find('a', class_='mdCMN38Item01Author')
|
||||||
|
print(f'> {title}')
|
||||||
|
print(f'> {author.text}')
|
||||||
|
os.mkdir(title)
|
||||||
|
stickers = soup.find_all('li', class_='mdCMN09Li')
|
||||||
|
|
||||||
|
def progress(cur, total, fname):
|
||||||
|
if cur == total:
|
||||||
|
end = '\n'
|
||||||
|
else:
|
||||||
|
end = ''
|
||||||
|
print(f'\r[{cur}/{total}] {fname}', end=end)
|
||||||
|
|
||||||
|
print(f'fetching {len(stickers)} stickers')
|
||||||
|
total = len(stickers)
|
||||||
|
for i, sticker in enumerate(stickers):
|
||||||
|
j = json.loads(sticker['data-preview'])
|
||||||
|
id = j['id']
|
||||||
|
url = j['staticUrl'].replace(';compress=true','')
|
||||||
|
|
||||||
|
progress(i+1, total, id)
|
||||||
|
img = requests.get(url)
|
||||||
|
|
||||||
|
if img.ok:
|
||||||
|
fname = id + '.png'
|
||||||
|
out = os.path.join(title, fname)
|
||||||
|
with open(out, 'wb') as f:
|
||||||
|
f.write(img.content)
|
||||||
|
else:
|
||||||
|
print('>> failed: {img.content}')
|
7
fetch.sh
Executable file
7
fetch.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
if nix-shell --version 2>&1 >/dev/null ; then
|
||||||
|
nix-shell --command "python ./fetch.py $@"
|
||||||
|
else
|
||||||
|
python ./fetch.py "$@"
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user