Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  3.  
  4. // --------------------------------------------
  5. // 対象日時チェック(コマンドライン引数かURLパラメータか)
  6. $target_date = $_REQUEST['$target_date'] ? $_REQUEST['$target_date'] : ($argv[1] ? $argv[1] : date('Ymd'));
  7. $year = substr($target_date,0,4);
  8. $month = substr($target_date,4,2);
  9. $day = substr($target_date,6,2);
  10. if (false === checkdate($month,$day,$year)){
  11. echo "Incorrect date and time\n";
  12. exit;
  13. }
  14.  
  15. // --------------------------------------------
  16. // 履歴データファイル(環境毎に適宜変更を)
  17. $dbfile = dirname(dirname(dirname(dirname(dirname(__FILE__)))))."/AppData/Local/Google/Chrome/user_data/Default/History";
  18.  
  19. // --------------------------------------------
  20. // 既に日報生成済みならやらない
  21. if ( file_exists(dirname(__FILE__).'/report_'.$year.$month.$day.'.txt') ){
  22. # echo "report exists...Done\n";
  23. # exit;
  24. }
  25.  
  26. // --------------------------------------------
  27. // メールボックス接続
  28. $mailbox="{xxxxxxxxxx}INBOX";
  29. $user="xxxxxxxxxx";
  30. $pass="xxxxxxxxxx";
  31.  
  32. $mbox = imap_open( $mailbox, $user ,$pass) or die("接続エラー\n");
  33.  
  34. // --------------------------------------------
  35. // メールボックスのメッセージ数を取得
  36. $cnt=imap_num_recent($mbox);
  37. $count = imap_num_msg($mbox);
  38.  
  39. // とりあえず100件
  40. for($idx=0;$idx<100;$idx++){
  41. $head = imap_header($mbox, $count - $idx);
  42. // 受信日時
  43. $check_date =strtotime($head->date);
  44.  
  45. // 対象日時(定時の17:30以降の時間帯に地下鉄駅を利用したログを監視)
  46. $min = mktime(17,30,0,$month,$day,$year);
  47. $max = mktime(23,59,59,$month,$day,$year);
  48.  
  49. if ( $min <= $check_date AND $max >= $check_date) {
  50. // IFTTTから送信されてきた件名「通勤メール」の有無をチェック
  51. $subject = mb_decode_mimeheader($head->subject);
  52. if (preg_match("/通勤メール/",$subject)){
  53.  
  54. // 帰宅した!日報生成
  55. // SqliteでChromeの履歴データにアクセス
  56. $db = new SQLite3($dbfile);
  57. $sql= <<<__SQL__
  58. SELECT
  59. datetime(last_visit_time / 1000000 + (strftime('%s', '1601-01-01') + (60*60*9)), 'unixepoch') as date,
  60. title,
  61. url
  62. FROM urls
  63. WHERE date(last_visit_time / 1000000 + (strftime('%s', '1601-01-01') + (60*60*9)),'unixepoch') = '$year-$month-$day';
  64. __SQL__;
  65. $results = $db->query($sql);
  66. while ($row = $results->fetchArray()) {
  67. list($protocol,$dummy,$domain) = explode('/',$row['url']);
  68. // ドメイン毎に集計
  69. $group[$domain][$row['date']]=$row['title'];
  70. }
  71.  
  72. foreach($group as $domain => $value){
  73. $report .= "・".$domain.PHP_EOL;
  74. foreach($value as $date => $title){
  75. $report .= " ".$date.' '.$title.PHP_EOL;
  76. }
  77. }
  78. $db->close();
  79.  
  80. $report = <<<__TEXT__
  81. --- 業務内容 ---
  82. $report
  83.  
  84. --- 感想 / 今日の一言
  85. お疲れ様でした!!!
  86.  
  87. __TEXT__;
  88.  
  89. file_put_contents(dirname(__FILE__).'/report_'.$year.$month.$day.'.txt',$report);
  90. break;
  91. }
  92. }
  93. }
  94. imap_close($mbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement