refactor
This commit is contained in:
parent
5f9da38d19
commit
4b16e4dacc
7 changed files with 58 additions and 46 deletions
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal 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
4
.idea/misc.xml
Normal 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>
|
|
@ -5,7 +5,9 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="2719f698-d385-4287-8ac4-9912303895a8" name="Changes" comment="">
|
<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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -15,23 +17,24 @@
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectColorInfo"><![CDATA[{
|
<component name="ProjectColorInfo">{
|
||||||
"associatedIndex": 0
|
"associatedIndex": 0
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="ProjectId" id="2XDGslrhhYX518libb4N3bk3PFj" />
|
<component name="ProjectId" id="2XDGslrhhYX518libb4N3bk3PFj" />
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"last_opened_file_path": "C:/Users/night/OneDrive/Рабочий стол/task7"
|
"last_opened_file_path": "C:/Users/night/OneDrive/Рабочий стол/task7",
|
||||||
|
"settings.editor.selected.configurable": "preferences.pluginManager"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
||||||
<module name="task7" />
|
<module name="task7" />
|
||||||
|
|
|
@ -10,13 +10,14 @@ use DBI;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
my $params = shift;
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
db_info => 'dbi:Pg:dbname=postgres;host=localhost;port=5432',
|
db_info => $params->{db_info} || 'dbi:Pg:dbname=postgres;host=localhost;port=5432',
|
||||||
db_username => 'postgres',
|
db_username => $params->{db_username} || 'postgres',
|
||||||
db_password => '0000',
|
db_password => $params->{db_password} || '0000',
|
||||||
dbh => undef,
|
dbh => undef,
|
||||||
db_params => {
|
db_params => $params->{db_params} || {
|
||||||
postgres_enable_utf8 => 1,
|
postgres_enable_utf8 => 1,
|
||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
},
|
},
|
||||||
|
@ -35,27 +36,27 @@ sub connect {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_rows {
|
sub get_rows {
|
||||||
my $class = shift;
|
my $self = shift;
|
||||||
my $address = shift;
|
my $address = shift;
|
||||||
|
|
||||||
my $alert = 0;
|
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 ;";
|
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);
|
my $rs = $sth->execute($address);
|
||||||
|
|
||||||
if ( $rs eq '0E0' ) {
|
if ( $rs > 100 ) {
|
||||||
return ( 0, [ [ 'Нет данных', 'Нет данных' ] ] );
|
|
||||||
}
|
|
||||||
elsif ( $rs > 100 ) {
|
|
||||||
$alert = 1;
|
$alert = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $table = $sth->fetchall_arrayref;
|
my $table = $sth->fetchall_arrayref;
|
||||||
|
|
||||||
return $alert, $table;
|
return {
|
||||||
|
alert => $alert,
|
||||||
|
table =>$table
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package TestProject;
|
package TestProject;
|
||||||
|
|
||||||
use DB;
|
|
||||||
|
|
||||||
use Dancer2;
|
use Dancer2;
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
use DB;
|
||||||
|
|
||||||
our $VERSION = '0.1';
|
our $VERSION = '0.1';
|
||||||
|
|
||||||
# самая крутая регулярка на email
|
# самая крутая регулярка на email
|
||||||
|
@ -32,19 +31,19 @@ post '/logs' => sub {
|
||||||
$err = 'Ошибка: пустой адрес';
|
$err = 'Ошибка: пустой адрес';
|
||||||
}
|
}
|
||||||
|
|
||||||
my $db_rows;
|
my %res_get_rows;
|
||||||
my $select_limit;
|
|
||||||
unless ($err) {
|
unless ($err) {
|
||||||
my $dbh = DB->new();
|
my $dbh = DB->new();
|
||||||
$dbh->connect();
|
$dbh->connect();
|
||||||
( $select_limit, $db_rows ) = $dbh->get_rows($address);
|
%res_get_rows = $dbh->get_rows($address);
|
||||||
}
|
}
|
||||||
|
|
||||||
template 'logs' => {
|
template 'logs' => {
|
||||||
title => $address,
|
title => $address,
|
||||||
err => $err,
|
err => $err,
|
||||||
alert => $select_limit,
|
alert => $res_get_rows{alert},
|
||||||
rows => $db_rows,
|
rows => $res_get_rows{table},
|
||||||
get_address => uri_for('/'),
|
get_address => uri_for('/'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,4 +39,4 @@ sub create_tables {
|
||||||
|
|
||||||
my $dbh = DBI->connect( $dbi_info, $db_username, $db_password,
|
my $dbh = DBI->connect( $dbi_info, $db_username, $db_password,
|
||||||
{ postgres_enable_utf8 => 1, RaiseError => 1 } );
|
{ postgres_enable_utf8 => 1, RaiseError => 1 } );
|
||||||
print( create_tables($dbh) );
|
create_tables($dbh);
|
||||||
|
|
|
@ -24,8 +24,8 @@ my $insert_log_template =
|
||||||
my $insert_message_template =
|
my $insert_message_template =
|
||||||
'INSERT INTO message (created,id,int_id,str) values (?,?,?,?)';
|
'INSERT INTO message (created,id,int_id,str) values (?,?,?,?)';
|
||||||
my $regex_for_get_id = qr( id=(\S*) ?);
|
my $regex_for_get_id = qr( id=(\S*) ?);
|
||||||
my $regex_get_address_for_log_with_blackhol = qr( \<(.*\@.*)\> );
|
my $regex_get_address_for_log_with_blackhole = qr( \<(.*\@.*)\> );
|
||||||
my $regex_get_address_for_log_without_blackhol = qr( (\S*\@\S*) );
|
my $regex_get_address_for_log_without_blackhole = qr( (\S*\@\S*) );
|
||||||
my $file_path = "log/out";
|
my $file_path = "log/out";
|
||||||
|
|
||||||
# ------------------- ------------- ---------------------------
|
# ------------------- ------------- ---------------------------
|
||||||
|
@ -44,11 +44,11 @@ sub _get_address {
|
||||||
my $str = shift;
|
my $str = shift;
|
||||||
|
|
||||||
if ( $str =~ /:blackhole:/ ) {
|
if ( $str =~ /:blackhole:/ ) {
|
||||||
$str =~ /$regex_get_address_for_log_with_blackhol/;
|
$str =~ /$regex_get_address_for_log_with_blackhole/;
|
||||||
return $1;
|
return $1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$str =~ /$regex_get_address_for_log_without_blackhol/;
|
$str =~ /$regex_get_address_for_log_without_blackhole/;
|
||||||
return $1;
|
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 ( $dbh, $created, $int_id, $str ) = @_;
|
||||||
|
|
||||||
my $address = _get_address($str);
|
my $address = _get_address($str) || '';
|
||||||
|
|
||||||
$dbh->do( $insert_log_template, undef,
|
$dbh->do( $insert_log_template, undef,
|
||||||
( $created, $int_id, $str, $address ) );
|
( $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 ( $dbh, $created, $int_id, $str ) = @_;
|
||||||
|
|
||||||
my $id = _get_id($str);
|
my $id = _get_id($str) || '';
|
||||||
|
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$dbh->do( $insert_message_template, undef,
|
$dbh->do( $insert_message_template, undef,
|
||||||
( $created, $id, $int_id, $str ) );
|
( $created, $id, $int_id, $str ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $address = _get_address($str);
|
my $address = _get_address($str) || '';
|
||||||
|
|
||||||
$dbh->do( $insert_log_template, undef,
|
$dbh->do( $insert_log_template, undef,
|
||||||
( $created, $int_id, $str, $address ) );
|
( $created, $int_id, $str, $address ) );
|
||||||
|
@ -109,10 +109,10 @@ sub process_log {
|
||||||
my ( $created, $int_id, $str, $flag ) = _parce_row_log($row);
|
my ( $created, $int_id, $str, $flag ) = _parce_row_log($row);
|
||||||
|
|
||||||
if ( $flag eq "<=" ) {
|
if ( $flag eq "<=" ) {
|
||||||
create_row_in_table_message( $dbh, $created, $int_id, $str );
|
save_message( $dbh, $created, $int_id, $str );
|
||||||
}
|
}
|
||||||
else {
|
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,
|
my $dbh = DBI->connect( $dbi_info, $db_username, $db_password,
|
||||||
{ postgres_enable_utf8 => 1, RaiseError => 1 } );
|
{ postgres_enable_utf8 => 1, RaiseError => 1 } );
|
||||||
|
|
||||||
print( process_log( $dbh, $file_path ) );
|
process_log( $dbh, $file_path );
|
||||||
exit(0);
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue