Skip to content

Instantly share code, notes, and snippets.

@iidx
Created April 6, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iidx/1e33af6610d5980e15eda867bede3fb7 to your computer and use it in GitHub Desktop.
Save iidx/1e33af6610d5980e15eda867bede3fb7 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import re, json
import urllib2 as u
bmsurl = "http://www.dream-pro.info/~lavalse/LR2IR/search.cgi?mode=ranking&bmsid="
def urlreq(url):
try:
return u.urlopen(u.Request(url)).read()
except Exception as e:
print e
return None
def getbmsids(username):
try:
url = "http://www.dream-pro.info/~lavalse/LR2IR/search.cgi?mode=search&sort=bmsid_desc&keyword={}_sabun&exec=%8C%9F%8D%F5&type=tag".format(username)
stream = urlreq(url)
r = r"<td\swidth=\"20%\"><a\shref=\'search.cgi\?mode=ranking\&bmsid=([\d]+)\'>"
bmsids = re.findall(r, stream)
return bmsids
except Exception as e:
print e
return None
def renderdata(bmsids, title, artists, dllink):
html = ""
for i in range(len(bmsids)):
ir = bmsurl+bmsids[i]
sibal_title = unicode(title[i], 'shift-jis').encode('utf8')
sibal_artist = unicode(artists[i], 'shift-jis').encode('utf8')
html += "<tr><td>{}</td><td>{}</td><td>{}</td><td><a href=\"{}\">DL</a></td><td><a href=\"{}\">IR</a></td></tr>".format(i+1, sibal_title, sibal_artist, dllink[i], ir)
return html
def getsabunlist(username):
bmsids = getbmsids(username)
if bmsids:
title = []
artists = []
dllink = []
for bmsid in bmsids:
stream = urlreq(bmsurl+bmsid)
if stream:
try:
title.append(re.search(r"<h1>(.+)</h1>", stream).group(1))
except Exception as e:
print e
title.append("[Title is Empty!]")
try:
artists.append(re.search(r"<h2>(.+)</h2>", stream).group(1))
except Exception as e:
print e
artists.append("[Artists is Empty!]")
try:
r = r"\x8D\xB7\x95\xAAURL</th><td colspan=\"7\"><a href=\"(.+)\""
result = re.search(r, stream).group(1)
dllink.append(result)
except Exception as e:
print e
dllink.append("#")
try:
html = renderdata(bmsids, title, artists, dllink)
except Exception as e:
print e
return None
return html
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment