Fix the list of banners we select from.

This commit is contained in:
ccd0 2014-10-07 10:13:15 -07:00
parent a97a358f1f
commit 84088259a5
3 changed files with 23 additions and 10 deletions

View File

@ -1,4 +1,6 @@
Banner =
banners: `<%= JSON.stringify(grunt.file.readJSON('src/Miscellaneous/banners.json')) %>`
init: ->
$.asap (-> d.body), ->
$.asap (-> $ 'hr'), Banner.ready
@ -35,16 +37,9 @@ Banner =
d.title = title
cb:
toggle: do ->
types =
jpg: 227
png: 270
gif: 253
->
type = Object.keys(types)[Math.floor 3 * Math.random()]
num = Math.floor types[type] * Math.random()
$('img', @parentNode).src = "//s.4cdn.org/image/title/#{num}.#{type}"
toggle: ->
banner = Banner.banners[Math.floor(Banner.banners.length * Math.random())]
$('img', @parentNode).src = "//s.4cdn.org/image/title/#{banner}"
click: (e) ->
if e.ctrlKey

File diff suppressed because one or more lines are too long

17
tools/banners.py Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
import urllib.request, urllib.error, json
banners = []
for ext in ['jpg', 'png', 'gif']:
for i in range(300):
banner = str(i) + '.' + ext
req = urllib.request.Request('http://s.4cdn.org/image/title/' + banner, method='HEAD')
try:
status = urllib.request.urlopen(req).status
except urllib.error.HTTPError as e:
status = e.status
print(banner, status)
if status == 200:
banners.append(banner)
with open('src/Miscellaneous/banners.json', 'w') as f:
f.write(json.dumps(banners))