postalcode

[sqlite3]駅名検索

ダウンロード - ekidata.jp駅名検索.zip


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#駅データ.jpのCSVを利用します
# https://ekidata.jp
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807


#############################
### クリップボードの中身取り出し
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "" as text
  end if
end if


#############################
###DBファイルへのパス
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
end tell
set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:true)
set ocidDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/stationfree.db")
set strDbFilePathURL to (ocidDBFilePathURL's |path|()) as text

set ocidLineDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/linefree.db")
set strLineDbFilePathURL to (ocidLineDBFilePathURL's |path|()) as text

set ocidPostDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/postno.db")
set strPostDbFilePathURL to (ocidPostDBFilePathURL's |path|()) as text


set strMes to ("名称や住所で検索 一部分でも可") as text
set strQueryText to strReadString as text

##############################
###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title "駅検索検索" default answer strQueryText buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
  if "OK" is equal to (button returned of recordResult) then
    set strReturnedText to (text returned of recordResult) as text
  else if (gave up of recordResult) is true then
return "時間切れです"
  else
return "キャンセル"
  end if
on error
  log "エラーしました"
return
end try
##############################
###戻り値整形
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
##############################
###ひらがなのみの場合はカタカナに
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ぁ-んー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
log ocidTextRange
set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
if (numMach as integer) = 1 then
  set ocidTransform to (refMe's NSStringTransformHiraganaToKatakana)
  set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:false)
end if
###数字がなければ全角に
set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:true)
##############################
##カタカナと漢字混在で検索方法が異なる
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ァ-ヶー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
set strSearchText to ocidTextM as text
if (numMach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*) FROM stationfree WHERE station_name LIKE '%" & strSearchText & "%' OR address LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*) FROM stationfree WHERE station_name LIKE '%" & strSearchText & "%' OR address LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
###検索結果の件数
set numQueryCnt to (do shell script strCommandText) as integer
##############################
###件数が100超える場合は中止を促す
if numQueryCnt > 100 then
  log "検索結果100件超です"
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ##1件の処理時間
  set numMin to (0.01 * numQueryCnt) as integer
  set strAlertMes to "検索結果100件超です(" & numQueryCnt & "件)\r継続すると結果表示まで約:" & numMin & "秒かかります" as text
  try
    set recordResponse to (display alert ("【選んでください】\r" & strAlertMes) buttons {"継続", "終了"} default button "継続" cancel button "終了" as informational giving up after 10) as record
  on error
    log "エラーしました"
return "キャンセルしました。処理を中止します。再度実行してください"
  end try
  if true is equal to (gave up of recordResponse) then
return "時間切れです。処理を中止します。再度実行してください"
  end if
else if numQueryCnt = 0 then
  log "検索結果0件です"
end if
####処理継続の場合はそのまま進む
if (numMach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM stationfree WHERE station_name LIKE '%" & strSearchText & "%' OR address LIKE '%" & strSearchText & "%' OR prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%' OR pref_and_city LIKE '%" & strSearchText & "%' OR city_and_town LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM stationfree WHERE station_name LIKE '%" & strSearchText & "%' OR address LIKE '%" & strSearchText & "%' OR prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%' OR pref_and_city LIKE '%" & strSearchText & "%' OR city_and_town LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
set strResponse to (do shell script strCommandText) as text
log strResponse

########################################
##コマンドの戻り値を改行でリストに
set AppleScript's text item delimiters to "\r"
set listResponse to every text item of strResponse
set AppleScript's text item delimiters to ""

########################################
##HTML 基本構造
###スタイル
set strStylle to "<style>#bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 80%;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 5px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[検索語句]" & strSearchText & "</title>" & strStylle & "</head><body>"
###ボディ
set strBody to ""
###最後
set strHtmlEndBody to "</body></html>"
###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
(ocidHTMLString's appendString:strHead)
#########
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption title=\"タイトル\">検索結果:" & strReturnedText & "</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"項目1\" scope=\"row\" > 連番 </th><th title=\"項目2\" scope=\"col\"> 駅名 </th><th title=\"項目3\" scope=\"col\"> 路線名 </th><th title=\"項目4\" scope=\"col\"> 住所 </th><th title=\"項目5\" scope=\"col\">リンク</th></tr></thead><tbody title=\"検索結果一覧\" >") as text
(ocidHTMLString's appendString:(strHTML))
set numLineNo to 1 as integer
repeat with itemLine in listResponse
  ###各行タブ区切りなのでタブでリストにする
  set AppleScript's text item delimiters to "\t"
  set listLineText to every text item of itemLine
  set AppleScript's text item delimiters to ""
  ###必要な項目を取得
  set strLineCode to (item 6 of listLineText) as text
  set strCommandText to ("/usr/bin/sqlite3 \"" & strLineDbFilePathURL & "\" -tabs \"SELECT line_name FROM linefree WHERE line_cd = '" & strLineCode & "';\"") as text
  log strCommandText
  set strLineName to (do shell script strCommandText) as text
  
  set strPostNO to (item 3 of listLineText) as text
  set strAddText to (item 9 of listLineText) as text
  
  set strLong to (item 10 of listLineText) as text
  set strLat to (item 11 of listLineText) as text
  ###リンク生成
  
  ###リンク1
  set strMapURL to ("https://www.navitime.co.jp/maps/aroundResult?lat=" & strLat & "&lon=" & strLong & "")
  set strLINK1 to "<a href=\"" & strMapURL & "\" target=\"_blank\">Navitime Map</a>"
  ###リンク2
  set strMapURL to ("https://map.yahoo.co.jp/place?lat=" & strLat & "&lon=" & strLong & "&zoom=15&maptype=trainRoutes")
  set strLINK2 to "<a href=\"" & strMapURL & "\" target=\"_blank\">Yahoo Map</a>"
  ###リンク3
  set strMapURL to ("https://maps.gsi.go.jp/vector/#15/" & strLat & "/" & strLong & "/&ls=vstd&disp=1&d=l")
  set strLINK3 to "<a href=\"" & strMapURL & "\" target=\"_blank\">Gsi vector Map</a>"
  ###リンク4
  set strMapURL to ("https://www.jma.go.jp/bosai/nowc/#lat:" & strLat & "/lon:" & strLong & "/zoom:15/")
  set strLINK4 to "<a href=\"" & strMapURL & "\" target=\"_blank\">Jma Map</a>"
  ###リンク5
  set strMapURL to ("http://maps.apple.com/?ll=" & strLat & "," & strLong & "")
  set strLINK5 to "<a href=\"" & strMapURL & "\" target=\"_blank\">Apple Map</a>"
  ##
  
  set strLINK to "" & strLINK1 & "&nbsp;|&nbsp;" & strLINK2 & "&nbsp;|&nbsp;" & strLINK3 & "&nbsp;|&nbsp;" & strLINK4 & "&nbsp;|&nbsp;" & strLINK5 & ""
  ###HTMLにして
  set strHTML to ("<tr><th title=\"項番1\" scope=\"row\">" & numLineNo & "</th><td title=\"項目2\"><b>" & strPostNO & "</b></td><td title=\"項目3\">" & strLineName & "</td><td title=\"項目4\">" & strAddText & "</td><td title=\"項目5\">" & strLINK & "</td></tr>") as text
(ocidHTMLString's appendString:(strHTML))
  set numLineNo to numLineNo + 1 as integer
end repeat

set strHTML to ("</tbody><tfoot><tr><th colspan=\"6\" title=\"フッター表の終わり\" scope=\"row\">ekidata.jp</th></tr></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))

###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###パス

set strFileName to (strSearchText & ".html") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
(*
tell application "TextEdit"
activate
open file aliasFilePath
end tell
*)
tell application "Safari"
  activate
  open file aliasFilePath
end tell






|

郵便番号検索 v2

都道府県+市区町村名に対応

ダウンロード - 郵便番号検索v2.zip


【スクリプトエディタで開く】|

#!/bin/bash
# V2 都道府県市区町村を追加
#com.cocolog-nifty.quicktimer.icefloe
##################################################
###設定項目 CSVのファイル名
STR_CSV_FILE_NAME="utf_all.csv"
### path to me
SCRIPT_PATH="${BASH_SOURCE[0]}"
/bin/echo "このスクリプトのパス $SCRIPT_PATH"
STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$SCRIPT_PATH")
/bin/echo "コンテナディレクトリ $STR_CONTAINER_DIR_PATH"
STR_DATA_DIR_PATH="$STR_CONTAINER_DIR_PATH/data"
/bin/mkdir -p "$STR_DATA_DIR_PATH"
/bin/echo "データ格納ディレクトリ $STR_DATA_DIR_PATH"
STR_CSV_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME"
/bin/echo "CSVのファイルパス $STR_CSV_FILE_PATH"
STR_IMPORT_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME.import.csv"
/bin/echo "SQLインポート用CSVの書き出しパス $STR_IMPORT_FILE_PATH"
STR_DB_FILE_PATH="$STR_DATA_DIR_PATH/postno.db"
/bin/echo "SQLDBのパス $STR_DB_FILE_PATH"
##################################################
###古いデータは削除する
/usr/bin/touch "$STR_IMPORT_FILE_PATH"
/usr/bin/touch "$STR_DB_FILE_PATH"
/usr/bin/touch "$STR_CSV_FILE_PATH"
/bin/rm  "$STR_IMPORT_FILE_PATH"
/bin/rm  "$STR_DB_FILE_PATH"
/bin/rm  "$STR_CSV_FILE_PATH"
##################################################
STR_URL="https://www.post.japanpost.jp/zipcode/dl/utf/zip/utf_all.zip"
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ $USER_TEMP_DIR"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --connect-timeout 20; then
  /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --http1.1 --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました"
    exit 1
  fi
fi
/bin/echo "ダウンロードしたZIPファイル $USER_TEMP_DIR/utf_all.zip"
##################################################
###解凍
/usr/bin/cd "$STR_DATA_DIR_PATH"
/usr/bin/bsdtar -xzvf "$USER_TEMP_DIR/utf_all.zip" -C "$STR_DATA_DIR_PATH"
/bin/echo "ダウンロードデータ解凍OK"
##################################################
###クオテーション除去
STR_TMP_FILE_PATH="$USER_TEMP_DIR/$STR_CSV_FILE_NAME.tmp.csv"
/usr/bin/sed 's/"//g' "$STR_CSV_FILE_PATH" > "$STR_TMP_FILE_PATH"
###改行変更
/usr/bin/sed 's/\r$//' "$STR_TMP_FILE_PATH" > "$STR_IMPORT_FILE_PATH"
/bin/echo "データ整形終了"
##################################################
###1行目挿入 この処理は不要だった
## STR_HEADER_TEXT="code,old_no,p_no,prefecture_kana,city_kana,town_kana,prefecture,city,town,more,aza,cho,contain,update,change"
## /usr/bin/touch "$STR_IMPORT_FILE_PATH"
## /bin/echo "$STR_HEADER_TEXT" > "$STR_IMPORT_FILE_PATH"
## /bin/cat "$STR_TMPB_FILE_PATH" >> "$STR_IMPORT_FILE_PATH"
##################################################
/bin/echo "データインポート開始"
###インポート DB作成
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
CREATE TABLE postalcode (code TEXT,old_no TEXT,p_no TEXT,prefecture_kana TEXT,city_kana TEXT,town_kana TEXT,prefecture TEXT,city TEXT,town TEXT,more INTEGER,azamore INTEGER,chomore INTEGER,containmore INTEGER,updatemore INTEGER,changemore INTEGER);
.mode csv
.import "$STR_IMPORT_FILE_PATH" postalcode
EOF
/bin/echo "データインポート終了"
sleep 2
/bin/echo "都道府県+地区町村作成開始"
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
ALTER TABLE postalcode ADD COLUMN pref_and_city TEXT;
EOF
/bin/echo "都道府県+地区町村作成開始 OK"

/bin/echo "都道府県+地区町村 データ結合開始"
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
UPDATE postalcode SET pref_and_city = prefecture || city;
EOF
/bin/echo "都道府県+地区町村 データ結合開始 ok"


/bin/echo "処理終了しました"
exit 0



【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# V2 都道府県市区町村を追加
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807



#############################
### クリップボードの中身取り出し
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "" as text
  end if
end if



#############################
###DBファイルへのパス
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
end tell
set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:true)
set ocidDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/postno.db")
set strDbFilePathURL to (ocidDBFilePathURL's |path|()) as text

set strMes to ("住所で検索 一部分でも可\r神奈川とかで指定すると検索結果が多くなります") as text
set strQueryText to strReadString as text

##############################
###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title "郵便番号検索" default answer strQueryText buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
  if "OK" is equal to (button returned of recordResult) then
    set strReturnedText to (text returned of recordResult) as text
  else if (gave up of recordResult) is true then
return "時間切れです"
  else
return "キャンセル"
  end if
on error
  log "エラーしました"
return
end try
##############################
###戻り値整形
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
##############################
###ひらがなのみの場合はカタカナに
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ぁ-んー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
log ocidTextRange
set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
if (numMach as integer) = 1 then
  set ocidTransform to (refMe's NSStringTransformHiraganaToKatakana)
  set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:false)
end if
###数字がなければ全角に
set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:true)
##############################
##カタカナと漢字混在で検索方法が異なる
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ァ-ヶー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
set strSearchText to ocidTextM as text
if (numMach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*) FROM postalcode WHERE prefecture_kana LIKE '%" & strSearchText & "%' OR city_kana LIKE '%" & strSearchText & "%' OR town_kana LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*) FROM postalcode WHERE prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%' OR pref_and_city LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
###検索結果の件数
set numQueryCnt to (do shell script strCommandText) as integer
##############################
###件数が100超える場合は中止を促す
if numQueryCnt > 100 then
  log "検索結果100件超です"
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ##1件の処理時間
  set numMin to (0.01 * numQueryCnt) as integer
  set strAlertMes to "検索結果100件超です(" & numQueryCnt & "件)\r継続すると結果表示まで約:" & numMin & "秒かかります" as text
  try
    set recordResponse to (display alert ("【選んでください】\r" & strAlertMes) buttons {"継続", "終了"} default button "継続" cancel button "終了" as informational giving up after 10) as record
  on error
    log "エラーしました"
return "キャンセルしました。処理を中止します。再度実行してください"
  end try
  if true is equal to (gave up of recordResponse) then
return "時間切れです。処理を中止します。再度実行してください"
  end if
else if numQueryCnt = 0 then
  log "検索結果0件です"
end if
####処理継続の場合はそのまま進む
if (numMach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture_kana LIKE '%" & strSearchText & "%' OR city_kana LIKE '%" & strSearchText & "%' OR town_kana LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%' OR pref_and_city LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
set strResponse to (do shell script strCommandText) as text


########################################
##コマンドの戻り値を改行でリストに
set AppleScript's text item delimiters to "\r"
set listResponse to every text item of strResponse
set AppleScript's text item delimiters to ""

########################################
##HTML 基本構造
###スタイル
set strStylle to "<style>#bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 80%;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 5px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[検索語句]" & strSearchText & "</title>" & strStylle & "</head><body>"
###ボディ
set strBody to ""
###最後
set strHtmlEndBody to "</body></html>"
###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
(ocidHTMLString's appendString:strHead)
#########
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption title=\"タイトル\">検索結果:" & strReturnedText & "</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"項目1\" scope=\"row\" > 連番 </th><th title=\"項目2\" scope=\"col\"> 郵便番号 </th><th title=\"項目3\" scope=\"col\"> 住所 </th><th title=\"項目4\" scope=\"col\"> 読み </th><th title=\"項目5\" scope=\"col\">団体コード</th><th title=\"項目6\" scope=\"col\">リンク</th></tr></thead><tbody title=\"検索結果一覧\" >") as text
(ocidHTMLString's appendString:(strHTML))
set numLineNo to 1 as integer
repeat with itemLine in listResponse
  ###各行タブ区切りなのでタブでリストにする
  set AppleScript's text item delimiters to "\t"
  set listLineText to every text item of itemLine
  set AppleScript's text item delimiters to ""
  ###必要な項目を取得
  set strCityCode to (item 1 of listLineText) as text
  set strPostNo to (item 3 of listLineText) as text
  set strAddText to ((item 7 of listLineText) & (item 8 of listLineText) & (item 9 of listLineText)) as text
  set strKana to ((item 4 of listLineText) & (item 5 of listLineText) & (item 6 of listLineText)) as text
  ###リンク生成
  set strLinkURL to ("https://www.post.japanpost.jp/cgi-zip/zipcode.php?zip=" & strPostNo & "")
  set strMapURL to ("https://www.google.com/maps/search/郵便番号+" & strPostNo & "")
  set strMapAppURL to ("http://maps.apple.com/?q=郵便番号+" & strPostNo & "")
  set strLINK to "<a href=\"" & strLinkURL & "\" target=\"_blank\">郵政</a>&nbsp;|&nbsp;<a href=\"" & strMapURL & "\" target=\"_blank\">Google</a>&nbsp;|&nbsp;<a href=\"" & strMapAppURL & "\" target=\"_blank\">Map</a>"
  ###HTMLにして
  set strHTML to ("<tr><th title=\"項番1\" scope=\"row\">" & numLineNo & "</th><td title=\"項目2\"><b>" & strPostNo & "</b></td><td title=\"項目3\">" & strAddText & "</td><td title=\"項目4\"><small>" & strKana & "</small></td><td title=\"項目5\">" & strCityCode & "</td><td title=\"項目6\">" & strLINK & "</td></tr>") as text
(ocidHTMLString's appendString:(strHTML))
  set numLineNo to numLineNo + 1 as integer
end repeat

set strHTML to ("</tbody><tfoot><tr><th colspan=\"6\" title=\"フッター表の終わり\" scope=\"row\">post.japanpost.jp</th></tr></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))

###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###パス

set strFileName to (strSearchText & ".html") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
(*
tell application "TextEdit"
activate
open file aliasFilePath
end tell
*)
tell application "Safari"
  activate
  open file aliasFilePath
end tell






|

郵便番号検索

ダウンロード - 郵便番号検索v1.zip


DB検索 結果をHTMLで表示

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# DB検索用
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807


#############################
###DBファイルへのパス
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
end tell
set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:true)
set ocidDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("bin/data/postno.db")
set strDbFilePathURL to (ocidDBFilePathURL's |path|()) as text
#############################
### クリップボードの中身取り出し
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "" as text
  end if
end if
##############################
###ダイアログ
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
set strMes to ("住所で検索 一部分でも可\r神奈川とかで指定すると検索結果が多くなります")
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title "郵便番号検索" default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
on error
  log "エラーしました"
return
end try

if "OK" is equal to (button returned of recordResult) then
  set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else
return "キャンセル"
end if
##############################
###戻り値整形
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
##############################
###ひらがなのみの場合はカタカナに
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ぁ-んー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
log ocidTextRange
set numPach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
if (numPach as integer) = 1 then
  set ocidTransform to (refMe's NSStringTransformHiraganaToKatakana)
  set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:false)
end if
###数字がなければ全角に
set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:true)
########################################
##カタカナと漢字混在で検索方法が異なる
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ァ-ヶー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
set numPach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
set strSearchText to ocidTextM as text
if (numPach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture_kana LIKE '%" & strSearchText & "%' OR city_kana LIKE '%" & strSearchText & "%' OR town_kana LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
set strResponse to (do shell script strCommandText) as text


########################################
##
set AppleScript's text item delimiters to "\r"
set listResponse to every text item of strResponse
set AppleScript's text item delimiters to ""

########################################
##HTML 基本構造
###スタイル
set strStylle to "<style>#bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 80%;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 5px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[検索語句]" & strSearchText & "</title>" & strStylle & "</head><body>"
###ボディ
set strBody to ""
###最後
set strHtmlEndBody to "</body></html>"
###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
(ocidHTMLString's appendString:strHead)
#########
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption title=\"タイトル\">検索結果:" & strReturnedText & "</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"項目1\" scope=\"row\" > 連番 </th><th title=\"項目2\" scope=\"col\"> 郵便番号 </th><th title=\"項目3\" scope=\"col\"> 住所 </th><th title=\"項目4\" scope=\"col\"> 読み </th><th title=\"項目5\" scope=\"col\">団体コード</th><th title=\"項目6\" scope=\"col\">リンク</th></tr></thead><tbody title=\"検索結果一覧\" >") as text
set numLineNo to 1 as integer
repeat with itemLine in listResponse
  set AppleScript's text item delimiters to "\t"
  set listLineText to every text item of itemLine
  set AppleScript's text item delimiters to ""
  
  set strCityCode to (item 1 of listLineText) as text
  set strPostNo to (item 3 of listLineText) as text
  set strAddText to ((item 7 of listLineText) & (item 8 of listLineText) & (item 9 of listLineText)) as text
  set strKana to ((item 4 of listLineText) & (item 5 of listLineText) & (item 6 of listLineText)) as text
  
  set strLinkURL to ("https://www.post.japanpost.jp/cgi-zip/zipcode.php?zip=" & strPostNo & "")
  set strMapURL to ("https://www.google.com/maps/search/郵便番号+" & strPostNo & "")
  set strMapAppURL to ("http://maps.apple.com/?q=郵便番号+" & strPostNo & "")
  set strLINK to "<a href=\"" & strLinkURL & "\" target=\"_blank\">郵政</a>&nbsp;|&nbsp;<a href=\"" & strMapURL & "\" target=\"_blank\">Google</a>&nbsp;|&nbsp;<a href=\"" & strMapAppURL & "\" target=\"_blank\">Map</a>"
  
  set strHTML to (strHTML & "<tr><th title=\"項番1\" scope=\"row\">" & numLineNo & "</th><td title=\"項目2\"><b>" & strPostNo & "</b></td><td title=\"項目3\">" & strAddText & "</td><td title=\"項目4\"><small>" & strKana & "</small></td><td title=\"項目5\">" & strCityCode & "</td><td title=\"項目6\">" & strLINK & "</td></tr>") as text
  
  set numLineNo to numLineNo + 1 as integer
end repeat


set strHTML to (strHTML & "</tbody><tfoot><tr><th colspan=\"6\" title=\"フッター表の終わり\" scope=\"row\">post.japanpost.jp</th></tr></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))

###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###パス

set strFileName to (strSearchText & ".html") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
(*
tell application "TextEdit"
activate
open file aliasFilePath
end tell
*)
tell application "Safari"
  activate
  open file aliasFilePath
end tell

DB作成

【スクリプトエディタで開く】|

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
##################################################
###設定項目 CSVのファイル名
STR_CSV_FILE_NAME="utf_all.csv"
### path to me
SCRIPT_PATH="${BASH_SOURCE[0]}"
/bin/echo "このスクリプトのパス $SCRIPT_PATH"
STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$SCRIPT_PATH")
/bin/echo "コンテナディレクトリ $STR_CONTAINER_DIR_PATH"
STR_DATA_DIR_PATH="$STR_CONTAINER_DIR_PATH/data"
/bin/mkdir -p "$STR_DATA_DIR_PATH"
/bin/echo "データ格納ディレクトリ $STR_DATA_DIR_PATH"
STR_CSV_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME"
/bin/echo "CSVのファイルパス $STR_CSV_FILE_PATH"
STR_IMPORT_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME.import.csv"
/bin/echo "SQLインポート用CSVの書き出しパス $STR_IMPORT_FILE_PATH"
STR_DB_FILE_PATH="$STR_DATA_DIR_PATH/postno.db"
/bin/echo "SQLDBのパス $STR_DB_FILE_PATH"
##################################################
###古いデータは削除する
/usr/bin/touch "$STR_IMPORT_FILE_PATH"
/usr/bin/touch "$STR_DB_FILE_PATH"
/usr/bin/touch "$STR_CSV_FILE_PATH"
/bin/rm  "$STR_IMPORT_FILE_PATH"
/bin/rm  "$STR_DB_FILE_PATH"
/bin/rm  "$STR_CSV_FILE_PATH"
##################################################
STR_URL="https://www.post.japanpost.jp/zipcode/dl/utf/zip/utf_all.zip"
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ $USER_TEMP_DIR"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --connect-timeout 20; then
  /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --http1.1 --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました"
    exit 1
  fi
fi
/bin/echo "ダウンロードしたZIPファイル $USER_TEMP_DIR/utf_all.zip"
##################################################
###解凍
/usr/bin/cd "$STR_DATA_DIR_PATH"
/usr/bin/bsdtar -xzvf "$USER_TEMP_DIR/utf_all.zip" -C "$STR_DATA_DIR_PATH"
/bin/echo "ダウンロードデータ解凍OK"
##################################################
###クオテーション除去
STR_TMP_FILE_PATH="$USER_TEMP_DIR/$STR_CSV_FILE_NAME.tmp.csv"
/usr/bin/sed 's/"//g' "$STR_CSV_FILE_PATH" > "$STR_TMP_FILE_PATH"
###改行変更
/usr/bin/sed 's/\r$//' "$STR_TMP_FILE_PATH" > "$STR_IMPORT_FILE_PATH"
/bin/echo "データ整形終了"
##################################################
###1行目挿入 この処理は不要だった
## STR_HEADER_TEXT="code,old_no,p_no,prefecture_kana,city_kana,town_kana,prefecture,city,town,more,aza,cho,contain,update,change"
## /usr/bin/touch "$STR_IMPORT_FILE_PATH"
## /bin/echo "$STR_HEADER_TEXT" > "$STR_IMPORT_FILE_PATH"
## /bin/cat "$STR_TMPB_FILE_PATH" >> "$STR_IMPORT_FILE_PATH"
##################################################
/bin/echo "データインポート開始"
###インポート DB作成
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
CREATE TABLE postalcode (code TEXT,old_no TEXT,p_no TEXT,prefecture_kana TEXT,city_kana TEXT,town_kana TEXT,prefecture TEXT,city TEXT,town TEXT,more INTEGER,azamore INTEGER,chomore INTEGER,containmore INTEGER,updatemore INTEGER,changemore INTEGER);
.mode csv
.import "$STR_IMPORT_FILE_PATH" postalcode
EOF
/bin/echo "データインポート終了"
/bin/echo "処理終了しました"
exit 0


|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom