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