Commit f71bc033be771caa15738fdabe313d5cb0504dea

Authored by Daniel Taylor
1 parent e4599a490e
Exists in master and in 1 other branch dan

Had a go at some fixes - producer and consumer all look OK to me now

Showing 4 changed files with 9 additions and 10 deletions   Show diff stats
... ... @@ -3,4 +3,4 @@ rabbitworker:
3 3 volumes:
4 4 - .:/opt/worker
5 5 - ./log:/var/log
6   - command: supervisord -n
7 6 \ No newline at end of file
  7 + command: python3.4 /opt/worker/worker.py
... ...
... ... @@ -5,9 +5,12 @@ def get_hacker_news_top_five():
5 5 page = requests.get('https://news.ycombinator.com/')
6 6 tree = html.fromstring(page.text)
7 7  
8   - headlines = tree.xpath('//td[@class="title"]/a/text()')
9   -
10   - return headlines[1]
  8 + headlines = []
  9 + results = tree.xpath('//td[@class="title"]/a/text()')
  10 + for result in results:
  11 + headlines.append(result.encode("UTF-8"))
  12 +
  13 + return headlines
11 14  
12 15 if __name__ == "__main__":
13 16 print(get_hacker_news_top_five())
14 17 \ No newline at end of file
... ...
... ... @@ -30,12 +30,8 @@ connection = pika.BlockingConnection(pika.ConnectionParameters(
30 30 channel = connection.channel()
31 31 channel.queue_declare(queue='jons_news', durable=True)
32 32  
33   -page = requests.get('https://news.ycombinator.com/')
34   -tree = html.fromstring(page.text)
35   -headlines = tree.xpath('//td[@class="title"]/a/text()')
36   -message = headlines
37   -# # print (get_hacker_news_top_five())
38   -# print ("1")
  33 +headlines = get_hacker_news_top_five()
  34 +
39 35 for headline in headlines:
40 36 message = headline
41 37 channel.basic_publish(exchange='',
... ...