Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have another problem. I am trying to create a class that will convert a dbf file to .csv and .txt then uploads them into my web server. The .sql file is generated properly but the csv file remains empty. please help me.

The main file:

import psql_manager
import os

PMan = psql_manager.psql_man
PMan.in_filedir = "c:/temp/tcode"
PMan.in_database_name = "table"
PMan.in_psql_database_name = "mydata"
PMan.in_table_name = "Main"
PMan.in_database_address = "localhost"
PMan.in_database_port = "5433"
PMan.in_psql_schemaname = "myschema"
PMan.in_database_username = "postgres"
PMan.in_database_password = "bvdock"
PMan.upload()

And the psql_manager module:

import os, sys
import psycopg2
import simpledbf
from simpledbf import Dbf5

(.....)
    def upload_dbf(*self):
        print("\n[Debug] Full Path = ",psql_man.in_filedir + "/" + psql_man.in_database_name + ".dbf\n")

        if not os.path.isfile(psql_man.in_filedir + "/" + psql_man.in_database_name + ".dbf"):
            return 0

        dbf = Dbf5(psql_man.in_filedir + "/" + psql_man.in_database_name + ".dbf")

        dbf.to_textsql(psql_man.in_filedir + "/" +   psql_man.in_database_name + ".sql",
                   psql_man.in_filedir + "/" + psql_man.in_database_name + ".csv",
                   sqltype='postgres',
                   table=psql_man.in_table_name)
        # SQL and CSV Files are generated above

        with open(psql_man.in_filedir + "/" + psql_man.in_database_name + ".sql", 'r') as sql_fhandle:
            mc_filestr = sql_fhandle.read().replace('\copy', 'copy')
            mc_filestr = mc_filestr.replace(psql_man.in_table_name, psql_man.in_psql_schemaname + '.' + psql_man.in_table_name)

        sql_fhandle = open(psql_man.in_filedir + "/" + psql_man.in_database_name + ".sql", 'w')
        sql_fhandle.write(mc_filestr)
        sql_fhandle.close()

        connection = psycopg2.connect(database=psql_man.in_psql_database_name,
                                  user=psql_man.in_database_username,
                                  password=psql_man.in_database_password,
                                  host=psql_man.in_database_address,
                                  port=psql_man.in_database_port)
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.