各種環境確認

OS

system-release

$ cat /etc/system-release
Amazon Linux AMI release 2017.03

Linux Kernelのバージョン

$ uname -r
4.9.32-15.41.amzn1.x86_64

$ uname -a
Linux ip-172-31-0-1 4.9.62-10.57.amzn2.x86_64

MacOS

$ sw_vers

CPU

$ cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 63
model name	: Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
stepping	: 2
microcode	: 0x25
cpu MHz		: 2394.500
cache size	: 30720 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs		:
bogomips	: 4789.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

メモリ

cat /proc/meminfo
MemTotal:        2049564 kB
MemFree:          466560 kB
MemAvailable:    1207500 kB
Buffers:          156492 kB
Cached:           685840 kB
SwapCached:            0 kB
Active:          1004176 kB
Inactive:         481820 kB
Active(anon):     643664 kB
Inactive(anon):      336 kB
Active(file):     360512 kB
Inactive(file):   481484 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                80 kB
Writeback:             0 kB
AnonPages:        643680 kB
Mapped:            31200 kB
Shmem:               344 kB
Slab:              73596 kB
SReclaimable:      61400 kB
SUnreclaim:        12196 kB
KernelStack:        4508 kB
PageTables:         6196 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1024780 kB
Committed_AS:    1914348 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       12288 kB
DirectMap2M:     2084864 kB

カーネル

$ cat /proc/version
Linux version 4.9.20-11.31.amzn1.x86_64 (mockbuild@gobi-build-64012) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Apr 13 01:53:57 UTC 2017

yum

$ yum version
Loaded plugins: priorities, update-motd, upgrade-helper
Installed: 2017.03/x86_64                                422:4171da904604225a8027284a2d61d2c128d56970
Group-Installed: yum                                       8:1a12bb5ccbfe54e3c1207ecf33c288ba8b7545fe
version

EPEL

$ rpm -qa | grep epel
epel-release-6-8.9.amzn1.noarch

Apache

$ httpd -v
Server version: Apache/2.2.32 (Unix)
Server built:   Jun 21 2017 19:11:57

# 詳細確認
$ httpd -V
Server version: Apache/2.2.32 (Unix)
Server built:   Jun 21 2017 19:11:57
Server's Module Magic Number: 20051115:42
Server loaded:  APR 1.5.1, APR-Util 1.4.1
Compiled using: APR 1.5.1, APR-Util 1.4.1
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Tomcat

AWS ElasticBeanstalk

$ /usr/sbin/tomcat7 version
Server version: Apache Tomcat/7.0.77
Server built:   Apr 19 2017 22:36:10 UTC
Server number:  7.0.77.0
OS Name:        Linux
OS Version:     4.9.20-11.31.amzn1.x86_64
Architecture:   amd64
JVM Version:    1.7.0_131-mockbuild_2017_02_15_02_03-b00
JVM Vendor:     Oracle Corporation

Amazon Linux

$ /opt/tomcat/bin/version.sh
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/java/default
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID:    /var/run/tomcat.pid
Server version: Apache Tomcat/8.0.44
Server built:   May 10 2017 17:21:09 UTC
Server number:  8.0.44.0
OS Name:        Linux
OS Version:     4.9.27-14.31.amzn1.x86_64
Architecture:   amd64
JVM Version:    1.8.0_131-b11
JVM Vendor:     Oracle Corporation

Maven

$ mvn --version
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T04:39:06+09:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre
Default locale: ja_JP, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"

MySQL

mysql> select version();
+------------+
| version()  |
+------------+
| 5.5.46-log |
+------------+
1 row in set (0.01 sec)

Postfix

$ /usr/sbin/postconf | grep mail_version

Java

$ java -version
java version "1.7.0_141"
OpenJDK Runtime Environment (amzn-2.6.10.1.73.amzn1-x86_64 u141-b02)
OpenJDK 64-Bit Server VM (build 24.141-b02, mixed mode)

PHP

