Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2019, 01:38 PM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Excel 2 Forum

Good day everybody,

I have an excel file with different rows and I want to create threads with content out of each row.
Is there already something like a phyton script available for this?

If not, can you give me some tipps and advice to start off how I could cope with something like this?
Maybe there is even a coder who could code something like this in python for me?

Greetings!
Reply With Quote
  #2  
Old 10-31-2019, 01:52 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a reason you want to use Python even though vBulletin 5 is created using PHP?

Using PHP you can read the Excel file and iterate through each row and then insert the thread.
PHP Code:
// Path to the vBulletin 5 folder. 
// '.' indicates current directory where the .htaccess file resides.
$vbpath '.';
define('CSRF_PROTECTION'false);
require_once(
$vbpath '/includes/vb5/autoloader.php');
vB5_Autoloader::register($vbpath);
vB5_Frontend_Application::init('config.php');

$api Api_InterfaceAbstract::instance();
$thread $api->callApi('content_text''add', [
    
'data' => [
        
'rawtext' => 'Content of the thread.',
        
'title' => 'Title of the thread.',
        
'parentid' => 3// ID of the forum section (or node as they call it in vBulletin 5)
        
'userid' => // ID of the user to post the thread as
    
],
    
'options' => [
        
'nl2br' => true
    
]
]);

var_dump($thread);

/*
Integer if created successfully, contains the thread id.
int(15)
Array if errors.
array(1) { [0]=> array(1) { [0]=> string(19) "humanverify_missing" } }
*/ 
Reply With Quote
  #3  
Old 10-31-2019, 01:53 PM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no, just because I am more into python at the moment.
Thanks already for the script. But how can I tell it to get the data from my excel exactly? Is there an example?

--------------- Added [DATE]1572536085[/DATE] at [TIME]1572536085[/TIME] ---------------

The excel file is structured as


colum 1 = title
colum = thread content


there are x rows whereby each row should be a different thread.
I understand the code you wrote there, but I dont get how I can link this to an excel file.



Can you help me here?

--------------- Added [DATE]1572543745[/DATE] at [TIME]1572543745[/TIME] ---------------

It hasnt necessarly to be excel 2 vbulletin. Right now I just have all the data in an excel file.
Reply With Quote
  #4  
Old 11-02-2019, 11:00 AM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I came a bit closer to the solution I guess, got some help from another guy regarding the importing problem from a csv file. But I can't get it working.


Anyone, any help here?






Code:
$row = 1;
if (($handle = fopen("yourdata.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($rowfields);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
...
$post_title = $rowfields[0];
$post_content = $rowfields[1];
...
// then you call the thread creator
PostCreator(... 
}
fclose($handle);
}


function PostCreator($title, $content... ) {
...
// here you call the code to create the thread
// it's not real code, just to help you figure it out

$thread = $api->callApi('content_text', 'add', [
'data' => [
'rawtext' => $content,
'title' => $title,
'parentid' => 3, // ID of the forum section (or node as they call it in vBulletin 5)
'userid' => 1 // ID of the user to post the thread as
],
'options' => [
'nl2br' => true
]
]);

}
Reply With Quote
  #5  
Old 11-02-2019, 11:40 AM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Something like:

PHP Code:
// Path to the vBulletin 5 folder. 
// '.' indicates current directory where the .htaccess file resides.
$vbpath '.';
define('CSRF_PROTECTION'false);
require_once(
$vbpath '/includes/vb5/autoloader.php');
vB5_Autoloader::register($vbpath);
vB5_Frontend_Application::init('config.php');
$api Api_InterfaceAbstract::instance();

$row 1;
if ((
$handle fopen('yourdata.csv''r')) !== FALSE) {
    while ((
$data fgetcsv($handle1000',')) !== FALSE) {
        
$num count($rowfields);
        echo 
'<p> ' $num ' fields in line ' $row ': <br /></p>';
        
$row++;
    
        
$post_title $rowfields[0];
        
$post_content $rowfields[1];
    
        
// then you call the thread creator
        
$thread $api->callApi('content_text''add', [
            
'data' => [
                
'rawtext' => $post_content,
                
'title' => $post_title,
                
'parentid' => 3// ID of the forum section (or node as they call it in vBulletin 5)
                
'userid' => // ID of the user to post the thread as
            
],
            
'options' => [
                
'nl2br' => true
            
]
        ]);

    }
    
fclose($handle);

You still need to modify the parentid and userid value.
Pretty sure the script you gave is not valid though because it calls the $rowfields variable which does not exist.
Reply With Quote
  #6  
Old 11-02-2019, 12:08 PM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks, I finally got it working. Many thanks 2 you!
Reply With Quote
  #7  
Old 04-06-2020, 05:28 AM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey Dave, the script works like a charm, thank you so much again for your help!

There just came up another question from my side. When I work with larg csv files (more than about 1000 lines) the script runs longer than the max. execution time allowed by my server. The most of the times I split the files into separate files, what works of course.

But is there a "simple" way to update the script so that it also works with large files without running into problems with the max. execution time?

Regards!
Reply With Quote
  #8  
Old 04-06-2020, 08:15 AM
shka shka is offline
 
Join Date: Mar 2016
Posts: 79
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try

PHP Code:
        // then you call the thread creator
        
set_time_limit(30);
        
$thread $api->callApi('content_text''add', [ 
Reply With Quote
Благодарность от:
Zweeper
  #9  
Old 04-10-2020, 07:08 AM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Seems to work, many thanks!
Reply With Quote
  #10  
Old 04-13-2020, 09:15 AM
Zweeper Zweeper is offline
 
Join Date: Jan 2005
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok it is working, but not for me, since I cant change the set_time_limit at more than 90 seconds.

I could split my csv file into several files and then create several scripts which I have to run each after another.

like:

import_n.php imports import_n.csv
n+1

Is there a way to automatically start import_2.php when import_1 is finished?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:11 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06024 seconds
  • Memory Usage 2,282KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete