SlideShare a Scribd company logo
Python-Twitter と Tkinter のことはじめ FukPUG Meet-up vol.1 2012-01-29
お前、誰よ? Name : Yukitaka Uchikoshi job :  結婚式場で社内 SE id: uchikoshi22 level : Python 初心者クラス
今日の目標 簡単なTwitterアプリをPythonで実装 pipの導入 python-twitterの導入 サルでも分かる初歩過ぎるTkinter TwitterのタイムラインをTkinterで表示
python-twitterって何? Twitter の API を扱うためのライブラリ タイムラインの取得 ツイートの投稿 リプライ・リツイートの取得 フォロワーリストの取得
python-twitterを利用する為 最低限必要なライブラリ python-twitter 次の3つが python-twitter と一緒にインストールされます simplejson oauth2 httplib2
Pythonのパッケージ管理 Pythonパッケージ管理ツール pipを使いましょう! pipを使う理由 パッケージのアンインスールが可能 easy_install はアンイストールコマンドがない
pipのインストール方法 easy_install pip
easy_install pip ?
pipをインストールするために easy_installのインストールが必要です (^ ^);
easy_installインストール Windows編
http://pypi.python.org/pypi/setuptools#downloads   Windows にインストールしている Python に合わせて setuptools の exe ファイルをダウンロードして実行すると、(通常) c:\python27\scripts フォルダの中に easy_install.exe ができます
easy_install インストール Mac/Linux 編
Mac Sudo ports install py27_setuptools Ubuntu sudo apt-get install python-setuptools Fedora sudo yum install python-setuptools
pip と必要パッケージのインストール Windows 編
Python2.7の例 コマンドプロンプトを立ち上げて以下を実行 cd c:\python27\Scripts easy_install.exe pip pip install python-twitter
pip と必要パッケージのインストール Mac / Linux 編
Python2.7の例 sudo easy_install pip pip install python-twitter
python-twitterの動作確認 sudo easy_install pip pip install simplejson pip install oauth2 pip install python-twitter
python-twitterの動作確認 $ python >>> import twitter >>> api = twitter.Api() >>>  tl = api.GetUserTimeLine(id=' uchikoshi22 ') >>> for t in tl: print t.text
PythonのGUIツール Tkinter wxPython Qt 今回はインストール不要のTkinterを使います   ※ Tkinter が付属されていない Python が標準で Linux にインストールされていることがあるので、 apt などでインストールする必要が稀にあります。 Titanium Desktop 今回はインストール不要のTkinterを使います(が)   ※ Tkinter が付属されていない Python が標準で Linux にインストールされていることがあるので、 apt などでインストールする必要が稀にあります。
TkinterでHello World #!/usr/bin/env python # tk0.py from Tkinter import * root = Tk() Button(root, text=”Hello World”).pack() root.mainloop()
Tkinterでタイムライン表示(1) #!/usr/bin/env python #-*- coding: utf-8 -*- # tk1.py from Tkinter import * Import twitter root = Tk() #  ここに次のスライドのコードを入力 root.mainloop()
Tkinterでタイムライン表示(2) #  追加するコード def get_timeline(u): api = twitter.Api() tls = api.GetUserTimeline(id=u, count=10) retunrn tls # 自分のアカウントを入力してください。 tls = get_timeline(' uchikoshi22 ')  for tl in tls: Label = (root, text=t.text).pack()
Tkinterでタイムライン表示(3) #!/usr/bin/env python #-*- coding: utf-8 -*- # tk1.pyの全体 from Tkinter import * Import twitter root = Tk() def get_timeline(u): api = twitter.Api() tls = api.GetUserTimeline(id=u, count=10) retunrn tls tls = get_timeline(' uchikoshi22 ')   # 自分のアカウントを入力してください   for tl in tls: Label = (root, text=t.text).pack() root.mainloop()
python-twitter利用時の注意 TwitterのAPIでBasic認証が使えなくなりました https://twitter.com/appsでTwitterのAPIを使うための認証登録が必要です。
 取得したconsumer keyなどをまとめた下記内容のファイルをアプリケーションと同じディレクトリに保存する #!/usr/bin/env python # tweetauth.py u_id = 'uchikoshi22' auth_dict = { 'consumer_key': 'xxxxxxxxxxxxxxxx', 'consumer_secret': 'xxxxxxxxxxxxxxxx', 'access_tokey_key': 'xxxxxxxxxxxxxxxxxx', 'access_token_secret': 'xxxxxxxxxxxxxxxxxxxxxxx' }
