-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzaiko.pl
executable file
·1192 lines (1024 loc) · 35.9 KB
/
zaiko.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
# This program was created by Kawabata Shuto and all copyrights have been saved on August 15th, 2017.
# shuto kawabata, University of Tsukuba, Tochigi prefecture, Utsunomiya city.
use utf8;
use Encode;
use strict;
use warnings;
use URI::Escape; #for encoding string
use Time::HiRes qw(sleep); #for sleep
use LWP::Simple; # get html
use LWP::UserAgent; # get html as UserAgent
use Mozilla::CA; #get html as Mozilla browser
use Term::ANSIColor qw(:constants); #for print with color
$Term::ANSIColor::AUTORESET = 1;
use Term::ANSIColor 2.00 qw(:pushpop);
# for E-mail
use Authen::SASL;
use MIME::Base64;
use Net::SMTP;
use Data::Dumper;
use Math::Round;
use Proc::CPUUsage;
my $q = 0;
while ($q == 0){
#print "Sleeping...zZ\n";
#sleep(5);
my $num = 1;
open(F, "item_list.csv")||die "cannot open 'item_list.csv':$!\n";
while(my $list = <F>){
my $cpu = Proc::CPUUsage->new;
my $usage1 = $cpu->usage; ## returns usage since new()
my $usage2 = $cpu->usage; ## returns usage since last usage()
# print $usage1."\n";
# print $usage2."\n";
# Extract domain
my @rec = split(/,/,$list);
my $url = $rec[0];
my $iName = $rec[2];
my $limit = $rec[1];
chomp($iName);
my $domin;
if ($url =~ /^(http|https):\/\/([-\w\.]+)\//){
$domin = $1."://".$2;
}
# Obtain html
print "ID: $num";
print "\n";
print "Now getting html ...\n";
sleep(0.1);
my $html = get($url) or die "The web-page of $url does not exsist. So, please remove $url of $num from item_list.csv ";
if($domin eq 'http://www.biccamera.com'){
&Big_Camera($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://www.yodobashi.com'){
&Yodobashi($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://shop.tsutaya.co.jp'){
&TSUTAYA($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'https://www.amazon.co.jp'){
&Amazon;
}elsif($domin eq 'https://online.nojima.co.jp'){
&Nojima($num,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://www.yamada-denkiweb.com'){
&Yamada($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'https://item.mercari.com'){
&mercari($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://7net.omni7.jp'){
&omuni7($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'https://item.rakuten.co.jp'){
&rakuten($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://www.ksdenki.com'){
&ksdenki($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://www.sofmap.com'){
&sofmap($num,$html,$url,$iName,$domin,$limit);
}elsif($domin eq 'http://www.kojima.net'){
&kojima($num,$html,$url,$iName,$domin,$limit);
}
print "\n\n";
$num++;
}
close(F);
}
sub Notify{
my $name = shift;
my $price = shift;
my $url = shift;
my $store = shift;
my $min_list_price = shift;
my $min_list_url = shift;
my $iName = shift;
my $num = shift;
my $min_list_domoin = shift;
my $min_list_num = shift;
my $deduction = shift;
my $time = shift;
my $status_jpn = shift;
my $NID = shift;
my $limit = shift;
#Alerm
print "\007";
#display notification on macbook
my $cmd= <<EOL;
osascript -e 'display notification "在庫を確認しました" with title "お知らせ" subtitle "$name"'
EOL
my $a=`$cmd`;
print "$a";
#send E-mail
my $SMTP_CONF =
{host=> 'smtp.mail.yahoo.co.jp', #yahooのsmtpサーバを送信用に指定
port=> '587',
from=> 'Username@yahoo.co.jp', #送信用メールアドレスを入力
return_path=> 'Username@yahoo.co.jp', #上に同じ
auth_uid=> 'Username@yahoo.co.jp', #上に同じ
auth_pw=> 'password' #Yahooアカウントのパスワード
};
main($name,$price,$url,$store,$min_list_price,$min_list_url,$iName,$num,$min_list_domoin,$min_list_num,$deduction,$time,$status_jpn,$NID,$limit);
sub main {
my $name = shift;
my $price = shift;
my $url = shift;
my $store = shift;
my $min_list_price = shift;
my $min_list_url = shift;
my $iName = shift;
my $num = shift;
my $min_list_domoin= shift;
my $min_list_num = shift;
my $deduction = shift;
my $time = shift;
my $status_jpn = shift;
my $NID = shift;
my $limit = shift;
#以下のAcceptを替えて受信先のアドレスとして指定してください.
publish_test_mail(['Accept@gmail.com'],$name,$price,$url,$store,$min_list_price,$min_list_url,$iName,$num,$min_list_domoin,$min_list_num,$deduction,$time,$status_jpn,$NID,$limit);
}
sub publish_test_mail {
my ($mailto ) = shift; #default
# my($mailto ) = shift;
my $name = shift;
my $price = shift;
my $url = shift;
my $store = shift;
my $min_list_price = shift;
my $min_list_url = shift;
my $iName = shift;
my $num = shift;
my $min_list_domin = shift;
my $min_list_num = shift;
my $deduction = shift;
my $time = shift;
my $status_jpn = shift;
my $NID = shift;
my $limit = shift;
my $subject_org = '在庫を確認しました';
my $subject = Encode::encode('MIME-Header-ISO_2022_JP', $subject_org);
my $display_deduction = abs($deduction);
if($min_list_domin eq 'http://www.biccamera.com'){
$min_list_domin = 'ビックカメラ';
}elsif($min_list_domin eq 'http://www.yodobashi.com'){
$min_list_domin = 'ヨドバシカメラ';
}elsif($min_list_domin eq 'http://shop.tsutaya.co.jp'){
$min_list_domin = 'TSUTAYAオンライン';
}elsif($min_list_domin eq 'https://online.nojima.co.jp'){
$min_list_domin = 'ノジマ電気';
}elsif($min_list_domin eq 'http://www.yamada-denkiweb.com'){
$min_list_domin = 'ヤマダ電機';
}elsif($min_list_domin eq 'https://item.mercari.com'){
$min_list_domin = 'メルカリ';
}elsif($min_list_domin eq 'http://7net.omni7.jp'){
$min_list_domin = 'オムニ7';
}elsif($min_list_domin eq 'https://item.rakuten.co.jp'){
$min_list_domin = '楽天オンライン';
}elsif($min_list_domin eq 'http://www.ksdenki.com'){
$min_list_domin = 'ケーズデンキ';
}elsif($min_list_domin eq 'http://www.sofmap.com'){
$min_list_domin = 'ソフマップ';
}elsif($min_list_domin eq 'http://www.kojima.net'){
$min_list_domin = 'コジマ';
}
#mailtoがない場合、送信は行いません. for debug
if( ref($mailto) ne "ARRAY" or @$mailto < 1 ){
return undef;
}
my $mailto_str = join(',', @$mailto );
my $message =<<EOF;
Hello, Shuto !
This E-mail was sent from the stock notification system since you added "$name" in item list as a favorite item and we confirmed that it is in stock now. Otherwise, status of the item or price of the item is now chenged.
So, please check it below.
--------------------------------------------------------------------------
Title: Notification of $NID
--------------------------------------------------------------------------
【ID】: $num
【NAME】: $name
【CATEGORY】: $iName
【STORE】: $store
【PRICE】 :¥$price
【STATUS】: $status_jpn
【URL】 : $url
【LIMITER】:¥$limit
【TIME】: $time
--------------------------------------------------------------------------
The Lowest Price of【$iName】below.
【ID】: $min_list_num
【CATEGORY】: $iName
【STORE】: $min_list_domin
【PRICE】: ¥$min_list_price
【URL】: $min_list_url
--------------------------------------------------------------------------
The Lowest Price is presently calculated by ranking just each raw prices on real time. So, if you want to switch to another calculated by real price, which is sum of raw price and tax and point reduction, please tell us with no hesitation. This stock notification system has been created by 'Shuto Kawabata' in August, 2017. All Copyrights have been reserved since 2017.
EOF
#メールのヘッダーを構築
my $header = << "MAILHEADER_1";
From: $SMTP_CONF->{from}
Return-path: $SMTP_CONF->{return_path}
Reply-To: $SMTP_CONF->{return_path}
To: $mailto_str
MAILHEADER_1
$header .=<<"MAILHEADER_2";
Subject: $subject
Mime-Version: 1.0
Content-Type: text/plain; charset = "ISO-2022-JP"
Content-Transfer-Encoding: 7bit
MAILHEADER_2
$message = encode('iso-2022-jp',$message);
my $smtp = Net::SMTP->new($SMTP_CONF->{host},
Hello=>$SMTP_CONF->{host},
Port=> $SMTP_CONF->{port},
Timeout=>20,
# Debug=> 1
);
unless($smtp){
my $msg = "can't connect smtp server: $!";
die $msg;
}
$smtp->auth($SMTP_CONF->{auth_uid}, $SMTP_CONF->{auth_pw}) or
die "can't login smtp server";
$smtp->mail($SMTP_CONF->{from});
$smtp->to(@$mailto);
$smtp->data();
$smtp->datasend("$header\n");
$smtp->datasend("$message\n");
$smtp->dataend();
$smtp->quit;
}
}
# コジマ
sub kojima{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName= shift;
my $domin= shift;
my $limit= shift;
my $store= 'コジマ';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','コジマ')."\n";
#name
my $n1 = '<title>【コジマネット】';
my $n2 = '</title>';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/</,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
$html =~ s/[\s ]+//g;
my $m1 = '<spanclass="price">';
my $m2 = '</span>';
#$html =~ /$m1(.+)$m2/;
#my $m3 = $+;
my @line = split(/$m1/,$html,2);
my $m3 = $line[1];
my @line2 = split(/$m2/,$m3,2);
my $Price = $line2[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,0,5);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = 'カートに入れる';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# ソフマップ
sub sofmap{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName= shift;
my $domin= shift;
my $limit= shift;
my $store= 'ソフマップ';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','ソフマップ')."\n";
#name
my $n1 = '<span class="product-detail-name">';
my $n2 = '</span>';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/</,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
my $m1 = '<span class="product-detail-price2">¥';
my $m2 = '</span>';
$html =~ /$m1(.+)$m2/;
my $m3 = $+;
my @line = split(/</,$m3,2);
my $Price = $line[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,1,10);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = '<inputalt="カートに入れる"';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# ケーズデンキ
sub ksdenki{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName= shift;
my $domin= shift;
my $limit= shift;
my $store= 'ケーズデンキ';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','ケーズデンキ')."\n";
#name
my $n1 = '<title>';
my $n2 = '</title>';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/</,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
my $m1 = '<span class="carousel_list_price_">';
my $m2 = '円';
$html =~ /$m1(.+)$m2/;
my $m3 = $+;
my @line = split(/円/,$m3,2);
my $Price = $line[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,1,5);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = 'カートに入れる';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# 楽天オンライン
sub rakuten{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName= shift;
my $domin= shift;
my $limit= shift;
my $store= '楽天オンライン';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','楽天オンライン')."\n";
#name
my $n1 = '<title>【楽天市場】【送料無料】 ';
my $n2 = '</title>';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/</,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
my $m1 = '<span itemprop="price" content="';
my $m2 = '" class="tax_postage">';
$html =~ /$m1(.+)$m2/;
my $m3 = $+;
my @line = split(/"/,$m3,2);
my $Price = $line[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,0,1);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = '在庫有り';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# オムニ7
sub omuni7{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName= shift;
my $domin= shift;
my $limit= shift;
my $store= 'オムニ7';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','オムニ7')."\n";
#name
my $n1 = '<title>オムニ7 - セブンネットショッピング|';
my $n2 = '通販</title>';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/通販/,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
my $m1 = '"sale_price_num_notax": "';
my $m2 = '円';
$html =~ /$m1(.+)$m2/;
my $m3 = $+;
my @line = split(/円/,$m3,2);
my $Price = $line[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,1,1);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = 'カートに入れる';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# mercari
sub mercari{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName= shift;
my $domin= shift;
my $limit= shift;
my $store= 'mercari';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','メルカリ')."\n";
#name
my $n1 = '<h2 class="item-name">';
my $n2 = '</h2>';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/</,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
my $m1 = '<span class="item-price bold">¥ ';
my $m2 = '</span>';
$html =~ /$m1(.+)$m2/;
my $m3 = $+;
my @line = split(/</,$m3,2);
my $Price = $line[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,0,0);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = '購入ページへ';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# YAMADA
sub Yamada{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName = shift;
my $domin = shift;
my $limit = shift;
my $store = 'ヤマダ電機';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','ヤマダ電機')."\n";
#Name
my $n1 = '<meta property="og:title" content="';
my $n2 = '"';
$html =~ /$n1(.+)$n2/;
my $n3 = $+;
my @n4 = split(/ /,$n3,2);
my $name = $n4[0];
print "[NAME]:";
print encode('utf-8',$name)."\n";
#Price
my $m1 = '<span class="highlight x-large">¥';
my $m2 = '</span>';
$html =~ /$m1(.+)$m2/;
my $m3 = $+;
my @line = split(/</,$m3,2);
my $Price = $line[0];
$Price = &split_price($Price);
# (row price, tax_id, percentage of point)
my $RP = &RP($Price,1,1);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA encode('utf-8',$Price);
print " excluding tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
$html =~ s/[\s ]+//g;
my $status;
my $i1 = 'カートに入れる';
if ($html =~ $i1){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# Nojima
sub Nojima{
my $num = shift;
my $url = shift;
my $iName = shift;
my $domin = shift;
my $limit = shift;
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW "ノジマ電気\n";
my $store = 'ノジマ電気';
# IE8のフリをする
my $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
# LWPを使ってサイトにアクセスし、HTMLの内容を取得する
my $ua = LWP::UserAgent->new('agent' => $user_agent);
my $res = $ua->get($url);
my $content = $res->content;
my $html = $content;
my $htmls = $html;
#Name
$html =~ s/[\s ]+//g;
print encode('utf-8','[STORE]:ノジマ電気')."\n";
$html =~ /<h1class="shouhinhcommodityName"itemprop="name">(.+)</;
my $st = $+;
my @str = split(/&/,$st,2);
my $name = $str[0];
print "[NAME]:";
print $name."\n";
#Price
my $moji2 = encode('utf-8','円<span');
$htmls =~ /<span class="pricenew">(.+)$moji2/; #<span class="pricenew">から円<spanまでの文字列(空白で区切れる)を抽出
my $Price = $+;
$Price = &split_price($Price);
my $RP = &RP($Price,0,8);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA $Price;
print " yen including tax.\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
#Inventory
my $status;
my $moji = encode('utf-8','カートに入れる');
if($htmls=~ $moji){
$status = 0;
print "[STATUS]:";
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}else{
$status = 8;
print "[STATUS]:";
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$Price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# TSUTAYA
sub TSUTAYA{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName = shift;
my $domin = shift;
my $limit = shift;
my $store = 'TSUTAYAオンライン';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
# domain
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','TSUTAYAオンライン')."\n";
# Name of item
$html =~ /_sc.pageName = "商品詳細:(.+)"/;
my $name = $+;
print "[NAME]:";
print encode('utf-8',$name)."\n";
# Price
$html =~ /<li>価格(税込):<span class="tolNote"><em class="nowrap">(.+)円/;
my $price = $+;
$price = &split_price($price);
my $RP = &RP($price,0,0.5);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA $price;
print " including tax\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
# Inventory
my $status;
$html =~ s/[\s ]+//g;#空白、タブ削除
print "[STATUS]:";
if ($html =~ /title="買い物かごへ"alt="買い物かごへ"/){
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
$status =0;
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<imgsrc="\/library\/img\/base\/ic\/btn_nostockL.png"alt="在庫なし"/){
$status =8;
print BOLD RED encode('utf-8','在庫なし')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /title="買い物かごへ(予約)"/){
$status =1;
print BOLD BRIGHT_GREEN encode('utf-8','予約受付中')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<p><spanclass="label_gray">完売しました<\/span><\/p>/){
$status =9;
print BOLD RED encode('utf-8','完売しました')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
#ヨドバシカメラ
sub Yodobashi{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName = shift;
my $domin = shift;
my $limit = shift;
my $store = 'ヨドバシカメラ';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','ヨドバシカメラ')."\n";
# Name of item
$html =~ /data-text="ヨドバシ.com - (.+)通販【全品無料配達】"/;
my $name = $+;
print "[NAME]:";
print encode('utf-8',$name)."\n";
# Price
$html =~ /id="js_scl_unitPrice">¥(.+)<\/span><span class="taxInfo">/;
my $price = $+;
$price = &split_price($price);
my $RP = &RP($price,0,10);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA $price;
print " including tax\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
# Inventory
my $status;
$html =~ s/[\s ]+//g;
print "[STATUS]:";
if ($html =~ /<spanclass="stockInfo"><spanclass="green">在庫あり/){
$status =0;
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<spanclass="stockInfo"><spanclass="green">在庫残少ご注文はお早めに!/){
$status =2;
print BOLD BRIGHT_GREEN encode('utf-8','在庫減少中')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<spanclass="stockInfo"><spanclass="red">お取り寄せ/){
$status =3;
print BOLD BRIGHT_GREEN encode('utf-8','お取り寄せ')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<spanid="salesInfoTxt"class="blue">ただいま予約受付中!/){
$status =1;
print BOLD BRIGHT_GREEN encode('utf-8','予約受付中')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<divclass="salesInfo"><p>予定数の販売を終了しました/){
$status =9;
print BOLD RED encode('utf-8','完売しました')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<divclass="salesInfo"><p>予約受付を終了しました/){
$status =10;
print BOLD RED encode('utf-8','予約受付終了');
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<divclass="salesInfo"><p>販売休止中です/){
print BOLD RED encode('utf-8','販売休止中')."\n";
$status =11;
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}
# ビックカメラ
sub Big_Camera{
my $num = shift;
my $html = shift;
my $url = shift;
my $iName = shift;
my $domin = shift;
my $limit = shift;
my $store = 'ビックカメラ';
print "[CATEGORY]:";
print BOLD CYAN "$iName\n";
print "[STORE]:";
print BOLD BRIGHT_YELLOW encode('utf-8','ビックカメラ')."\n";
# Name of item
$html =~ /data-item-name="(.+)"/;
my $name = $+;
print "[NAME]:";
print encode('utf-8',$name)."\n";
# Price
$html =~ /<li>税込:(.+)円/;
my $price = $+;
$price = &split_price($price);
$price = round($price - $price*0.08);
my $RP = &RP($price,1,5);
print "[PRICE]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA $price;
print " excluding tax\n";
print "[RealPrice]:";
print BOLD MAGENTA encode('utf-8','¥');
print BOLD MAGENTA round($RP)."\n";
# Inventory
my $status;
$html =~ s/[\s ]+//g;
print "[STATUS]:";
if ($html =~ /<p><spanclass="label_green">在庫あり<\/span><\/p>/){
$status =0;
print BOLD BRIGHT_GREEN encode('utf-8','在庫あり')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<p><spanclass="label_orange">お取り寄せ<\/span><\/p>/){
$status =3;
print BOLD BRIGHT_GREEN encode('utf-8','お取り寄せ')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<p><spanclass="label_blue">予約受付中<\/span><\/p>/){
$status =1;
print BOLD BRIGHT_GREEN encode('utf-8','予約受付中')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}elsif($html =~ /<p><spanclass="label_gray">完売しました<\/span><\/p>/){
$status =9;
print BOLD RED encode('utf-8','完売しました')."\n";
&save_file($num,$name,$price,$url,$store,$iName,$domin,$status,$RP,$limit);
}
}