Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Python implementation of https://gist.github.com/jleclanche/9533710 by jleclanche

View blizznotes.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#!/usr/bin/env python2
 
# Python implementation of https://gist.github.com/jleclanche/9533710 by jleclanche
# Implemented by allenskd ( https://gist.github.com/allenskd )
 
# Instructions
# -----------------
# Install html2text using pip or python-pip your distribution repository
#
# Usage
# -----------------
# ./blizznotes.py
# To get WoW notes ./blizznotes.py -n wow
# To get beta WoW patch notes ./blizznotes.py -n wow -t beta
# More options
# ./blizznotes.py --help
 
# Extra Notes
# If you want to use an alias on it
# Open your ~/.profile
# Add at the end:
# alias patchnotes="python PATH_TO_SCRIPT/blizznotes.py"
# source ~/.profile
# Now you can call it with:
# patchnotes -n wow -t live
 
import optparse
import urllib2
import html2text
# saving myself some headaches
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
 
user_agent = {"User-Agent": "Battle.net/1.0.8.4217"}
base_url = "https://us.battle.net/connect/en/app"
note_options = ['all','wow','s2','d3','wtcg']
type_options = ['live','ptr','beta']
build_uri = "{0}/{1}/patch-notes?productType={2}"
 
def get_patchnotes(uri):
request = urllib2.Request(uri, None, user_agent)
resp = urllib2.urlopen(request)
html = resp.read()
html.decode('utf-8')
if html.strip() == '':
html = "No patch notes found"
return html
 
def init():
parser = optparse.OptionParser()
parser.add_option('--notes','-n', default="all",help="returns the patch notes of the following Blizzard games\nyou can use: all | wow | s2 | d3 | wtcg")
parser.add_option('--type','-t', default="live", help="product type: live | ptr | beta")
opts, args = parser.parse_args()
if opts.notes:
if opts.notes not in note_options:
print "Sorry, I don't know which game is that :(. Your input was: %s" % opts.notes
return
if opts.type not in type_options:
print "That type doesn't exist. Your input was: %s" % opts.type
return
if opts.notes == 'all':
for notes in note_options:
if notes == 'all':
continue
#print '========= %s =========' % notes
#print build_uri.format(base_url, notes, opts.type)
print html2text.html2text(get_patchnotes(build_uri.format(base_url, notes, opts.type)))
return
 
print html2text.html2text(get_patchnotes(build_uri.format(base_url, opts.notes, opts.type)))
 
 
if __name__ == '__main__':
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.