Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
64
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/python2.4
  2.  
  3.  
  4. import psycopg2
  5. import os
  6. import time
  7. from multiprocessing import *
  8. from sshtunnel import *
  9. import MySQLdb
  10.  
  11. remote_host='ahost'
  12. port=50000
  13. remote_ssh_port=5434
  14. remote_bind_port=5432
  15. username='ausername'
  16.  
  17. with SSHTunnelForwarder((remote_host, remote_ssh_port),ssh_username=username, ssh_pkey='/home/conoadmin/.ssh/id_dsa', remote_bind_address = ('localhost', remote_bind_port), local_bind_address = ('localhost', port)):
  18. pg_conn = psycopg2.connect("dbname='adb' user='auser' host='localhost' port=50000 password='apasswd'")
  19. pg_cur = pg_conn.cursor()
  20. pg_cur.execute('select start from "Data" LIMIT 1;')
  21. liste = pg_cur.fetchall()
  22. pg_cur.close()
  23.  
  24. print(liste)
  25.  
  26.  
  27. mysql_conn = MySQLdb.connect(host='localhost',
  28. user='user',
  29. passwd='password',
  30. db='test')
  31.  
  32. mysql_cur = mysql_conn.cursor()
  33.  
  34. for item in liste:
  35. mysql_cur.execute('INSERT IGNORE INTO postdatum(zeit)' 'VALUES(%s)', item)
  36.  
  37. mysql_conn.commit()
  38. mysql_cur.close()
  39.  
  40. [(datetime.datetime(2016, 1, 23, 20, 48, 3),)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement