Skip to content

Commit

Permalink
Fixed a few bugs with choosing what to download.
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleplusc committed Jan 1, 2016
1 parent 6aa804b commit b1ecb9a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions sticker-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def main():
pack_id = int(input("Enter the sticker pack ID: "))
pack_url = "http://dl.stickershop.line.naver.jp/products/0/0/1/{}/android/productInfo.meta".format(pack_id)
pack_meta = get_pack_meta(pack_url).text
pack_meta = get_pack_meta(pack_url, pack_id).text



Expand All @@ -31,13 +31,13 @@ def main():


# [3] A less ugly way of checking menu values
menu = {'gif': get_gif, 'png': get_png, 'y': get_png, 'both': [get_gif, get_png]}
print(menu[pack_ext])
menu = {'gif': [get_gif], 'png': [get_png], 'y': [get_png], 'both': [get_gif, get_png]}
if pack_ext in menu:
for choice in menu[pack_ext]:
choice(list_ids, pack_id)
else:
print("Nothing done. Program exiting...")
sys.exit()

print("\nDone! Program exiting...")

Expand Down Expand Up @@ -74,7 +74,7 @@ def get_png(list_ids, pack_id):
f.write(chunk)


def get_pack_meta(pack_url):
def get_pack_meta(pack_url, pack_id):
pack_meta = requests.get(pack_url)

# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Status codes
Expand All @@ -83,13 +83,8 @@ def get_pack_meta(pack_url):

if pack_meta.status_code == 200:
return pack_meta
'''
f = open('dump.txt', 'w+b') # [2] write mode
f.write(pack_meta.content) # [1] UnicodeEncodeError
f.close()
'''
else:
print("{} did not return 200 status code. Program exiting...".format(pack_id))
print("{} did not return 200 status code, possibly invalid sticker ID. Program exiting...".format(pack_id))
sys.exit()


Expand Down

0 comments on commit b1ecb9a

Please sign in to comment.