Creating a CSV file from these forums

Creating a CSV file from these forums

Postby Antonio Linares » Thu Jan 25, 2024 6:00 am

These forums as a DBF and FPT files:
https://huggingface.co/datasets/fivetech/forums_dbf/tree/main

forums_csv.prg
Code: Select all  Expand view
#include "FiveWin.ch"

request dbfcdx

function Main()

    local cPostsCSV := "topic,text" + Chr( 10 )

    USE posts VIA "dbfcdx"

    INDEX ON posts->topic + posts->date + posts->time + posts->forum TO subject
    GO TOP

    while ! EoF()
       cPostsCSV += StrTran( StrTran( StrTran( StrToUtf8( RTrim( posts->topic ) ), ["], [""] ), CRLF, "" ), ",", "" ) + ',"' + ;
                    StrTran( StrTran( StrToUtf8( RTrim( posts->text ) ),  ["], [""] ), CRLF, "" ) + '
"' + Chr( 10 )
       SKIP
    end      

    hb_memoWrit( "
forums.csv", cPostsCSV )

return nil

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( STRTOUTF8 )
{
   int iLength1;
   int iLength2;
   LPWSTR szWideText;
   char * szDest;

   iLength1 = MultiByteToWideChar( CP_ACP, 0, hb_parc( 1 ), hb_parclen( 1 ), NULL, 0 );
   szWideText = ( LPWSTR ) hb_xgrab( ( iLength1 + 1 ) * 2 );
   MultiByteToWideChar( CP_ACP, 0, hb_parc( 1 ), hb_parclen( 1 ), szWideText, iLength1 );
   szWideText[ iLength1 ] = NULL;
   iLength2 = WideCharToMultiByte( CP_UTF8, 0, szWideText, iLength1, NULL, 0, NULL, NULL );
   szDest = ( char * ) hb_xgrab( iLength2 + 1 );
   WideCharToMultiByte( CP_UTF8, 0, szWideText, iLength1, szDest, iLength2, NULL, NULL );
   hb_xfree( ( void * ) szWideText );
   szDest[ iLength2 ] = NULL;
   hb_retc( szDest );
   hb_xfree( ( void * ) szDest );
}    

#pragma ENDDUMP

Resulting forums.csv file:
https://huggingface.co/datasets/fivetech/forums_csv/tree/main
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests