initial commit

This commit is contained in:
xeals 2020-07-08 16:10:14 +10:00
commit 75d05f8f4a
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C
3 changed files with 75 additions and 0 deletions

58
fetch.py Normal file
View 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
View 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

10
shell.nix Normal file
View File

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = pkgs.lib.singleton
(pkgs.python3.withPackages (ppkgs: with ppkgs; [
beautifulsoup4
requests
ipython
]));
}