Example #1
0
    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)
Example #2
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy import func
from sqlalchemy import desc


import data
from datamodel import TrendyHashtag
from datamodel import Tweet
from datamodel import Member

from streamer import HashtagLogger


app = Flask(__name__)
h = HashtagLogger(data.engine_url, oauth=data.oauth)
h.start()


## Utilities
def connect():
    """
    Separated so that the method can be run in each created thread.
    Initiates connexion to the database and starts a Session to be used to query it.
    Returns the session used to communicate with the database
    """
    # creates engine, tries to create all the tables needed later on
    engine = create_engine(data.engine_url, echo=data.debug)
    # initiates session to the database, tries to create proper session
    Session = sessionmaker(bind=engine)
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")
Example #4
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)