$ php -v
PHP 5.3.29 (cli) (built: May 12 2015 22:42:19)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies

Python

$ python -V
Python 2.7.12

Shell

現在のShell

$ echo $SHELL
/bin/zsh

利用可能なShell

$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

Google Places API

PythonでGooglePlacesAPIを利用してみる。

from googleplaces import GooglePlaces, types, lang, json

YOUR_API_KEY   = 'AIzaSyDMiOg7qvttHyeAarDLX2Mxacmrr3soqD4'
google_places  = GooglePlaces(YOUR_API_KEY)

# You may prefer to use the text_search API, instead.
query_result = google_places.nearby_search(
    language   = 'ja',
    location   = '東京, 日本',
    # keyword  = '青百合',
    # radius   = 20000,
    types      = 'food | cafe | bar'
)

if query_result.has_attributions:
    print(query_result.has_attributions)
for place in query_result.places:
    line = []
    geo_name = ''
    location = ''
    tel = ''

    place.get_details()

    # プレイス名称
    geo_name = place.name
    if geo_name == None :
        line.append('NULL')
    else :
        line.append(geo_name)

    # 緯度経度
    location = place.geo_location
    lat = str(location["lat"])
    lng = str(location["lng"])

    if lat == None :
        line.append('NULL')
    else :
        line.append(lat)

    if lng == None :
        line.append('NULL')
    else :
        line.append(lng)

    # 電話番号
    tel = place.local_phone_number
    if tel == None :
        line.append('NULL')
    else :
        line.append(tel)

    print(line)

▼ 出力結果

/Users/xxx/.pyenv/versions/3.4.5/bin/python "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 52233 --file /Users/xxx/Dropbox/Sites/pythonTest/googlePlacesApi.py
warning: Debugger speedups using cython not found. Run '"/Users/aaa/.pyenv/versions/3.4.5/bin/python" "/Applications/PyCharm CE.app/Contents/helpers/pydev/setup_cython.py" build_ext --inplace' to build.
pydev debugger: process 38426 is connecting

Connected to pydev debugger (build 163.9735.8)
['東京', {'lat': Decimal('35.7090259'), 'lng': Decimal('139.7319925')}, None]
['ホテル椿山荘東京', {'lat': Decimal('35.7121974'), 'lng': Decimal('139.726076')}, '03-3943-1111']
['ホテルグランドパレス', {'lat': Decimal('35.6973265'), 'lng': Decimal('139.7504322')}, '03-3264-1111']
['庭のホテル東京', {'lat': Decimal('35.700622'), 'lng': Decimal('139.75667')}, '03-3293-0028']
['Hotel Higashi-Shinjuku イーホテル東新宿', {'lat': Decimal('35.6977609'), 'lng': Decimal('139.7071375')}, '03-5287-3588']
['ホテルリステル新宿', {'lat': Decimal('35.692872'), 'lng': Decimal('139.711396')}, '03-3350-0123']
['Citadines Shinjuku Tokyo', {'lat': Decimal('35.6910489'), 'lng': Decimal('139.7131214')}, '03-5379-7208']
['東急ステイ水道橋', {'lat': Decimal('35.70081589999999'), 'lng': Decimal('139.7565031')}, '03-3293-0109']
['エースイン新宿', {'lat': Decimal('35.6925119'), 'lng': Decimal('139.7243036')}, '03-3350-6655']
['東横INN新宿歌舞伎町', {'lat': Decimal('35.69732310000001'), 'lng': Decimal('139.7043361')}, '03-5155-1045']
['ホテル機山館', {'lat': Decimal('35.7080429'), 'lng': Decimal('139.7597332')}, '03-3812-1211']
['シタディーンセントラル新宿東京', {'lat': Decimal('35.6944294'), 'lng': Decimal('139.7042888')}, '03-3200-0220']
['ホテルたてしな', {'lat': Decimal('35.692288'), 'lng': Decimal('139.709014')}, '03-3350-5271']
['ホテルメトロポリタン', {'lat': Decimal('35.7283502'), 'lng': Decimal('139.7079847')}, '03-3980-1111']
['ホテルシェーナ', {'lat': Decimal('35.69599540000001'), 'lng': Decimal('139.704277')}, '03-3232-6711']
['YMCAアジア青少年センター', {'lat': Decimal('35.7000021'), 'lng': Decimal('139.7585113')}, '03-3233-0611']
['新宿区', {'lat': Decimal('35.6938401'), 'lng': Decimal('139.7035494')}, None]

