This commit is contained in:
Ougi 2023-11-09 14:49:14 +03:00
parent 5f9da38d19
commit 4b16e4dacc
7 changed files with 58 additions and 46 deletions

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
</project>

View file

@ -5,7 +5,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="2719f698-d385-4287-8ac4-9912303895a8" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/Task.pdf" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TestProject/lib/DB.pm" beforeDir="false" afterPath="$PROJECT_DIR$/TestProject/lib/DB.pm" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TestProject/lib/TestProject.pm" beforeDir="false" afterPath="$PROJECT_DIR$/TestProject/lib/TestProject.pm" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -15,23 +17,24 @@
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 0
}]]></component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 0
}</component>
<component name="ProjectId" id="2XDGslrhhYX518libb4N3bk3PFj" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"last_opened_file_path": "C:/Users/night/OneDrive/Рабочий стол/task7"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/night/OneDrive/Рабочий стол/task7&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;
}
}]]></component>
}</component>
<component name="RunManager">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="task7" />

View file

@ -10,13 +10,14 @@ use DBI;
sub new {
my $class = shift;
my $params = shift;
my $self = {
db_info => 'dbi:Pg:dbname=postgres;host=localhost;port=5432',
db_username => 'postgres',
db_password => '0000',
db_info => $params->{db_info} || 'dbi:Pg:dbname=postgres;host=localhost;port=5432',
db_username => $params->{db_username} || 'postgres',
db_password => $params->{db_password} || '0000',
dbh => undef,
db_params => {
db_params => $params->{db_params} || {
postgres_enable_utf8 => 1,
RaiseError => 1,
},
@ -35,27 +36,27 @@ sub connect {
}
sub get_rows {
my $class = shift;
my $self = shift;
my $address = shift;
my $alert = 0;
my $sql_logs = "select created,str from log where address = ?
my $sql_logs_template = "select created,str from log where address = ?
order by created,int_id ;";
my $dbh = $class->{dbh};
my $dbh = $self->{dbh};
my $sth = $dbh->prepare($sql_logs);
my $sth = $dbh->prepare($sql_logs_template);
my $rs = $sth->execute($address);
if ( $rs eq '0E0' ) {
return ( 0, [ [ 'Нет данных', 'Нет данных' ] ] );
}
elsif ( $rs > 100 ) {
if ( $rs > 100 ) {
$alert = 1;
}
my $table = $sth->fetchall_arrayref;
return $alert, $table;
return {
alert => $alert,
table =>$table
};
}
1;

View file

@ -1,11 +1,10 @@
package TestProject;
use DB;
use Dancer2;
use Data::Dumper;
use DB;
our $VERSION = '0.1';
# самая крутая регулярка на email
@ -32,19 +31,19 @@ post '/logs' => sub {
$err = 'Ошибка: пустой адрес';
}
my $db_rows;
my $select_limit;
my %res_get_rows;
unless ($err) {
my $dbh = DB->new();
$dbh->connect();
( $select_limit, $db_rows ) = $dbh->get_rows($address);
%res_get_rows = $dbh->get_rows($address);
}
template 'logs' => {
title => $address,
err => $err,
alert => $select_limit,
rows => $db_rows,
alert => $res_get_rows{alert},
rows => $res_get_rows{table},
get_address => uri_for('/'),
};

View file

@ -39,4 +39,4 @@ sub create_tables {
my $dbh = DBI->connect( $dbi_info, $db_username, $db_password,
{ postgres_enable_utf8 => 1, RaiseError => 1 } );
print( create_tables($dbh) );
create_tables($dbh);

View file

@ -24,8 +24,8 @@ my $insert_log_template =
my $insert_message_template =
'INSERT INTO message (created,id,int_id,str) values (?,?,?,?)';
my $regex_for_get_id = qr( id=(\S*) ?);
my $regex_get_address_for_log_with_blackhol = qr( \<(.*\@.*)\> );
my $regex_get_address_for_log_without_blackhol = qr( (\S*\@\S*) );
my $regex_get_address_for_log_with_blackhole = qr( \<(.*\@.*)\> );
my $regex_get_address_for_log_without_blackhole = qr( (\S*\@\S*) );
my $file_path = "log/out";
# ------------------- ------------- ---------------------------
@ -44,11 +44,11 @@ sub _get_address {
my $str = shift;
if ( $str =~ /:blackhole:/ ) {
$str =~ /$regex_get_address_for_log_with_blackhol/;
$str =~ /$regex_get_address_for_log_with_blackhole/;
return $1;
}
else {
$str =~ /$regex_get_address_for_log_without_blackhol/;
$str =~ /$regex_get_address_for_log_without_blackhole/;
return $1;
}
}
@ -68,10 +68,10 @@ sub _parce_row_log {
}
sub create_row_in_table_log {
sub save_log {
my ( $dbh, $created, $int_id, $str ) = @_;
my $address = _get_address($str);
my $address = _get_address($str) || '';
$dbh->do( $insert_log_template, undef,
( $created, $int_id, $str, $address ) );
@ -80,17 +80,17 @@ sub create_row_in_table_log {
}
sub create_row_in_table_message {
sub save_message {
my ( $dbh, $created, $int_id, $str ) = @_;
my $id = _get_id($str);
my $id = _get_id($str) || '';
if ($id) {
$dbh->do( $insert_message_template, undef,
( $created, $id, $int_id, $str ) );
}
else {
my $address = _get_address($str);
my $address = _get_address($str) || '';
$dbh->do( $insert_log_template, undef,
( $created, $int_id, $str, $address ) );
@ -109,10 +109,10 @@ sub process_log {
my ( $created, $int_id, $str, $flag ) = _parce_row_log($row);
if ( $flag eq "<=" ) {
create_row_in_table_message( $dbh, $created, $int_id, $str );
save_message( $dbh, $created, $int_id, $str );
}
else {
create_row_in_table_log( $dbh, $created, $int_id, $str );
save_log( $dbh, $created, $int_id, $str );
}
}
@ -122,6 +122,5 @@ sub process_log {
my $dbh = DBI->connect( $dbi_info, $db_username, $db_password,
{ postgres_enable_utf8 => 1, RaiseError => 1 } );
print( process_log( $dbh, $file_path ) );
exit(0);
process_log( $dbh, $file_path );