Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFファイルをgrep対象にする #94

Merged
merged 5 commits into from Apr 18, 2020
Merged

PDFファイルをgrep対象にする #94

merged 5 commits into from Apr 18, 2020

Conversation

515hikaru
Copy link
Collaborator

@515hikaru 515hikaru commented Apr 18, 2020

closes #5

やったこと

  • grep.sh の実装の関数化(やりすぎている節がある)
  • PDF を grep の対象にする

残タスク

  • PDF ファイルが rename される都合元のURLを保持できていない
    • pdftotextfoo.pdffoo.txt にするため
    • とはいえクロールしたファイルに上書きをするのも怖いのでどうしたものか考え中
  • テストの追加( sanitize_grep_result とか )

@515hikaru
Copy link
Collaborator Author

515hikaru commented Apr 18, 2020

pdftotext ./www-data/www.cao.go.jp/yosan/soshiki/r02/zei/zeisei_shiryor02.pdf 
Syntax Error: Expected the optional content group list, but wasn't able to find it, or it isn't an Array
  • でもメッセージは出てるのに変換はできている模様(よくわからん)
    • 終了コードも0

@515hikaru
Copy link
Collaborator Author

PDF ファイルが rename される都合元のURLを保持できていない
pdftotext が foo.pdf を foo.txt にするため
とはいえクロールしたファイルに上書きをするのも怖いのでどうしたものか考え中

一旦 pdf.txt みたいな拡張子にしてしまって、grep の結果に現れる .pdf.txt:.pdf: に書き換えるという強引な技しか思いつかない。

@515hikaru 515hikaru marked this pull request as ready for review April 18, 2020 08:34
Copy link
Member

@yuiseki yuiseki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストも書かれているし、よさそうです!ありがとうございます

Copy link
Collaborator

@tamakiii tamakiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

まだアプリケーションの仕様がよくわかってないですが、

  • 処理対象のファイルを xargs で取って処理する形なら set +e set -e をしなくてもよくなるかも?
    • list-grep-target.sh | xargs grep.sh > ./tmp/grep_コロナ_$word.txt.tmp
    • イメージでしかないので変なこと言ってたら 🙏
  • $INTERMEDIATE_FILE_PATH を各関数に引数で渡すといい感じになるかも?
    • 実装上問題はなさそう

test/grep_test.sh Show resolved Hide resolved
test/grep_test.sh Show resolved Hide resolved
@yuiseki yuiseki merged commit 8f62fc2 into master Apr 18, 2020
@yuiseki yuiseki deleted the feature/grep-pdf branch April 18, 2020 10:07
@tamakiii
Copy link
Collaborator

こんな感じで grep の exit code 無視できるかも?

#!/usr/bin/env bash -eu

hello() {
  echo "hoge" | grep "oga" > /dev/stdout || true
}

world() {
  echo "world";
  # rm file_does_not_exists.txt
}

main() {
  hello
  world
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
	main $@
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDFファイルの文字列も検索したい
3 participants