Process finished with exit code 0

ぐるなびAPI

環境

  • Python 3.4.5
  • java 1.8.0

概要

PythonでぐるなびAPIからレストランデータを取得する。

# -*- coding: utf-8 -*-
import sys
import urllib.request
import json

####
# 変数の型が文字列かどうかチェック
####
def is_str( data = None ) :
    if isinstance( data, str ) :
        return True
    else :
        return False

####
# 初期値設定
####
# APIアクセスキー

keyid = ""
# エンドポイントURL
url = "http://api.gnavi.co.jp/RestSearchAPI/20150630/"
hit_per_page = 500

####
# APIアクセス
####
# URLに続けて入れるパラメータを組立
query = [
    ("format","json"),
    ("keyid",keyid),
    ("hit_per_page",hit_per_page)
]
# URL生成
url += "?{0}".format(urllib.parse.urlencode(query))
# API実行
try :
    result = urllib.request.urlopen(url).read()
except ValueError :
    print (u"APIアクセスに失敗しました。")
    sys.exit()

####
# 取得した結果を解析
####
data = json.loads(result.decode('utf-8'))
# エラーの場合
if "error" in data :
    if "message" in data :
        print (u"{0}".format( data["message"] ))
    else :
        print (u"データ取得に失敗しました。")
    sys.exit()

# ヒット件数取得
total_hit_count = None
if "total_hit_count" in data :
    total_hit_count = int(data["total_hit_count"])

# ヒット件数が0以下、または、ヒット件数がなかったら終了
if total_hit_count is None or total_hit_count <= 0 :
    print (u"指定した内容ではヒットしませんでした。")
    sys.exit()

# レストランデータがなかったら終了
if not "rest" in data :
    print (u"レストランデータが見つからなかったため終了します。")
    sys.exit()

# ヒット件数表示
print ("{0}件ヒットしました。".format( total_hit_count ))

# レストランデータ取得
for rest in data["rest"] :
    line = []
#    id = ""
    name = ""
#    access_line = ""
#    access_station = ""
#    access_walk = ""
    tel = ""
    opentime = ""
    latitude = ""
    longitude = ""
    '''
    # 店舗番号
    if "id" in rest and is_str( rest["id"] ) :
        id = rest["id"]
    line.append( id )
    '''
    # 店舗名
    if "name" in rest and is_str( rest["name"] ) :
        name = u"{0}".format( rest["name"] )
    line.append( name )
    '''
    if "access" in rest :
        access = rest["access"]
        # 最寄の路線
        if "line" in access and is_str( access["line"] ) :
            access_line = u"{0}".format( access["line"] )
        # 最寄の駅
        if "station" in access and is_str( access["station"] ) :
            access_station = u"{0}".format( access["station"] )
        # 最寄駅から店までの時間
        if "walk" in access and is_str( access["walk"] ) :
            access_walk = u"{0}分".format( access["walk"] )
        line.extend( [ access_line, access_station, access_walk ] )
    '''
    # 電話番号
    if "tel" in rest and is_str(rest["tel"]) :
        tel = rest["tel"]
    line.append(tel)
    # 営業時間
    if "opentime" in rest and is_str(rest["opentime"]) :
        opentime = rest["opentime"]
    line.append(opentime)
    # 緯度経度
    if "longitude" in rest and is_str(rest["longitude"]):
        longitude = rest["longitude"]
    line.append(longitude)
    if "latitude" in rest and is_str(rest["latitude"]):
        latitude = rest["latitude"]
    line.append(latitude)
    # 出力
    print ("\t".join(line))

