Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import MySQLdb
- import csv
- #informations about the database
- MYSQL_HOST="padam"
- MYSQL_USER="poumpoum"
- MYSQL_PASS="!WTF!"
- MYSQL_DB="biz_biz"
- def change_date(filename,filename2):
- db = MySQLdb.connect(host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASS, db=MYSQL_DB)
- cur = db.cursor()
- #first we select everything we need
- 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
- WHERE pi.operation_date = "2011-06-02 00:00:00" AND
- pi.operation_type = 4;
- """
- record_dump = csv.writer(
- open(filename,'w'),delimiter=';')
- cur.execute(query)
- rows = cur.fetchall()
- #write our csv
- for row in rows :
- record_dump.writerow([elem for elem in row])
- #3...2...1 ingnition :
- query2 = """ UPDATE payment_invoices_subscriptions pis JOIN payment_invoices pi ON pis.invoice_id = pi.invoice_id
- SET pis.start_date = "2011-06-01 00:00:00",pis.end_date = "2011-07-01 00:00:00"
- WHERE pi.operation_date = "2011-06-02 00:00:00" AND pi.operation_type = 4;"""
- #on allume un cierge
- cur.execute(query2)
- ###############NOW LET'S GO FOR payment_invoices################################
- query3 = """ SELECT pi.web_user_id,pi.invoice_id FROM payment_invoices pi WHERE
- pi.operation_date = "2011-06-02 00:00:00" AND pi.operation_type = 4;"""
- record_dump2 = csv.writer(
- open(filename2,'w'),delimiter=';'
- )
- cur.execute(query3)
- rows = cur.fetchall()
- #write our csv
- for row in rows :
- record_dump2.writerow([elem for elem in row])
- #3 ... 2...1 ignition
- query4 = """UPDATE payment_invoices pi SET pi.operation_date = "2011-06-01 00:00:00", pi.payment_date = "2011-06-01 00:00:00"
- WHERE pi.operation_date = "2011-06-02 00:00:00" AND pi.operation_type = 4;"""
- #on sacrifie un poulet
- cur.execute(query4)
- changed = change_date('date_changed_on_pis.csv','date_changed_on_pi.csv')
- ####ensuite, on compte le nombre de ligne dans le premier et le second fichier
- ####si celui ci n'est pas identique, on est mal ...
Add Comment
Please, Sign In to add comment