Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 9.27 KB | None | 0 0
  1. use warnings;                                                                                                                                                                    
  2. use strict;                                                                                                                                                                      
  3. use Getopt::Long;                                                                                                                                                                
  4.                                                                                                                                                                                  
  5. my $bg = '';                                                                                                                                                                    
  6. my $graph = '';                                                                                                                                                                  
  7. my $filename = "graph.png";                                                                                                                                                      
  8. my $db_dump = '';                                                                                                                                                                
  9.                                                                                                                                                                                  
  10. # displays my help if there are no arguments or one of the specified options                                                                                                    
  11. usage() if (@ARGV < 1 or ! GetOptions('b=i' => \$bg, 'g' => \$graph, 'f=s' => \$filename, 'd' => \$db_dump));                                                                    
  12.                                                                                                                                                                                  
  13. print "#---------------------#\n";                                                                                                                                              
  14. print "DEBUG info\n";                                                                                                                                                            
  15. print "bg: $bg g: $graph filename: $filename and d: $db_dump\n";                                                                                                                
  16. print "#---------------------#\n\n";                                                                                                                                            
  17.                                                                                                                                                                                  
  18. if ($db_dump == 1) { &dbconnect(); print $1; }                                                                                                                                  
  19.                                                                                                                                                                                  
  20. sub usage {                                                                                                                                                                      
  21.         use Term::ANSIColor qw(:constants);                                                                                                                                      
  22.         print "Unknown option: @_\n" if ( @_ );                                                                                                                                  
  23.         print "usage: $0 [", BOLD, "-b #", RESET, "] [", BOLD, "-g", RESET, "] [", BOLD,"-f file", RESET, "] [ ", BOLD "-d", RESET, " ]\n\n";                                    
  24.         print "\t", BOLD, "-b", RESET, "   :   Specify a blood sugar value\n";                                                                                                  
  25.         print "\t", BOLD, "-g", RESET, "   :   Utilize graphing feature\n";                                                                                                      
  26.         print "\t", BOLD, "-f", RESET, "   :   Specify output PNG filename. Must be used with ", BOLD, "-g", RESET, ". Default name is graph.png\n";                            
  27.         print "\t", BOLD, "-d", RESET, "   :   Display all fields from the BG database\n\n";                                                                                    
  28.         exit;                                                                                                                                                                    
  29. }                                                                                                                                                                                
  30.                                                                                                                                                                                  
  31. sub dbconnect {                                                                                                                                                                  
  32.         use DBI;                                                                                                                                                                
  33.         print "hey! you're about to connect!!\n";                                                                                                                                
  34.         my $dbh = DBI->connect(                                                                                                                                                  
  35.                 "dbi:SQLite:dbname=cosc279_bgs.db",                                                                                                                              
  36.                 "",                                                                                                                                                              
  37.                 "",                                                                                                                                                              
  38.                 { RaiseError => 1 },                                                                                                                                            
  39.                 ) or die $DBI::errstr;                                                                                                                                          
  40.         return $1;                                                                                                                                                              
  41. }                                                                                                                                                                                
  42.                                                                                                                                                                                  
  43. sub db_dump {                                                                                                                                                                    
  44.         my $data = $1->selectall_arrayref("SELECT * FROM bgtable BY Date DESC");                                                                                                
  45.         foreach (@$data) {                                                                                                                                                      
  46.                 my ($id, $date, $time, $bg) = @$_;                                                                                                                              
  47.                 print "$id\t$date\t$time\t$bg\n";                                                                                                                                
  48.                 }                                                                                                                                                                
  49.         exit;                                                                                                                                                                    
  50. }                                                                                                                                                                                
  51.                                                                                                                                                                                  
  52. sub grapher {                                                                                                                                                                    
  53.         print "Utilize the grapher\n";                                                                                                                                          
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement