Example #1
0
def sn(input, s, b, epsilon=1e-5, max=1000, name='snorm'):
    """ Streaming normalizes a 2D tensor along its 1st axis, which corresponds to batch """
    m, v = tf.nn.moments(input, [0], keep_dims=True)
    v_sqrt = tf.sqrt(v + epsilon)
    m_stream = streaming.stream(m, name + 'sm')
    v_sqrt_stream = streaming.stream(v_sqrt, name + 'sv')
    normalised_input = (input - m_stream) / v_sqrt_stream
    return normalised_input * s + b
Example #2
0
def track_keywords():
    """
    Track two keywords with a tracking stream and print machting tweets and notices.
    To stop the stream, press ctrl-c or kill the python process.
    """
    keywords = ["politics", "election"]
    stream = streaming.stream(
        on_tweet=print_tweet, on_notification=print_notice, track=keywords)
Example #3
0
def track_keywords():
    """
    Track two keywords with a tracking stream and print machting tweets and notices.
    To stop the stream, press ctrl-c or kill the python process.
    """
    keywords = ["politics", "election"]
    stream = streaming.stream(on_tweet=print_tweet,
                              on_notification=print_notice,
                              track=keywords)
Example #4
0
def save_follow_users():
    """
    Follow several users, saving their tweets (and retweets) as they arrive.
    To stop the stream, press ctrl-c or kill the python process.
    """
    outfile = open("user_example.json", "w")

    def save_tweet(tweet):
        outfile.write(tweet)
    users = ["807095", "2467791"]
    stream = streaming.stream(
        on_tweet=save_tweet, on_notification=print_notice, follow=users)
Example #5
0
def save_track_keywords():
    """
    Track two keywords with a tracking stream and save machting tweets.
    To stop the stream, press ctrl-c or kill the python process.
    """
    # Set up file to write to
    outfile = open("keywords_example.json", "w")

    def save_tweet(tweet):
        outfile.write(tweet)
    keywords = ["politics", "election"]
    stream = streaming.stream(
        on_tweet=save_tweet, on_notification=print_notice, track=keywords)
Example #6
0
def save_follow_users():
    """
    Follow several users, saving their tweets (and retweets) as they arrive.
    To stop the stream, press ctrl-c or kill the python process.
    """
    outfile = open("user_example.json", "w")

    def save_tweet(tweet):
        outfile.write(tweet)

    users = ["807095", "2467791"]
    stream = streaming.stream(on_tweet=save_tweet,
                              on_notification=print_notice,
                              follow=users)
Example #7
0
def follow_users():
    """
    Follow several users, printing their tweets (and retweets) as they arrive.
    To stop the stream, press ctrl-c or kill the python process.
    """
    # user IDs are: nytimes: 807095, washingtonpost: 2467791
    # they can be obtained through:
    # users = ["nytimes", "washingtonpost"]
    # users_json = rest.fetch_user_list_by_screen_name(screen_names=users)
    # for u in users_json:
    #   print("{0}: {1}".format(u["screen_name"], u["id"]))
    users = ["807095", "2467791"]
    stream = streaming.stream(
        on_tweet=print_tweet, on_notification=print_notice, follow=users)
Example #8
0
def follow_users():
    """
    Follow several users, printing their tweets (and retweets) as they arrive.
    To stop the stream, press ctrl-c or kill the python process.
    """
    # user IDs are: nytimes: 807095, washingtonpost: 2467791
    # they can be obtained through:
    # users = ["nytimes", "washingtonpost"]
    # users_json = rest.fetch_user_list_by_screen_name(screen_names=users)
    # for u in users_json:
    #   print("{0}: {1}".format(u["screen_name"], u["id"]))
    users = ["807095", "2467791"]
    stream = streaming.stream(on_tweet=print_tweet,
                              on_notification=print_notice,
                              follow=users)
Example #9
0
def save_track_keywords():
    """
    Track two keywords with a tracking stream and save machting tweets.
    To stop the stream, press ctrl-c or kill the python process.
    """
    # Set up file to write to
    outfile = open("keywords_example.json", "w")

    def save_tweet(tweet):
        outfile.write(tweet)

    keywords = ["politics", "election"]
    stream = streaming.stream(on_tweet=save_tweet,
                              on_notification=print_notice,
                              track=keywords)
Example #10
0
    def get(self):
        min_time = request.args.get('min_time')
        print min_time, float(min_time)

        if min_time is None:
            min_time = datetime.datetime.now() + datetime.timedelta(minutes=-1)
            print min_time
        else:
            min_time = datetime.datetime.fromtimestamp(float(min_time))
            print min_time

        print "starting query"
        response = flask.make_response(streaming.stream(min_time))
        response.headers['Access-Control-Allow-Origin'] = '*'
        return response
Example #11
0
def save_track_keywords():
    """
    Track two keywords with a tracking stream and save machting tweets.
    To stop the stream, press ctrl-c or kill the python process.
    """
    # Set up file to write to
    outfile = open("keywords_example.json", "w")

    def save_tweet(tweet):
        json.dump(tweet, outfile)
        # Insert a newline after one tweet
        outfile.write("\n")

    keywords = ["politics", "election"]
    try:
        stream = streaming.stream(on_tweet=save_tweet,
                                  on_notification=print_notice,
                                  track=keywords)
    except (KeyboardInterrupt, SystemExit):
        logging.error("User stopped program, exiting!")
        outfile.flush()
        outfile.close()
Example #12
0
def getTweets():
    stream()
    return redirect(url_for('display_timeline'))
Example #13
0
 def post(self):
     flask.flash(streaming.stream())
     return flask.render_template('index.html')
Example #14
0
import streaming

while (True):
    try:
        streaming.stream()
    except:
        print("One more file!")