2021-05-05 14:35:36 -06:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
my $username = ""; # Username to include in posts
|
|
|
|
my $dblocation = "./shomble/posts.db"; #needs to point to the relative or absolute
|
|
|
|
# system path of the posts.db file.
|
|
|
|
my $post = "";
|
|
|
|
|
|
|
|
my $db = DBI->connect("DBI:SQLite:dbname=$dblocation", "", "", { RaiseError => 1}) or die $DBI::errstr;
|
|
|
|
|
|
|
|
TRYAGAIN:
|
|
|
|
print "Ok, what would you like to submit?\n>";
|
|
|
|
$post = <STDIN>;
|
|
|
|
chomp $post;
|
|
|
|
|
|
|
|
print "Confirming this is your post:\n".$post."\n Is this correct? (you must type y or yes to submit)\n>";
|
|
|
|
|
|
|
|
if ( <STDIN> =~ /y(es)?/i ) {
|
|
|
|
#this needs to be called right before the post is submitted to the database.
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
|
2021-05-07 13:48:56 -06:00
|
|
|
my $timeStamp = sprintf("%.2d/%.2d/%.4d %.2d:%.2d:%.2d", $mday, ($mon + 1), ($year + 1900), $hour, $min, $sec;
|
2021-05-05 14:35:36 -06:00
|
|
|
|
|
|
|
my $statmentHandle = $db->prepare('INSERT INTO posts VALUES( ?1, ?2, ?3)') or die $DBI::errstr;
|
|
|
|
$statmentHandle->execute( $timeStamp, $username, $post ) or die $DBI::errstr;
|
|
|
|
print "Post submitted, thank you for using Shombler!";
|
|
|
|
} else {
|
|
|
|
goto TRYAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->disconnect();
|