Commit e4599a490e8037544ae1b1493f4568e42b5439d5

Authored by Jonathan Wilson
1 parent 34cbb5ad44
Exists in master and in 1 other branch dan

sending multiple headlines using for loop

Showing 1 changed file with 12 additions and 12 deletions   Show diff stats
... ... @@ -30,18 +30,18 @@ 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 = 'string' #headlines[1]
37   -# print (message)
  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
38 37 # # print (get_hacker_news_top_five())
39 38 # print ("1")
40   -
41   -channel.basic_publish(exchange='',
42   - routing_key='jons_news',
43   - body=message,
44   - properties=pika.BasicProperties(
45   - delivery_mode = 2, # Make message persistent
46   - ))
  39 +for headline in headlines:
  40 + message = headline
  41 + channel.basic_publish(exchange='',
  42 + routing_key='jons_news',
  43 + body=message,
  44 + properties=pika.BasicProperties(
  45 + delivery_mode = 2, # Make message persistent
  46 + ))
47 47 logging.debug("Published: {0}".format(message))
... ...