コード例 #1
0
ファイル: bchis.cpp プロジェクト: shenjian74/Bitcoin-History
void writeout_file(char *time_peroid){
	char sql[1024];
	int retcode;
	
	sprintf(sql, "SELECT * FROM history");
	retcode = sqlite3_exec(pDB, sql, &sqlite3_exec_callback, time_peroid, &errmsg);
	if(SQLITE_OK!=retcode){
		printf("retcode of sqlite3_exec():%d description:%s", retcode, errmsg);
		sqlite3_free(errmsg);
	}
	
	char filename[1024];
	sprintf(filename, "%s.csv", time_peroid);
	FILE *fp = fopen(filename, "wt");
	if(NULL!=fp){
		printf("\nWriting file:%s...", filename);
		for(DataMap::iterator it = dataMap.begin(); it != dataMap.end(); it++){
			struct tm *st = localtime(&(it->second.timestamp));
			fprintf(fp, "%04d.%02d.%02d,%02d:%02d,%lf,%lf,%lf,%lf,%lf\n", 
				st->tm_year+1900, st->tm_mon+1, st->tm_mday, st->tm_hour, st->tm_min,
				it->second.open, it->second.high, it->second.low, it->second.close,
				it->second.amount);
				/*
				printf("timestamp:%s open:%lf high:%lf low:%lf close:%lf amount:%lf\n",
				ctime(&(it->second.timestamp)), it->second.open, it->second.high,
				it->second.low, it->second.close, it->second.amount);
			*/
			
		}
		printf("done", filename);
		fclose(fp);
	}
	
	dataMap.clear(); // clear all the data in map
}
コード例 #2
0
ファイル: main.cpp プロジェクト: tinkostuff/opendta-code
/*---------------------------------------------------------------------------
* MAIN
*---------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
   QStringList args;
   for( int i=1; i<argc; i++) args << argv[i];

   // usage
   if( (argc==1) || ((argc==2) && (args.at(0)=="--stdout")))
   {
      cerr << QObject::tr("dta2csv [--stdout] <Liste-von-DTA-Dateien>").toStdString() << endl;
      cerr << QObject::tr("  Copyright (C) 2015  [email protected], http://opendta.sf.net/").toStdString() << endl;
      cerr << QObject::tr("  Version: %1").arg(VERSION_STRING).toStdString() << endl;
      cerr << QObject::tr("  GNU General Public License Version 3").toStdString() << endl;
      cerr << QObject::tr("  powered by Qt framework").toStdString() << endl;
      return 0;
   }

   // globale variablen
   bool output2stdout = false;

   // Argumente untersuchen
   if (args.at(0) == "--stdout")
   {
      cerr << "Ausgabe wird nach stdout umgeleitet!" << endl;
      output2stdout = true;
      args.takeFirst();
   }

   // jede Datei einzeln bearbeiten
   DataMap data;
   for( int i=0; i<args.size(); i++)
   {
      QString fileName = args.at(i);
      cerr << QObject::tr("konvertiere Datei: ").toStdString() << fileName.toStdString() << endl;

      // Datei oeffnen
      DtaFile *dta = new DtaFile(fileName);
      if( !dta->open())
      {
         // Fehlertext wird beireits in DtaFile geschrieben
         delete dta;
         continue;
      }

      // Datei einlesen
      dta->readDatasets(&data);

      if( !output2stdout && !data.isEmpty())
      {
         // Ausgabedatei oeffnen
         QFile fOut(fileName+".csv");
         if (!fOut.open(QIODevice::WriteOnly | QIODevice::Text))
         {
            qWarning() << QString(QObject::tr("FEHLER: beim \326ffnen der CSV-Datei '%1'!")).arg(fileName+".csv");
            delete dta;
            continue;
         }

         // Daten schreiben
         outputData( &fOut, &data);

         // Ausgabedatei schliessen
         fOut.close();

         // Daten loeschen
         data.clear();

      } // if !output2stdout && !data.isEmpty

      delete dta;
   } // foreach file

   // Ausgabe nach stdout
   if (output2stdout)
   {
      cerr << "schreibe Ergebnis" << endl;
      QFile fOut;
      //fOut.open( stdout, QIODevice::WriteOnly | QIODevice::Text);
      fOut.open( stdout, QIODevice::WriteOnly);
      outputData( &fOut, &data);
      fOut.close();
   }

} // main