Example #1
0
    def __init__(self,
                 starting_ids,
                 credentials,
                 graph_size=None,
                 directions=['followers', 'following'],
                 breadth=None,
                 traverse=True,
                 export_name=None):
        self.breadth = breadth
        self.traverse = traverse
        self.graph_size = graph_size
        self.nodes_count = len(starting_ids)
        self.directions = directions
        self.explored_nodes = defaultdict(dict)
        self.new_nodes = Queue()
        self.credentials = credentials
        self.explored_lock = thread_lock()
        self.count_lock = thread_lock()

        for node in starting_ids:
            self.new_nodes.put(node)

        if not export_name:
            export_name = date.today().strftime("%Y-%m-%d")
            self.export_name = export_name + '_twitter_relations.json'
        else:
            self.export_name = export_name
Example #2
0
def pretty_print(sender: str = "sys0",
                 msg: str = None,
                 state: str = "success"):
    """
    Produces nicely formatted CLI output for messages:
    HH:MM:S |sender| msg
    """
    if sender.startswith("net"):
        bg_color = Back.BLUE
    elif sender.startswith("avr"):
        bg_color = Back.MAGENTA
    elif sender.startswith("sys"):
        bg_color = Back.GREEN

    if state == "success":
        fg_color = Fore.GREEN
    elif state == "error":
        fg_color = Fore.RED
    else:
        fg_color = Fore.YELLOW

    with thread_lock():
        print(Fore.WHITE + datetime.now().strftime(Style.DIM + "%H:%M:%S ") +
              bg_color + Style.BRIGHT + " " + sender + " " + Back.RESET + " " +
              fg_color + msg.strip())
Example #3
0
    def __init__(self, starting_ids, credentials, graph_size=None,
                 directions=['followers', 'following'], breadth=None,
                 traverse=True, export_name=None):
        self.breadth = breadth
        self.traverse = traverse
        self.graph_size = graph_size
        self.nodes_count = len(starting_ids)
        self.directions = directions
        self.explored_nodes = defaultdict(dict)
        self.new_nodes = Queue.Queue()
        self.credentials = credentials
        self.explored_lock = thread_lock()
        self.count_lock = thread_lock()

        for node in starting_ids:
            self.new_nodes.put(node)

        if not export_name:
            export_name = date.today().strftime("%Y-%m-%d")
            self.export_name = export_name + '_twitter_relations.json'
        else:
            self.export_name = export_name
Example #4
0
def share_print(id, type, accept, reject, total_hashrate,
                computetime, diff, ping, reject_cause=None):
    """
    Produces nicely formatted CLI output for shares:
    HH:MM:S |avrN| ⛏ Accepted 0/0 (100%) ∙ 0.0s ∙ 0 kH/s ⚙ diff 0 k ∙ ping 0ms
    """
    try:
        diff = get_prefix("", int(diff), 0)
    except:
        diff = "?"

    try:
        total_hashrate = get_prefix("H/s", total_hashrate, 2)
    except:
        total_hashrate = "? H/s"

    if type == "accept":
        share_str = get_string("accepted")
        fg_color = Fore.GREEN
    elif type == "block":
        share_str = get_string("block_found")
        fg_color = Fore.YELLOW
    else:
        share_str = get_string("rejected")
        if reject_cause:
            share_str += f"{Style.NORMAL}({reject_cause}) "
        fg_color = Fore.RED

    with thread_lock():
        print(Fore.WHITE + datetime.now().strftime(Style.DIM + "%H:%M:%S ")
              + Fore.WHITE + Style.BRIGHT + Back.MAGENTA + Fore.RESET
              + " avr" + str(id) + " " + Back.RESET
              + fg_color + Settings.PICK + share_str + Fore.RESET
              + str(accept) + "/" + str(accept + reject) + Fore.MAGENTA
              + " (" + str(round(accept / (accept + reject) * 100)) + "%)"
              + Style.NORMAL + Fore.RESET
              + " ∙ " + str("%04.1f" % float(computetime)) + "s"
              + Style.NORMAL + " ∙ " + Fore.BLUE + Style.BRIGHT
              + str(total_hashrate) + Fore.RESET + Style.NORMAL
              + Settings.COG + f" diff {diff} ∙ " + Fore.CYAN
              + f"ping {(int(ping))}ms")
Example #5
0
from ffbinaries.errors import (FFBinariesAPIClientError, NoCacheDataError,
                               ExpiredCacheDataError)
from ffbinaries.utils import retry

BASE_API_URL = 'https://ffbinaries.com/api'
DEFAULT_API_VERSION = 'v1'

ENDPOINT_VERSIONS = 'versions'
ENDPOINT_VERSION = 'version'
ENDPOINT_LATEST = '{0}/latest'.format(ENDPOINT_VERSION)
ENDPOINT_EXACT_VERSION = '{0}/{{0}}'.format(ENDPOINT_VERSION)

CACHE_AGE = 300

PROC_LOCK = proc_lock()
THREAD_LOCK = thread_lock()


class FFBinariesAPIClient:
    """ffbinaries API Client Class."""
    def __init__(self, use_caching=False, cache_age=CACHE_AGE, log_init=None):

        if log_init is not None and callable(log_init[0]):
            log_init[0](log_init[1])
        self._log = logging.getLogger(self.__class__.__name__)

        self._use_caching = use_caching
        self._cache = SimpleCache(cache_age)

    def _request(self, url, method=HTTP.GET, stream=False, jsonify=False):
        """General Request Method."""