万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    ExcelのREPLACE関数をPythonRubyPHP

    Excelは指定位置、文字数、置き換え文字で置き換えられる

    =REPLACE("エクセル2007",1,4,"ワード")

    →結果"ワード2007"

    str = "Haruo"
    str[1..3] = "ell"
    p str=> "Hello"
    

    Facebook SDK

    こっちが今最新(20012/3/23)
    https://github.com/pythonforfacebook/facebook-sdk.git


    本とか解説書わかりにくいがここがいいな
    http://www.nakamurahiroki.com/2011/02/facebook-apioauth-20html

    MySQL connectorはPython3未対応

    Python2でないとエラー出るOracle製品なのに・・・

    Traceback (most recent call last):
      File "/Users/shinriyo/ve/fb_env/​lib/python3.2/site-packages/​sqlalchemy/pool.py", line 717, in _do_get
        return self._pool.get(wait, self._timeout)
      File "/Users/shinriyo/ve/fb_env/​lib/python3.2/site-packages/​sqlalchemy/util/queue.py", line 137, in get
        raise Empty
    sqlalchemy.util.queue.Empty
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/opt/python-3.2.2/lib/​python3.2/runpy.py", line 160, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
      File "/opt/python-3.2.2/lib/​python3.2/runpy.py", line 73, in _run_code
        exec(code, run_globals)
      File "/Users/shinriyo/ve/fb_env/&#8203;tmp/teaspoon/__main__.py", line 78, in <module>
        eval(argv[1])()
      File "/Users/shinriyo/ve/fb_env/&#8203;tmp/teaspoon/__main__.py", line 46, in create
        __create__()
      File "./models/__init__.py", line 29, in <lambda>
        __create__ = lambda: (setattr(engine, 'echo', True), metadata.create_all(engine))
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/schema.py", line 2556, in create_all
        tables=tables)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 2291, in _run_visitor
        conn = self.contextual_connect(close_&#8203;with_result=False)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 2478, in contextual_connect
        self.pool.connect(), 
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/pool.py", line 224, in connect
        return _ConnectionFairy(self).&#8203;checkout()
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/pool.py", line 387, in __init__
        rec = self._connection_record = pool._do_get()
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/pool.py", line 739, in _do_get
        con = self._create_connection()
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/pool.py", line 188, in _create_connection
        return _ConnectionRecord(self)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/pool.py", line 273, in __init__
        pool.dispatch.first_connect.&#8203;exec_once(self.connection, self)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/event.py", line 279, in exec_once
        self(*args, **kw)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/event.py", line 288, in __call__
        fn(*args, **kw)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/strategies.&#8203;py", line 168, in first_connect
        dialect.initialize(c)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/dialects/mysql/&#8203;base.py", line 1977, in initialize
        default.DefaultDialect.&#8203;initialize(self, connection)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/default.py", line 181, in initialize
        self._get_default_schema_name(&#8203;connection)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/dialects/mysql/&#8203;base.py", line 1942, in _get_default_schema_name
        return connection.execute('SELECT DATABASE()').scalar()
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 1450, in execute
        params)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 1627, in _execute_text
        statement, parameters
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 1716, in _execute_context
        result = context.get_result_proxy()
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/default.py", line 646, in get_result_proxy
        return base.ResultProxy(self)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 2892, in __init__
        self._init_metadata()
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 2899, in _init_metadata
        self._metadata = ResultMetaData(self, metadata)
      File "/Users/shinriyo/ve/fb_env/&#8203;lib/python3.2/site-packages/&#8203;sqlalchemy/engine/base.py", line 2750, in __init__
        if primary_keymap.setdefault(&#8203;name.lower(), rec) is not rec: 
    TypeError: unhashable type: 'bytearray'
    (fb_env)shinriyo:teaspoon shinriyo$ 

    ・これよさげ?Python3用
    https://github.com/davispuh/MySQL-for-Python-3
    しかし、レジストリの情報をsite.cfgに登録が必要で面倒

    ・「py-postgresql 」PostgresQL用 Python3対応ドライバ

    PORT:5432

    Python3だからなのかpipコマンドはだめだった

    $ pip install py-postgresql
    Downloading/unpacking py-postgresql
      Real name of requirement py-postgresql is py-postgresql
      Downloading py-postgresql-1.0.3.tar.bz2 (829Kb): 829Kb downloaded
      Running setup.py egg_info for package py-postgresql
        Traceback (most recent call last):
          File "<string>", line 14, in <module>
        IOError: [Errno 2] No such file or directory: 'C:\\Users\\sugitashinsuke\\env32\\build\\py-postgresql\\setup.py'
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
    
      File "<string>", line 14, in <module>
    
    IOError: [Errno 2] No such file or directory: 'C:\\Users\\sugitashinsuke\\env32\\build\\py-postgresql\\setup.py'
    
    ----------------------------------------
    Command python setup.py egg_info failed with error code 1 in C:\Users\sugitashinsuke\env32\build\py-postgresql
    Storing complete log in C:\Users\sugitashinsuke\AppData\Roaming\pip\pip.log

    ・py-postgresql
    http://pypi.python.org/pypi/py-postgresql
    Windowsはここからmsiファイルでインストール

    => 12:59:27 : creating the database.
    Traceback (most recent call last):
      File "C:\Python32\Lib\runpy.py", line 160, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
      File "C:\Python32\Lib\runpy.py", line 73, in _run_code
        exec(code, run_globals)
      File "C:\Users\sugitashinsuke\env32\teaspoon\__main__.py", line 77, in <module>
        else: eval(argv[1])()
      File "C:\Users\sugitashinsuke\env32\teaspoon\__main__.py", line 45, in create
        from models import __create__
      File ".\models\__init__.py", line 21, in <module>
        engine = create_engine('postgresql+pypostgresql://teaspoon:teaspoon@localhost/teaspoon')
      File "C:\Users\sugitashinsuke\env32\lib\site-packages\sqlalchemy\engine\__init__.py", line 327, in create_engine
        return strategy.create(*args, **kwargs)
      File "C:\Users\sugitashinsuke\env32\lib\site-packages\sqlalchemy\engine\strategies.py", line 64, in create
        dbapi = dialect_cls.dbapi(**dbapi_args)
      File "C:\Users\sugitashinsuke\env32\lib\site-packages\sqlalchemy\dialects\postgresql\pypostgresql.py", line 58, in dbapi
        from postgresql.driver import dbapi20
    ImportError: No module named postgresql.driver

    ・「psycopg2」PostgresQLでPython3.2対応
    http://www.stickpeople.com/projects/python/win-psycopg/
    Windowsのもある
    うまくうごかない


    MySQL用のモジュールはOurSQL

    MySQL C client librariesが必須
    http://dev.mysql.com/downloads/connector/c/