sys.exit()

ループで外部ファイルにデータを移す場合

# -*- coding: utf-8 -*-
import sys
import urllib.request
import json

####
# 変数の型が文字列かどうかチェック
####
def is_str( data = None ) :
    if isinstance( data, str ) :
        return True
    else :
        return False

####
# 初期値設定
####
# APIアクセスキー

keyid = "16147047739469cf3"
# エンドポイントURL
url = "http://api.gnavi.co.jp/RestSearchAPI/20150630/"
hit_per_page = 500
offset = 500

for offset in range(0, 550000, 500):
    ####
    # APIアクセス
    ####
    # URLに続けて入れるパラメータを組立
    query = [
        ("format","json"),
        ("keyid",keyid),
        ("hit_per_page",hit_per_page),
        ("offset",offset)
    ]
    # URL生成
    url += "?{0}".format(urllib.parse.urlencode(query))
    # API実行
    try :
        result = urllib.request.urlopen(url).read()
    except ValueError :
        print (u"APIアクセスに失敗しました。")
        sys.exit()

    ####
    # 取得した結果を解析
    ####
    data = json.loads(result.decode('utf-8'))
    # エラーの場合
    if "error" in data :
        if "message" in data :
            print (u"{0}".format( data["message"] ))
        else :
            print (u"データ取得に失敗しました。")
        sys.exit()

    # ヒット件数取得
    total_hit_count = None
    if "total_hit_count" in data :
        total_hit_count = int(data["total_hit_count"])

    # ヒット件数が0以下、または、ヒット件数がなかったら終了
    if total_hit_count is None or total_hit_count <= 0 :
        print (u"指定した内容ではヒットしませんでした。")
        sys.exit()

    # レストランデータがなかったら終了
    if not "rest" in data :
        print (u"レストランデータが見つからなかったため終了します。")
        sys.exit()

    # ヒット件数表示
    #print ("{0}件ヒットしました。".format( total_hit_count ))

    # レストランデータ取得
    for rest in data["rest"] :
        line = []
    #    id = ""
        name = ""
    #    access_line = ""
    #    access_station = ""
    #    access_walk = ""
        tel = ""
        opentime = ""
        latitude = ""
        longitude = ""
        '''
        # 店舗番号
        if "id" in rest and is_str( rest["id"] ) :
            id = rest["id"]
        line.append( id )
        '''
        # 店舗名
        if "name" in rest and is_str( rest["name"] ) :
            name = u"{0}".format( rest["name"] )
        line.append( name )
        '''
        if "access" in rest :
            access = rest["access"]
            # 最寄の路線
            if "line" in access and is_str( access["line"] ) :
                access_line = u"{0}".format( access["line"] )
            # 最寄の駅
            if "station" in access and is_str( access["station"] ) :
                access_station = u"{0}".format( access["station"] )
            # 最寄駅から店までの時間
            if "walk" in access and is_str( access["walk"] ) :
                access_walk = u"{0}分".format( access["walk"] )
            line.extend( [ access_line, access_station, access_walk ] )
        '''
        # 電話番号
        if "tel" in rest and is_str(rest["tel"]) :
            tel = rest["tel"]
        line.append(tel)
        # 営業時間
        if "opentime" in rest and is_str(rest["opentime"]) :
            opentime = rest["opentime"]
        line.append(opentime)
        # 緯度経度
        if "longitude" in rest and is_str(rest["longitude"]):
            longitude = rest["longitude"]
        line.append(longitude)
        if "latitude" in rest and is_str(rest["latitude"]):
            latitude = rest["latitude"]
        line.append(latitude)
        # 外部ファイルへ出力
        lists = (",".join(line))
        f = open('test.tsv', "a")
        f.write(lists)
        f.close()

sys.exit()