Guest User

Untitled

a guest
Dec 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import MySQLdb
  3. import csv
  4. #informations about the database
  5. MYSQL_HOST="padam"
  6. MYSQL_USER="poumpoum"
  7. MYSQL_PASS="!WTF!"
  8. MYSQL_DB="biz_biz"
  9.  
  10.  
  11. def change_date(filename,filename2):
  12. db = MySQLdb.connect(host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASS, db=MYSQL_DB)
  13. cur = db.cursor()
  14. #first we select everything we need
  15. query = """SELECT pis.start_date,pis.end_date,pi.web_user_id, pi.invoice_id FROM payment_invoices_subscriptions pis JOIN payment_invoices pi ON pis.invoice_id = pi.invoice_id
  16. WHERE pi.operation_date = "2011-06-02 00:00:00" AND
  17. pi.operation_type = 4;
  18. """
  19. record_dump = csv.writer(
  20. open(filename,'w'),delimiter=';')
  21.  
  22. cur.execute(query)
  23. rows = cur.fetchall()
  24. #write our csv
  25. for row in rows :
  26. record_dump.writerow([elem for elem in row])
  27.  
  28. #3...2...1 ingnition :
  29. query2 = """ UPDATE payment_invoices_subscriptions pis JOIN payment_invoices pi ON pis.invoice_id = pi.invoice_id
  30. SET pis.start_date = "2011-06-01 00:00:00",pis.end_date = "2011-07-01 00:00:00"
  31. WHERE pi.operation_date = "2011-06-02 00:00:00" AND pi.operation_type = 4;"""
  32.  
  33. #on allume un cierge
  34. cur.execute(query2)
  35.  
  36. ###############NOW LET'S GO FOR payment_invoices################################
  37.  
  38. query3 = """ SELECT pi.web_user_id,pi.invoice_id FROM payment_invoices pi WHERE
  39. pi.operation_date = "2011-06-02 00:00:00" AND pi.operation_type = 4;"""
  40.  
  41. record_dump2 = csv.writer(
  42. open(filename2,'w'),delimiter=';'
  43. )
  44. cur.execute(query3)
  45. rows = cur.fetchall()
  46. #write our csv
  47. for row in rows :
  48. record_dump2.writerow([elem for elem in row])
  49.  
  50. #3 ... 2...1 ignition
  51. query4 = """UPDATE payment_invoices pi SET pi.operation_date = "2011-06-01 00:00:00", pi.payment_date = "2011-06-01 00:00:00"
  52. WHERE pi.operation_date = "2011-06-02 00:00:00" AND pi.operation_type = 4;"""
  53.  
  54. #on sacrifie un poulet
  55. cur.execute(query4)
  56. changed = change_date('date_changed_on_pis.csv','date_changed_on_pi.csv')
  57.  
  58. ####ensuite, on compte le nombre de ligne dans le premier et le second fichier
  59. ####si celui ci n'est pas identique, on est mal ...
Add Comment
Please, Sign In to add comment