from time import sleep

# most trendy hashtags currently
#trendy = ["#smartiphone5BNOLotto", "#enkötüsüde", "#GiveMeThatGlobeIphone5", "#SilivriyeÖzgürlük", "#CiteNomesFeios",  "#121212concert", "#ItsNotCuteWhen", "#nowplaying", "#Blessed", "#breakoutartist"]
#print "Trends streamed will be : "
#print trendy


def stop_handler(signal, frame):
    """
    Detects when the user presses CTRL + C and stops the count thread
    """
    global h
    print "You just closed the stream!"
    h.stop()

# registering the signal
signal.signal(signal.SIGINT, stop_handler)

h = HashtagLogger(engine_url, oauth=True)
h.start()
print "Press CTRL + C to stop application"
h.add_hashtag("#nowplaying")
h.add_hashtag("#blessed")
h.add_hashtag("#WTF")
sleep(2)
h.add_hashtag("#f**k")

h.remove_hashtag("#WTF")
Esempio n. 2
0
class Trigger():
    def __init__(self):
        # registering the signal to stop command line
        signal.signal(signal.SIGINT, self.stop_handler)

        # starting all services
        # Streamer
        print "Starting streamer"
        self.h = HashtagLogger(data.engine_url, oauth=data.oauth)
        self.h.start()

        #Counter
        print "Starting counter"
        #self.c = Counter(data.engine_url)
        #self.c.start()

        # FIXME: Must create a wrapper to display them all periodically here
        # LeaderBoard
        # self.l = LeaderBoardAll()
        # self.l.start()

        print "Command Line utility started:"
        print "Press CTRL + C to stop application"
        print "type h, help or ? to get a list of possible commands"
        while True:
            res = raw_input(">")
            self.parse(res)

    def parse(self, comm):
        """
        Parses the command input by the user
        and triggers the corresponding action
        """
        word = comm.lower()
        if word in ["h", "help", "?"]:
            self.help()
        else:
            if word.startswith("add #"):
                hashtag = word.replace("add ", "")
                self.h.add_hashtag(hashtag)
            elif word.startswith("rm #"):
                hashtag = word.replace("rm ", "")
                self.h.remove_hashtag(hashtag)
            else:
                print "Unrecognized command"

    def help(self):
        """
        Prints Help message in command line
        """
        print "######"
        print "add [hashtag] : adds hashtag to list of interest hashtags "
        print "rm [hashtag] : removes hashtag from list of interest hashtags "
        print
        print "WARNING: hashtag always starts with #!"
        print "######"

    def stop_handler(self, signal, frame):
        """
        Detects when the user presses CTRL + C and stops the count thread
        """
        print ""
        print "Stopping Streamer"
        self.h.stop()
        #print "Stopping Counter"
        #self.c.stop()
        #print "Stopping LeaderBoard"
        #self.l.stop()
        print "Stopping Command Line"
        sys.exit(0)