save doc to sqlite
This commit is contained in:
parent
3db228fa08
commit
54e6b0a139
4 changed files with 115 additions and 9 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
|||
.idea/
|
||||
.vscode/
|
||||
SecretKey.csv
|
||||
SecretKey.csv
|
||||
data/
|
||||
output/
|
||||
*.db
|
65
Translator/read.pl
Normal file
65
Translator/read.pl
Normal file
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use v5.26;
|
||||
|
||||
use Carp;
|
||||
use Data::Dumper;
|
||||
use File::Find;
|
||||
use SQL::Abstract;
|
||||
use DBI;
|
||||
|
||||
my $db =
|
||||
DBI->connect( "DBI:SQLite:dbname=../data.db", "", "", { RaiseError => 1 } )
|
||||
or confess $DBI::errstr;
|
||||
|
||||
sub sqlstr {
|
||||
return qq
|
||||
/create table if not exists @_ (
|
||||
id integer primary key autoincrement,
|
||||
title text,
|
||||
filepath text,
|
||||
content text
|
||||
);/;
|
||||
}
|
||||
my %tablesql = (
|
||||
"origin" => sqlstr("origin"),
|
||||
"trans" => sqlstr("trans"),
|
||||
);
|
||||
my $act;
|
||||
for my $table ( keys %tablesql ) {
|
||||
$act = $db->prepare( $tablesql{$table} );
|
||||
$act->execute() or confess $DBI::errstr;
|
||||
}
|
||||
|
||||
my @data;
|
||||
finddepth(
|
||||
sub {
|
||||
return unless ( $_ =~ /.md$/ );
|
||||
push @data, $File::Find::name;
|
||||
},
|
||||
'../data/'
|
||||
);
|
||||
my $csql = qq
|
||||
/insert into origin (title,filepath,content)
|
||||
values (?,?,?);/;
|
||||
for my $d (@data) {
|
||||
my %info;
|
||||
my $content;
|
||||
open my $file, "< :encoding(UTF-8)", $d;
|
||||
<$file>;
|
||||
while (<$file>) {
|
||||
chomp;
|
||||
if (/^([^:]+):\s+(.+)/) {
|
||||
$info{$1} = $2;
|
||||
}
|
||||
last if /---/;
|
||||
}
|
||||
while (<$file>) {
|
||||
$content .= $_;
|
||||
}
|
||||
close($file);
|
||||
$act = $db->prepare($csql);
|
||||
$act->execute( $info{'title'}, $d, $content ) or carp $DBI::errstr;
|
||||
$act->finish() or carp $DBI::errstr;
|
||||
}
|
30
Translator/sen.pl
Normal file
30
Translator/sen.pl
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use v5.26;
|
||||
|
||||
use Text::CSV;
|
||||
use Carp;
|
||||
use utf8;
|
||||
|
||||
my $csv = Text::CSV->new( { binary => 1, auto_diag => 1 } );
|
||||
open my $in, "< :encoding(UTF-8)", $ARGV[0] or confess;
|
||||
open my $out, "> :encoding(UTF-8)", "../output/import.csv" or confess;
|
||||
$csv->print( $out, [ "原文", "译文" ] );
|
||||
my $msgid;
|
||||
my $msgstr;
|
||||
while ( my $line = <$in> ) {
|
||||
chomp $line;
|
||||
if ( $line =~ /^msgid "(.*)"/ ) {
|
||||
$msgid = $1;
|
||||
}
|
||||
elsif ( $line =~ /^msgstr "(.*)"/ ) {
|
||||
$msgstr = $1;
|
||||
$msgid =~ s/\\n/\n/g;
|
||||
$msgstr =~ s/\\n/\n/g;
|
||||
$csv->print( $out, [ $msgid, $msgstr ] );
|
||||
print $out "\n";
|
||||
}
|
||||
}
|
||||
close $in;
|
||||
close $out;
|
|
@ -3,13 +3,20 @@ use strict;
|
|||
use warnings;
|
||||
use v5.26;
|
||||
|
||||
use Carp;
|
||||
use Time::Piece;
|
||||
use Digest::SHA qw(sha256_hex hmac_sha256_hex);
|
||||
use Digest::SHA qw(sha256_hex hmac_sha256_hex);
|
||||
use JSON::MaybeXS qw(encode_json);
|
||||
|
||||
say "You must provide SecretKey.csv to parent folder!";
|
||||
my $SourceText = "Get Current Time in Seconds Perl";
|
||||
my $payload = qq
|
||||
/{"SourceText":"$SourceText","Source":"en","Target":"zh","ProjectId":0}/;
|
||||
carp "You must provide SecretKey.csv to parent folder!";
|
||||
our $SourceText ;
|
||||
my $data = {
|
||||
SourceText => $SourceText,
|
||||
Source => 'en',
|
||||
Target => 'zh',
|
||||
ProjectID => 0
|
||||
};
|
||||
my $payload = encode_json($data);
|
||||
|
||||
my $service = "tmt";
|
||||
my $host = "$service.tencentcloudapi.com";
|
||||
|
@ -46,7 +53,7 @@ $RequestTimestamp
|
|||
$CredentialScope
|
||||
$HashedCanonicalRequest/;
|
||||
|
||||
open my $in, "<", "../SecretKey.csv" or die $!;
|
||||
open my $in, "<", "../SecretKey.csv" or confess;
|
||||
my $key;
|
||||
<$in>;
|
||||
$key = <$in>;
|
||||
|
@ -59,6 +66,7 @@ my $SecretService = hmac_sha256_hex( $SecretDate, $service );
|
|||
my $SecretSigning = hmac_sha256_hex( $SecretService, "tc3_request" );
|
||||
my $Signature = hmac_sha256_hex( $SecretSigning, $StringToSign );
|
||||
|
||||
my $Authorization =
|
||||
our $Authorization =
|
||||
"$Algorithm Credential=$SecretID/$CredentialScope, SignedHeaders=$SignedHeaders, Signature=$Signature";
|
||||
say $Authorization;
|
||||
|
||||
say $payload;
|
Loading…
Add table
Reference in a new issue