|
|
@ -6,17 +6,17 @@ import argparse |
|
|
|
import eventlet |
|
|
|
import tweepy |
|
|
|
import config |
|
|
|
import time |
|
|
|
from telnetsrv.evtlet import TelnetHandler, command |
|
|
|
#from str import join |
|
|
|
|
|
|
|
for key in config.twitter_conf: |
|
|
|
if config.twitter_conf[key] == 'env': |
|
|
|
try: |
|
|
|
os.environ[key] |
|
|
|
config.twitter_conf[key] = os.environ[key] |
|
|
|
except KeyError: |
|
|
|
print "Please, set the environment variable %s or set it in the config" % key |
|
|
|
sys.exit(1) |
|
|
|
config.twitter_conf[key] = os.environ[key] |
|
|
|
|
|
|
|
logging.getLogger('').setLevel(logging.DEBUG) |
|
|
|
|
|
|
@ -42,11 +42,8 @@ class TwitterApi(): |
|
|
|
tweets = "" |
|
|
|
feed = self.api.search(tag, count=20) |
|
|
|
for i in feed: |
|
|
|
# tweets.join(i, "\n") |
|
|
|
tweets = tweets + i.text + "\n" |
|
|
|
# print type(tweets) |
|
|
|
return tweets |
|
|
|
# return '\n'.join(tweets) |
|
|
|
return tweets.encode('utf-8').strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -60,12 +57,21 @@ class TestTelnetHandler(TelnetHandler): |
|
|
|
authNeedPass = False |
|
|
|
|
|
|
|
twitter = TwitterApi() |
|
|
|
get_tweets_event = [] |
|
|
|
|
|
|
|
# queue = eventlet.queue.Queue(10000) |
|
|
|
# wait = eventlet.semaphore.CappedSemaphore(1000) |
|
|
|
|
|
|
|
def feed_auto(self): |
|
|
|
# while True: |
|
|
|
self.feed = self.twitter.get_tweets_by_tag(config.twitter_conf['TW_DEFAULT_TAG']) |
|
|
|
self.writeresponse(self.feed) |
|
|
|
# time.sleep(5) |
|
|
|
|
|
|
|
def session_start(self): |
|
|
|
'''Called after the user successfully logs in.''' |
|
|
|
message = self.twitter.get_tweets_by_tag("OpenFest2015") |
|
|
|
event = eventlet.spawn_after(180, self.writemessage, message) |
|
|
|
self.get_tweets_event = [] |
|
|
|
message = self.feed_auto() |
|
|
|
event = eventlet.spawn(self.writemessage, message) |
|
|
|
self.get_tweets_event.append(event) |
|
|
|
|
|
|
|
def session_end(self): |
|
|
@ -97,8 +103,8 @@ class TestTelnetHandler(TelnetHandler): |
|
|
|
# if not params[0]: |
|
|
|
# params[0] = "#OpenFest2016" |
|
|
|
|
|
|
|
self.feed = self.twitter.get_tweets_by_tag("#openfest") |
|
|
|
self.writeresponse(self.feed.encode('utf-8').strip()) |
|
|
|
self.feed = self.twitter.get_tweets_by_tag(config.twitter_conf['TW_DEFAULT_TAG']) |
|
|
|
self.writeresponse(self.feed) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|