commit: 618ffb98e06ca3e0243de3ef4a052127b81fb6a9
parent: 3dc676ed261a6d3f4e0bcb65c43189ec2a63b52f
Author: lanodan <lanodan.delta@free.fr>
Date: Sat, 7 Feb 2015 21:04:18 +0100
Add Streaming, Searching, Tracking
Diffstat:
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/twitter/search.py b/twitter/search.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python3
+# -*- encoding: utf-8 -*-
+from TwitterAPI import TwitterAPI, TwitterOAuth, TwitterRestPager
+import sys
+
+o = TwitterOAuth.read_file('credentials.txt')
+api = TwitterAPI(
+ o.consumer_key,
+ o.consumer_secret,
+ o.access_token_key,
+ o.access_token_secret)
+
+try:
+ r = api.request('search/tweets', {'q': sys.argv[1:]})
+ for item in r:
+ if 'text' in item:
+ print(item['id'], ' <\033[1m', item['user']['screen_name'], '\033[0m> — ', item['user']['name'], sep='')
+ else:
+ print(item)
+
+ print('\nQUOTA: %s' % r.get_rest_quota())
+except:
+ print(sys.exc_info())
diff --git a/twitter/track.py b/twitter/track.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python3
+# -*- encoding: utf-8 -*-
+from TwitterAPI import TwitterAPI, TwitterOAuth, TwitterRestPager
+import sys
+
+o = TwitterOAuth.read_file('credentials.txt')
+api = TwitterAPI(
+ o.consumer_key,
+ o.consumer_secret,
+ o.access_token_key,
+ o.access_token_secret)
+
+try:
+ r = api.request('statuses/filter', {'track': sys.argv[1:]})
+ for item in r:
+ print(item['text'] if 'text' in item else item)
+except:
+ print(sys.exc_info())