v/pol
1
0
mirror of https://github.com/taroved/pol synced 2025-05-21 00:20:22 -07:00

link detect in progress

This commit is contained in:
Alexandr Nesterenko 2016-07-17 11:26:13 -07:00
parent 964b3e70d2
commit 3f2c9f6624
3 changed files with 18 additions and 5 deletions

13
feed.py
View File

@ -46,6 +46,10 @@ def element_to_string(element):
s.append(element.tail)
return ''.join(s)
def _build_link(doclink, link):
# todo
return link
def _buildFeed(response, feed_config):
tree = response.selector._root.getroottree()
@ -58,6 +62,13 @@ def _buildFeed(response, feed_config):
element = node.xpath(feed_config['fields'][field_name])
if element:
item[field_name] = element_to_string(element[0])
# get item link
if field_name == 'title':
anchor = element[0].xpath('ancestor-or-self::node()[name()="a"]')
if anchor and anchor[0].get('href'):
item['title_link'] = _build_link(feed_config['uri'], anchor[0].get('href'))
if len(item) == len(feed_config['fields']): # all fields are required
items.append(item)
@ -73,7 +84,7 @@ def _buildFeed(response, feed_config):
for item in items:
feed.add_item(
title=item['title'] if 'title' in item else '',
link=feed_config['uri'],
link = item['title_link'] if 'title_link' in item else feed_config['uri'],
description=item['description'] if 'description' in item else '',
#enclosure=Enclosure(fields[4], "32000", "image/jpeg") if 4 in fields else None, #"Image"
pubdate=datetime.datetime.now()

View File

@ -51,11 +51,9 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
{% if index_page %}
{% block logo %}
<a href="{% url 'index' %}" class="brand-pic"><img src="{% static 'frontend/images/apple-touch-icon-precomposed.png' %}" width="40" height="40" /></a>
{% else %}
<a href="{% url 'index' %}" class="brand">{% trans "brand" %}</a>
{% endif %}
{% endblock %}
<div class="container-fluid nav-collapse">
<ul class="nav pull-right">

View File

@ -2,6 +2,10 @@
{% load staticfiles %}
{% load i18n %}
{% block logo %}
<a href="{% url 'index' %}" class="brand">{% trans "brand" %}</a>
{% endblock %}
{% block content %}
<div class="welcom">
<img src="{% static 'frontend/images/pol.png' %}" alt="Hi!" />