0% found this document useful (0 votes)
9 views1 page

Mysql 2 Csvall

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Mysql 2 Csvall

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#!

/usr/bin/env python
#juliver_sihombing@[Link]
#14-02-2014
#---------------

import sys
import os
import datetime
from ipserver import IPNYA
import csv
import MySQLdb

#set penamaan file (format Victoria_(Day-1).csv)


now=[Link]()
now -= [Link](days=1)
tTime=[Link]("%Y%m%d%H")
FILENAME="/home/data/chiken_crush_" + tTime + ".csv"

#set konfigurasi database


#hostname="[Link]"
dbuser="dinas"
dbpass="dinas123"
dbname="db_cc_jambi"

#set Query String


#SELECTQ="select pscd,trdt,trno,rvnamt,svchgamt,taxamt from iafjrndt where
active='1' and svchgamt>'0' and taxamt>'0' and date(trdt)=curdate() - interval 1
day order by pscd"
SELECTQ="select id_nota,no_faktur,tanggal,input_date,subtotal,diskon,pajakppn,total
from penjualan where id_jenis IN ('K','T','G') and date(input_date)between
date_sub(curdate(),interval 31 day) and curdate()"
# where date(tgl)>=curdate() - interval 1 day order by tgl asc"
#SELECTQ="select * from device"

#open connection to database


db = [Link](host=IPNYA, user=dbuser, passwd=dbpass, db=dbname, port=3306)

#prepare csv file


dump_writer = [Link](open(FILENAME,'w'), delimiter=',',quotechar="'")
cursor = [Link]()
#execute query, fetching data row
[Link](SELECTQ)
result = [Link]()

#get column names


field_names = [i[0] for i in [Link]]
dump_writer.writerow(field_names)
#dump to csv
#data = [row[0] for row in [Link]()]
for record in result:
dump_writer.writerow(record)

#close connection
[Link]()

You might also like