外部ファイル (tweetauth.py) の利用 #!/usr/bin/env python # -*- coding:utf-8 -*- # tk3.py import tweetauth # tweetauth.py 内の u_id の値を表示 print tweetauth.u_id # tweetauth 内 auth_dict の consumber_key の値を表示 print tweetauth.auth_dict['consumer_key']
フォローしているツイートを 取得表示する
#!/usr/bin/env python #-*- coding: utf-8 -*- from Tkinter import * import twitter import tweetauth user = tweetauth.u_id t_dict = tweetauth.auth_dict def get_friends_timeline(user, max_timeline): api = twitter.Api( consumer_key = t_dict['consumer_key'], consumer_secret = t_dict['consumer_secret'], access_token_key = t_dict['access_token_key'], access_token_secret = t_dict['access_token_secret'], ) friends_timelines = api.GetFriendsTimeline(user, count=) return friends_timelines f_tls = get_friends_timeline(user, max_timeline) for tl in f_tls: tweet = tl.user.screen_name + " => " + tl.text Label(root, text=tweet).pack() root.mainloop()
Twitter への Post について ハンズオンしてみませんか?
今回はここまでです ありがとうございました

More Related Content

PPT
Python入門からpython twitter利用のハンズオン
PDF
今年使ってみて良かった、Pythonモジュール、パッケージ、ツール
PDF
「Python言語」はじめの一歩 / First step of Python
PDF
Pythonでゲーム作る
PDF
XML-RPC : Pythonが「電池付属」と呼ばれる理由
PDF
「Python言語」はじめの一歩 / First step of Python / 2016 Jan 12
PDF
久しぶりのPythonでgoogleのアレを制御してみた
PDF
Pythonを取り巻く開発環境 #pyconjp
Python入門からpython twitter利用のハンズオン
今年使ってみて良かった、Pythonモジュール、パッケージ、ツール
「Python言語」はじめの一歩 / First step of Python
Pythonでゲーム作る
XML-RPC : Pythonが「電池付属」と呼ばれる理由
「Python言語」はじめの一歩 / First step of Python / 2016 Jan 12
久しぶりのPythonでgoogleのアレを制御してみた
Pythonを取り巻く開発環境 #pyconjp

What's hot (18)

PDF
第1回python勉強会
PDF
密着!わたしのコンソールアプリ開発環境
PDF
Python3 プログラミング勉強会
PPTX
各OSにおいて、OpenCVをpythonから使う方法
PDF
python-twitterを用いたTwitterデータ収集
PPTX
2017/12/21 虎の穴 Python勉強会
PDF
Python パッケージの影響を歴史から理解してみよう!
PDF
PyQtではじめるGUIプログラミング
PDF
Pyconjp2014_implementations
PDF
Python入門
POTX
素振りのススメ at Python入門者の集い
PPTX
QtでHello, World!!
PDF
オープンCAEとPython
ODP
PySide/QtWebkitで楽々 slideshare Hack
PPTX
Pythonの環境導入 2014年春季版
PDF
Python 2/3コード共存戦略 #osakapy
PDF
BPStudy#54 そろそろPython3
PDF
なぜ科学計算にはPythonか?
第1回python勉強会
密着!わたしのコンソールアプリ開発環境
Python3 プログラミング勉強会
各OSにおいて、OpenCVをpythonから使う方法
python-twitterを用いたTwitterデータ収集
2017/12/21 虎の穴 Python勉強会
Python パッケージの影響を歴史から理解してみよう!
PyQtではじめるGUIプログラミング
Pyconjp2014_implementations
Python入門
素振りのススメ at Python入門者の集い
QtでHello, World!!
オープンCAEとPython
PySide/QtWebkitで楽々 slideshare Hack
Pythonの環境導入 2014年春季版
Python 2/3コード共存戦略 #osakapy
BPStudy#54 そろそろPython3
なぜ科学計算にはPythonか?
Ad

