49def response(resp):
50 results = []
51 dom = html.fromstring(resp.text)
52 results_dom = dom.xpath('//li[contains(@class, "video-listing-entry")]')
53
54 if not results_dom:
55 return []
56
57 for result_dom in results_dom:
58 url = base_url + extract_text(result_dom.xpath(url_xpath))
59 thumbnail = extract_text(result_dom.xpath(thumbnail_xpath))
60 title = extract_text(result_dom.xpath(title_xpath))
61 p_date = extract_text(result_dom.xpath(published_date))
62
63 fixed_date = datetime.strptime(p_date, '%Y-%m-%dT%H:%M:%S%z')
64 earned = extract_text(result_dom.xpath(earned_xpath))
65 views = extract_text(result_dom.xpath(views_xpath))
66 rumbles = extract_text(result_dom.xpath(rumbles_xpath))
67 author = extract_text(result_dom.xpath(author_xpath))
68 length = extract_text(result_dom.xpath(length_xpath))
69 if earned:
70 content = f"{views} views - {rumbles} rumbles - ${earned}"
71 else:
72 content = f"{views} views - {rumbles} rumbles"
73
74 results.append(
75 {
76 'url': url,
77 'title': title,
78 'content': content,
79 'author': author,
80 'length': length,
81 'template': 'videos.html',
82 'publishedDate': fixed_date,
83 'thumbnail': thumbnail,
84 }
85 )
86 return results