Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import pika
  3.  
  4.  
  5. def doQuery( conn, i ) :
  6. cur = conn.cursor()
  7.  
  8. cur.execute("SELECT * FROM table OFFSET %s LIMIT 100000", (i,))
  9.  
  10.  
  11. return cur.fetchall()
  12.  
  13.  
  14. print "Using psycopg2"
  15. import psycopg2
  16. myConnection = psycopg2.connect( host=hostname, user=username,
  17. password=password, dbname=database )
  18.  
  19. connection =
  20. pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
  21. channel = connection.channel()
  22.  
  23. channel.queue_declare(queue='task_queue2')
  24.  
  25. endloop = False
  26. i = 1
  27. while True:
  28.  
  29. results = doQuery( myConnection, i )
  30.  
  31.  
  32.  
  33. j = 0
  34. while j < 10000:
  35.  
  36. try:
  37. results[j][-1]
  38. except:
  39. endloop = True
  40. break
  41.  
  42.  
  43. message = str(results[j][-1]).encode("hex")
  44.  
  45. channel.basic_publish(exchange='',
  46. routing_key='task_queue2',
  47. body=message
  48. #properties=pika.BasicProperties(
  49. #delivery_mode = 2, # make message persistent
  50. )#)
  51.  
  52.  
  53.  
  54. j = j + 1
  55.  
  56. # if i % 10000 == 0:
  57. # print i
  58.  
  59. if endloop == False:
  60. break
  61.  
  62. i = i + 10000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement