Browse Source

feed is now implemened - fetches the latest twitter feed for a given tag

python-server
Blagovest Petrov 8 years ago
parent
commit
2893c533dd
  1. 32
      server/server.py

32
server/server.py

@ -38,8 +38,16 @@ class TwitterApi():
def send(self, tweet):
self.api.update_status(tweet)
def get_tweets_by_tag(tag):
print "NotImplemented"
def get_tweets_by_tag(self, tag):
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):
@ -52,12 +60,18 @@ class TestTelnetHandler(TelnetHandler):
authNeedPass = False
twitter = TwitterApi()
get_tweets_event = []
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.append(event)
def session_end(self):
'''Called after the user logs off.'''
for event in self.get_tweets_event:
event.kill()
def writeerror(self, text):
'''Called to write any error information (like a mistyped command).
@ -70,12 +84,22 @@ class TestTelnetHandler(TelnetHandler):
@command(['tweet', 'send'])
def command_tweet(self, params):
''' <message>
Sends the message as a tweet from @USR
Sends the message as a tweet from @OpenFest_Fttp
'''
message = " ".join(params)
print type(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__':
Handler = TestTelnetHandler

Loading…
Cancel
Save