Viewers also liked (20)

ODP
Python 3000
PPTX
Introduction to Graphics
PPT
Apache Web Server Setup 3
PPTX
Python programming lab2
PDF
OSCON 2008: Porting to Python 3.0
PDF
Cc code cards
PPTX
Python programming lab1
PPT
Securing Apache Web Servers
PPT
PyTrening 2.0 # 15 Okienka GUI
PPT
Future Programming Language
PDF
Python and you
PPT
Apache Web Server Setup 2
PDF
10 more-things-you-can-do-with-python
PDF
An introduction-to-tkinter
PDF
Tkinter Does Not Suck
PDF
Begin with Python
PDF
Introduction to python 3 2nd round
PPT
Chapter 11 Presentation
PPT
Chapter 12 Presentation
ODP
20 cool things python
Python 3000
Introduction to Graphics
Apache Web Server Setup 3
Python programming lab2
OSCON 2008: Porting to Python 3.0
Cc code cards
Python programming lab1
Securing Apache Web Servers
PyTrening 2.0 # 15 Okienka GUI
Future Programming Language
Python and you
Apache Web Server Setup 2
10 more-things-you-can-do-with-python
An introduction-to-tkinter
Tkinter Does Not Suck
Begin with Python
Introduction to python 3 2nd round
Chapter 11 Presentation
Chapter 12 Presentation
20 cool things python
Ad

Similar to Python twitterとtkinterのことはじめ (20)

PDF
2023_freshman
PDF
Nltk for biginer
PDF
はじめてのPython
PDF
20170131 python3 6 PEP526
PDF
Cent osにpyhtonをインストールしてみよう
PDF
仙台 iOS開発者勉強会 2011/11/03 - TwitterAPIについて
PPTX
RTミドルウエアコンテスト2011応募作品「RTno」
PDF
NumPyが物足りない人へのCython入門
PDF
Security.gs fes 2010 in tokyo
PDF
StreamingAPIを使用したTwitter Bot @waketi の紹介
PDF
Cython intro prelerease
PDF
Wrapping a C++ library with Cython
PDF
Pythonの処理系はどのように実装され,どのように動いているのか? 我々はその実態を調査すべくアマゾンへと飛んだ.
PDF
組み込みシステムのセキュリティ
PDF
DATUM STUDIO PyCon2016 Turorial
PPTX
Stellaris を使った組み込みアプリ開発ガイド
PDF
広島IT勉強会カレンダー(仮)はRubyを使っています
PPTX
Brief introduction of Boost.ICL
PPTX
rpi_handson_2.5
PPTX
171129-irex2017
2023_freshman
Nltk for biginer
はじめてのPython
20170131 python3 6 PEP526
Cent osにpyhtonをインストールしてみよう
仙台 iOS開発者勉強会 2011/11/03 - TwitterAPIについて
RTミドルウエアコンテスト2011応募作品「RTno」
NumPyが物足りない人へのCython入門
Security.gs fes 2010 in tokyo
StreamingAPIを使用したTwitter Bot @waketi の紹介
Cython intro prelerease
Wrapping a C++ library with Cython
Pythonの処理系はどのように実装され,どのように動いているのか? 我々はその実態を調査すべくアマゾンへと飛んだ.
組み込みシステムのセキュリティ
DATUM STUDIO PyCon2016 Turorial
Stellaris を使った組み込みアプリ開発ガイド
広島IT勉強会カレンダー(仮)はRubyを使っています
Brief introduction of Boost.ICL
rpi_handson_2.5
171129-irex2017

Python twitterとtkinterのことはじめ