35
by Jaap Broekhuizen
Started working on xml parsing class |
1 |
#!/usr/bin/env python
|
2 |
||
3 |
# t00mblr - a GTK tumblr client
|
|
4 |
# By: Jaap Broekhuizen <jaapz.b@gmail.com>
|
|
5 |
# Website: blog.jaapz.nl
|
|
6 |
#
|
|
7 |
# License:
|
|
8 |
# This file is part of t00mblr.
|
|
9 |
#
|
|
10 |
# t00mblr is free software: you can redistribute it and/or modify
|
|
11 |
# it under the terms of the GNU General Public License as published by
|
|
12 |
# the Free Software Foundation, either version 3 of the License, or
|
|
13 |
# (at your option) any later version.
|
|
14 |
#
|
|
15 |
# t00mblr is distributed in the hope that it will be useful,
|
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
# GNU General Public License for more details.
|
|
19 |
#
|
|
20 |
# You should have received a copy of the GNU General Public License
|
|
21 |
# along with t00mblr. If not, see <http://www.gnu.org/licenses/>.
|
|
22 |
||
23 |
'''This renders the tumblr api xml output'''
|
|
24 |
||
25 |
import urllib |
|
36
by Jaap Broekhuizen
Base for xml parsing is now made |
26 |
from lxml import etree |
35
by Jaap Broekhuizen
Started working on xml parsing class |
27 |
|
28 |
from common import d |
|
29 |
||
30 |
class renderer(): |
|
31 |
blog = None |
|
36
by Jaap Broekhuizen
Base for xml parsing is now made |
32 |
parsed_xml = None |
39
by Jaap Broekhuizen
Done some work on renderer |
33 |
template = "./templates/main.tpl" |
35
by Jaap Broekhuizen
Started working on xml parsing class |
34 |
|
35 |
def __init__(self, blog): |
|
36 |
"""
|
|
37 |
Renderer main init
|
|
38 |
"""
|
|
39 |
self.blog = blog |
|
40 |
self.get_blog() |
|
41 |
||
42 |
def get_blog(self): |
|
43 |
"""
|
|
44 |
Retrieves the blog xml from the tumblr api
|
|
45 |
"""
|
|
46 |
try: |
|
47 |
stream = urllib.urlopen("http://"+self.blog+".tumblr.com/api/read") |
|
36
by Jaap Broekhuizen
Base for xml parsing is now made |
48 |
xml = stream.read() |
49 |
self.tumblr = etree.fromstring(xml) |
|
35
by Jaap Broekhuizen
Started working on xml parsing class |
50 |
except Exception, e: |
51 |
print e |
|
52 |
return False |
|
39
by Jaap Broekhuizen
Done some work on renderer |
53 |
|
54 |
def parse_blog(self): |
|
36
by Jaap Broekhuizen
Base for xml parsing is now made |
55 |
"""
|
39
by Jaap Broekhuizen
Done some work on renderer |
56 |
Parses the xml into webkit-viewable html
|
36
by Jaap Broekhuizen
Base for xml parsing is now made |
57 |
"""
|
58 |
posts = self.tumblr[1] |
|
39
by Jaap Broekhuizen
Done some work on renderer |
59 |
caption = "" |
60 |
html = "" |
|
36
by Jaap Broekhuizen
Base for xml parsing is now made |
61 |
for post in posts: |
39
by Jaap Broekhuizen
Done some work on renderer |
62 |
caption = post[0].text |
63 |
poster = self.get_poster() |
|
64 |
media = self.get_media() |
|
65 |
#html = self.insert_in_html(poster, caption, media)
|
|
66 |
html += caption # temporary return variable |
|
67 |
return html |
|
68 |
#return html
|
|
69 |
||
70 |
"""
|
|
71 |
TODO:
|
|
72 |
loop through text list
|
|
73 |
print captions into divs
|
|
74 |
get images by captions
|
|
75 |
"""
|
|
76 |
||
77 |
def get_media(self): |
|
78 |
"""
|
|
79 |
Gets the photo, video or audio posted
|
|
80 |
"""
|
|
81 |
pass
|
|
82 |
||
83 |
def get_poster(self): |
|
84 |
"""
|
|
85 |
Gets user name of the poster
|
|
86 |
"""
|
|
87 |
pass
|
|
88 |
||
89 |
def insert_in_html(self, poster, caption, media=None): |
|
90 |
"""
|
|
91 |
Gets all variables and puts them in the html page
|
|
92 |
"""
|
|
93 |
pass
|
|
94 |