Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Sat Nov 21 14:29:50 2015
- @author: User
- """
- from bs4 import BeautifulSoup
- import re
- import os
- # theres probably better way
- def innerHtml(element):
- t = []
- for child in element.children:
- t.append('%s' % child)
- return '\n'.join(t)
- home = 'C:/wamp/www/4chan'
- threads = []
- for item in os.listdir(home):
- threadNumber = item
- m = re.match('^[0-9]+$',item)
- if m == None:
- continue
- print threadNumber
- thread = home + "/" + threadNumber + "/index.html"
- f = open(thread,'r')
- html = f.read()
- f.close()
- soup = BeautifulSoup(html, 'html.parser')
- post = soup.find(class_="opContainer")
- postMessage = post.find(class_="postMessage")
- fileThumb = post.find(class_="fileThumb")
- postImage = fileThumb.find('img')
- imgStyle = postImage.get('style')
- w = re.search('width: ([0-9]+)px',imgStyle)
- h = re.search('height: ([0-9]+)px',imgStyle)
- w = float(w.group(1))
- h = float(h.group(1))
- #print float(w.group(1) + ' ' + h.group(1)
- asp = w / h
- w2 = 150
- h2 = w2 / asp
- newStyle = 'width: %dpx; height: %dpx' % (w2,h2)
- image = '<a href="' + threadNumber + '/index.html"><img src="' + threadNumber + '/' + postImage.get('src') + '" class="thumb" style="'+newStyle+'"/></a>'
- teaser = '<div class="teaser">'+innerHtml(postMessage)+'</div>'
- result = '<div class="thread">' + image + teaser + '</div>'
- threads.append(result)
- #result = topHtml + result + bottomHtml
- dest = home + '/index.html'
- topHtml = '<html><head><link href="https://s.4cdn.org/css/catalog_yotsuba_b_new.635.css" rel="stylesheet" id="base-css" type="text/css"></head><body><div id="threads" class="extended-small">'
- bottomHtml = '</div></body></html>'
- result = topHtml + "\n".join(threads) + bottomHtml
- f = open(dest,'w')
- f.write(result)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement