|
@ -38,8 +38,16 @@ class TwitterApi(): |
|
|
def send(self, tweet): |
|
|
def send(self, tweet): |
|
|
self.api.update_status(tweet) |
|
|
self.api.update_status(tweet) |
|
|
|
|
|
|
|
|
def get_tweets_by_tag(tag): |
|
|
def get_tweets_by_tag(self, tag): |
|
|
print "NotImplemented" |
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTelnetHandler(TelnetHandler): |
|
|
class TestTelnetHandler(TelnetHandler): |
|
@ -52,12 +60,18 @@ class TestTelnetHandler(TelnetHandler): |
|
|
authNeedPass = False |
|
|
authNeedPass = False |
|
|
|
|
|
|
|
|
twitter = TwitterApi() |
|
|
twitter = TwitterApi() |
|
|
|
|
|
get_tweets_event = [] |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
event = eventlet.spawn_after(180, self.writemessage, message) |
|
|
|
|
|
self.get_tweets_event.append(event) |
|
|
|
|
|
|
|
|
def session_end(self): |
|
|
def session_end(self): |
|
|
'''Called after the user logs off.''' |
|
|
'''Called after the user logs off.''' |
|
|
|
|
|
for event in self.get_tweets_event: |
|
|
|
|
|
event.kill() |
|
|
|
|
|
|
|
|
def writeerror(self, text): |
|
|
def writeerror(self, text): |
|
|
'''Called to write any error information (like a mistyped command). |
|
|
'''Called to write any error information (like a mistyped command). |
|
@ -70,12 +84,22 @@ class TestTelnetHandler(TelnetHandler): |
|
|
@command(['tweet', 'send']) |
|
|
@command(['tweet', 'send']) |
|
|
def command_tweet(self, params): |
|
|
def command_tweet(self, params): |
|
|
''' <message> |
|
|
''' <message> |
|
|
Sends the message as a tweet from @USR |
|
|
Sends the message as a tweet from @OpenFest_Fttp |
|
|
''' |
|
|
''' |
|
|
message = " ".join(params) |
|
|
message = " ".join(params) |
|
|
print type(message) |
|
|
|
|
|
self.twitter.send(message) |
|
|
self.twitter.send(message) |
|
|
|
|
|
|
|
|
|
|
|
@command(['feed', 'get_tweets']) |
|
|
|
|
|
def command_get(self, params): |
|
|
|
|
|
''' <#tag> |
|
|
|
|
|
Gets latest tweets by a given tag (Default: #OpenFest2016) |
|
|
|
|
|
''' |
|
|
|
|
|
# if not params[0]: |
|
|
|
|
|
# params[0] = "#OpenFest2016" |
|
|
|
|
|
|
|
|
|
|
|
self.feed = self.twitter.get_tweets_by_tag("#openfest") |
|
|
|
|
|
self.writeresponse(self.feed.encode('utf-8').strip()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
Handler = TestTelnetHandler |
|
|
Handler = TestTelnetHandler |
|
|