basichttp server (забыл git add .)
[chanspy.git] / daemon.shit / plugins / wakaba_thread.py
blob021079d895ef6c74178a81256a74650bcb0ef0be
1 import dbus.service
3 from my_thread import Thread
4 from post import Post
6 import urllib
7 import re
9 INTERFACE = 'py.chans.dbus'
11 class WakabaThread(Thread):
13 def __init__(self, bus_name, obj_path, board, id):
14 Thread.__init__(self, bus_name, obj_path, board, id)
16 #TODO: _normal_ parsing needs
17 @dbus.service.method(dbus_interface=INTERFACE, in_signature='', out_signature='')
18 def refresh(self):
19 def get_posts_dicts():
20 def parse_msg_table(post_data):
21 post = {}
22 post['id'] = re.findall('<a name="([0-9]+)">', post_data)[0]
23 post['date'] = ''
24 post['name'] = ''
25 post['title'] = ''
26 post['is_sage'] = ''
27 img_src = re.findall('<a target="_blank" href="(.*?)">', post_data)
28 if img_src:
29 post['img_src'] = img_src[0]
30 else:
31 post['img_src'] = ''
32 post['text'] = re.findall('<blockquote>(.*?)</blockquote>', post_data)[0]
33 return post
35 def get_msg_tables(data):
36 return re.findall('<table><tbody><tr><td class="doubledash">(.*?)</td></tr></tbody></table>', data)
38 data = urllib.urlopen('%s/%s/res/%s.html' %(self.board.base_uri, self.board.name, self.id)).read()
40 first_post = re.findall('(<div id="thread-.*?</blockquote>)', data)[0]
41 posts = [parse_msg_table(first_post)]
42 for msg_table in get_msg_tables(data):
43 posts.append(parse_msg_table(msg_table))
44 return posts
46 self.posts = []
47 posts_dicts = get_posts_dicts()
48 for post_dict in posts_dicts:
49 self.posts.append( Post(bus_name=self.bus_name, obj_path=self.obj_path +'/'+ post_dict['id'], post=post_dict) )