<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function

import inspect
import os
import subprocess
import time
from multiprocessing import Pool
from sys import stdout

import realhud

from tweepy.error import TweepError

DRAGONFIRE_PATH = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
FNULL = open(os.devnull, 'w')

songRunning = False


class TTA:
    def __init__(self, args):
        self.headless = args["headless"]
        self.silent = args["silent"]
        self.twitter = args["twitter"]
        if self.twitter:
            self.headless = True
            self.silent = True
        self.twitter_api = None
        self.twitter_user = None
        realhud.load_gif(DRAGONFIRE_PATH + "/realhud/animation/avatar.gif")

    def define(self, com="", msg="", sp="False"):
        self.command = com
        self.message = msg
        self.speak = sp

    def execute(self, duration):
        if self.twitter:
            return True
        try:
            subprocess.Popen(["notify-send", "Dragonfire", self.message])
        except BaseException:
            pass
        if self.command != "":
            time.sleep(duration)
            try:
                subprocess.Popen(self.command, stdout=FNULL, stderr=FNULL)
            except BaseException:
                pass
        # if self.speak == True:
        #   self.say(self.message)
        # else:

    def define_and_execute(self, com="", msg="", sp="False", duration=0):
        self.command = com
        self.message = msg
        self.speak = sp
        if self.twitter:
            return True
        try:
            subprocess.Popen(["notify-send", "Dragonfire", self.message])
        except BaseException:
            pass
        if self.command != "":
            time.sleep(duration)
            try:
                subprocess.Popen(self.command, stdout=FNULL, stderr=FNULL)
            except BaseException:
                pass

    def say(self, message, dynamic=False, end=False):
        if self.twitter:
            text = "@" + self.twitter_user + " " + message.upper()
            text = (text[:280]) if len(text) > 280 else text
            try:
                self.twitter_api.update_status(text)
            except TweepError as e:
                print("Warning: " + e.response.text)
            return True
        # if songRunning == True:
        #   subprocess.Popen(["rhythmbox-client","--pause"])
        if len(message) < 10000:
            if dynamic:
                if end:
                    print(message.upper())
                    print(
                        "_______________________________________________________________\n"
                    )
                else:
                    print("Dragonfire: " + message.upper(), end=' ')
                    stdout.flush()
            else:
                print("Dragonfire: " + message.upper())
                print(
                    "_______________________________________________________________\n"
                )
        if not self.silent:<commit_msg>Follow the user with a certain chance and include the link if there are any while tweeting<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function

import inspect
import os
import subprocess
import time
from multiprocessing import Pool
from sys import stdout
from random import randint

import realhud

from tweepy.error import TweepError

DRAGONFIRE_PATH = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
FNULL = open(os.devnull, 'w')

songRunning = False


class TTA:
    def __init__(self, args):
        self.command = None
        self.message = None

        self.headless = args["headless"]
        self.silent = args["silent"]
        self.twitter = args["twitter"]
        if self.twitter:
            self.headless = True
            self.silent = True
        self.twitter_api = None
        self.twitter_user = None
        realhud.load_gif(DRAGONFIRE_PATH + "/realhud/animation/avatar.gif")

    def define(self, com="", msg="", sp="False"):
        self.command = com
        self.message = msg
        self.speak = sp

    def execute(self, duration):
        if self.twitter:
            return True
        try:
            subprocess.Popen(["notify-send", "Dragonfire", self.message])
        except BaseException:
            pass
        if self.command != "":
            time.sleep(duration)
            try:
                subprocess.Popen(self.command, stdout=FNULL, stderr=FNULL)
            except BaseException:
                pass
        # if self.speak == True:
        #   self.say(self.message)
        # else:

    def define_and_execute(self, com="", msg="", sp="False", duration=0):
        self.command = com
        self.message = msg
        self.speak = sp
        if self.twitter:
            return True
        try:
            subprocess.Popen(["notify-send", "Dragonfire", self.message])
        except BaseException:
            pass
        if self.command != "":
            time.sleep(duration)
            try:
                subprocess.Popen(self.command, stdout=FNULL, stderr=FNULL)
            except BaseException:
                pass

    def say(self, message, dynamic=False, end=False):
        if self.twitter:
            text = "@" + self.twitter_user + " " + message.upper()
            text = (text[:280]) if len(text) > 280 else text
            if len(self.command) > 1:
                if self.command[0] == "sensible-browser":
                    text = text[:((len(self.command[1])+1)*(-1))] + " " + self.command[1]
            try:
                self.twitter_api.update_status(text)
                if randint(1,3) == 1:
                    self.twitter_api.create_friendship(self.twitter_user, follow=True)
            except TweepError as e:
                print("Warning: " + e.response.text)
            return True
        # if songRunning == True:
        #   subprocess.Popen(["rhythmbox-client","--pause"])
        if len(message) < 10000:
            if dynamic:
                if end:
                    print(message.upper())
                    print(
                        "_______________________________________________________________\n"
                    )
                else:
                    print("Dragonfire: " + message.upper(), end=' ')
                    stdout.flush()
            else:
                print("Dragonfire: " + message.upper())
                print(
                    "_______________________________________________________________\n"
                )
        if not self.silent:
{'fraction_non_alphanumeric': 0.10684523809523809, 'fraction_numerical': 0.005208333333333333, 'mean_word_length': 1.7243615727604378, 'pattern_counts': {'":': 5, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3183506', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1800, 'n_words': 413}