shombler/shomble.pl

33 lines
1.1 KiB
Perl
Raw Normal View History

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();
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();