Ejemplo n.º 1
0
def clean_old_entries():
    """cleans up entries from database(s) that are older than a day for moon call and ops log"""
    tables = [str(env + "_moon_call"), str(env + "_twitter_scores")]

    when = helpers.get_time_now()

    for table in tables:
        col = ""

        if "moon_call" in table:
            col = "main_end"
            when = when - timedelta(weeks=1)

        if "twitter_scores" in table:
            col = "created"
            when = when - timedelta(hours=24)

        with Db() as db:
            try:
                db.cur.execute("delete from " + table +
                               " where to_timestamp(" + col + ") <= " +
                               str(when))
            except psycopg2.Error as e:
                print e
                pass
Ejemplo n.º 2
0
def get_cutoff(x):
    now = get_time_now(naive=False)
    day_delta = timedelta(hours=24)

    return {
        "day": now - day_delta,
    }[x]
Ejemplo n.º 3
0
    def on_message(self, message):
        print('[WS] Incoming message:', message)

        date = helpers.get_time_now()

        f = open("/home/pi/" + message + ".txt", "a")
        f.write(date + "\n")
        f.close()

        # Broadcast message to all clients
        [
            client.write_message({
                "date": date,
                "list": message
            }) for client in connections
        ]
Ejemplo n.º 4
0
def moon_call():
    """ call hot shots on market symbols """

    operations_log = {}
    operations_log["main_start"] = helpers.get_time_now(stringify=True)

    print("[JOB] Starting moon_call at " + operations_log["main_start"])

    summaries = rex.get_market_summaries()
    scores = []

    print("[JOB] Searching Twitter for BTRX symbol high volume list...")
    operations_log["twitter_search_start"] = helpers.get_time_now(
        stringify=True)

    avg_res = archivist.get_moon_call_res_duration()

    print("[JOB] Scoring " + str(len(summaries)) + " coins...")
    # get and score relevant tweets per symbol.
    for summary in summaries:
        entry = summary
        entry["created"] = helpers.get_time_now(stringify=True)

        coin_symbol = "$" + summary["symbol"]

        # search twitter
        tweets = twit.search(coin_symbol)
        score = logician.judge(tweets, stale_break=avg_res + 3200)

        # if score sucks, go to next symbol
        if not score:
            continue

        entry["score"] = int(score)
        postgres.add_twitter_score(entry)
        scores.append(entry)

    operations_log["twitter_search_end"] = helpers.get_time_now(stringify=True)

    # sort and find hottest trends
    sorted_scores = sorted(scores,
                           key=operator.itemgetter("score"),
                           reverse=True)
    hourly_top_scores = sorted_scores[:5]

    print("[JOB] Preparing message templates...")

    daily_top_scores = archivist.get_score_history(tf="day")

    # track the daily coins for each call
    operations_log["daily_coins"] = []

    for coin in daily_top_scores:
        operations_log["daily_coins"].append(coin["symbol"])

    # ensure that we are not unnecessarily sending daily/ block
    last_daily = archivist.get_last_scores("day")

    day_matches_last_moon_call = False
    if last_daily is not None:
        day_matches_last_moon_call = last_daily == operations_log[
            "daily_coins"]

    if day_matches_last_moon_call:
        daily_top_scores = []

    # prepare message for telegram
    operations_log["send_message_start"] = helpers.get_time_now(stringify=True)

    bot.generate_and_post_message(hourly_top_scores, daily_top_scores)

    operations_log["send_message_end"] = helpers.get_time_now(stringify=True)

    print("[JOB] Moon call complete, message sent at " +
          helpers.get_time_now(stringify=True))
    print("[JOB] Sleeping now for one hour...\n\n")

    operations_log["main_end"] = helpers.get_time_now(stringify=True)
    postgres.add_operations_log(operations_log)
    postgres.clean_old_entries()
Ejemplo n.º 5
0
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# GPIO.setup(24, GPIO.OUT)   # set GPIO24 as an output (LED)

prev_input23 = 0
prev_input24 = 0
prev_input25 = 0

try:
    while True:  # this will carry on until you hit CTRL+C
        if (GPIO.input(23) == True):
            if (not prev_input23):  # if port 23 == 1 and it was previously 0
                print("Port 23 is 1/HIGH/True - BUTTON PRESSED")
                # payload = { "date": datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ'), "list": "kitties" }
                payload = {"date": helpers.get_time_now(), "list": "kitties"}
                # r = requests.post("http://192.168.0.104/post", data = payload)
                r = requests.post("http://127.0.0.1/post", data=payload)
                print(r.text)
                # GPIO.output(24, (not GPIO.input(24)))         # Toggle pin 24 - set port/pin value to 1/HIGH/True
            prev_input23 = True
        else:
            prev_input23 = False

        if (GPIO.input(24) == True):
            if (not prev_input24):  # if port 24 == 1 and it was previously 0
                print("Port 24 is 1/HIGH/True - BUTTON PRESSED")
                # payload = { "date": datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ'), "list": "andi" }
                payload = {"date": helpers.get_time_now(), "list": "andi"}
                # r = requests.post("http://192.168.0.104/post", data = payload)
                r = requests.post("http://127.0.0.1/post", data=payload)
Ejemplo n.º 6
0
def judge(tweets, stale_break):
    """
    judge provides a score judging an array of tweets based on
    - user credibility
    - tweet quality, hype     
    """

    scores = []
    for tweet in tweets:
        # ignore stale tweets.
        if parse_date(tweet.created_at) < get_time_now() - timedelta(
                seconds=stale_break):
            break

        score = 0

        # judge user credibility
        user = tweet.user
        twitter_handle = user.screen_name
        followers = user.followers_count

        # f**k potential bots.
        # - default profile means they have not modified at all.
        if user.default_profile is True:
            continue

        # f**k shills and spammers.
        if twitter_handle in SHILLS:
            continue

        score += followers
        if user.verified:
            score *= 2

        # judge tweet quality
        favs = tweet.favorite_count
        retweets = tweet.retweet_count
        text = tweet.text

        # TODO: check tweet.entities
        # https://dev.twitter.com/overview/api/entities
        # if these entities are in CRYPTO_TERMS yeahhh

        if favs:
            score += favs * 4

        if retweets:
            score += retweets * 4

        # vips get bumps.
        if twitter_handle in VIP_PLAYERS:
            score *= 2

        # deduct points for coin spamming
        if text.count("$") > 3:
            score *= 0.5

        # TODO: add sentiment analysis here!
        # - take the polarity of the text and simply multiply the score by that

        scores.append(score)

    if not scores:
        return 0

    return sum(scores) / float(len(scores))