<commit_before>import os
import sys
import json
import time
from distutils.version import LooseVersion
import importlib
import pip
from enum import Enum
import logging
import csv
import subprocess

apikey = ''
password = ''
username = ''
bkey = ''
buy_trades = {}
sell_trades = {}
items = {}
key_price = 0
bud_price = 0
escrow = None
whitelist = []
currencies = {'bud':'Earbuds', 'ref':'Refined Metal', 'rec':'Reclaimed Metal', 'scrap':'Scrap Metal', 'key':'Mann Co. Supply Crate Key'}
packages = ['steampy', 'requests']
declined_trades = []
past_time = time.time()
start_time = time.time()

logging.basicConfig(filename='trade.log', level=logging.DEBUG,
                    format='[%(asctime)s][%(levelname)s][%(name)s]: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')

start_text = """
  _____    _____  ____         _____    ____        _      ____  U _____ u       ____     U  ___ u _____   
 |_ " _|  |" ___||___"\       |_ " _|U |  _"\ u U  /"\  u |  _"\ \| ___"|/    U | __")u    \/"_ \/|_ " _|  
   | |   U| |_  uU __) |        | |   \| |_) |/  \/ _ \/ /| | | | |  _|"       \|  _ \/    | | | |  | |    
  /| |\  \|  _|/ \/ __/ \      /| |\   |  _ <    / ___ \ U| |_| |\| |___        | |_) |.-,_| |_| | /| |\   
 u |_|U   |_|    |_____|u     u |_|U   |_| \_\  /_/   \_\ |____/ u|_____|       |____/  \_)-\___/ u |_|U   
 _// \\\_  )(\\\,- <<  //       _// \\\_  //   \\\_  \\\    >>  |||_   <<   >>      _|| \\\_       \\\   _// \\\_  
(__) (__)(__)(_/(__)(__)     (__) (__)(__)  (__)(__)  (__)(__)_) (__) (__)    (__) (__)     (__) (__) (__) 

Created by: Zwork101    Github: https://github.com/Zwork101    Steam: https://steamcommunity.com/id/ZWORK101\n
"""

class TradeOfferStatus(Enum):
    INVALID = 1
    ACTIVE = 2
    ACCEPTED = 3
    EXPIRED = 4
    CANCELED = 6
    INVALID_ITEMS = 8
    WAIT_CONF = 9
    WAIT_SFAC = 10
    ESCROW = 11


class TradeManager:

    """
    The manager for trades. This will be used to organize trades and keep everything from falling apart.
    Prams: client (steampy.client.SteamClient object, and conf, steampy.confirmation.ConfirmationExecutor
    Public values: client and conf (see above)
    Public functions: accept, check_trades_content, get_new_trades, check_good_trades, check_bad_trades
    """

    def __init__(self, client, conf):
        self._trades = []
        self._pending_trades = []
        self._try_confs = []
        self._declined_trades = []
        self.client = client
        self.conf = conf


    def decline(self, trade):
        if decline_trades:
            self.client.decline_trade_offer(trade.id)
        self._declined_trades.append(trade.id)


    def accept(self, trade):
        """
        The accept function handles accepting trades. This is important, because different errors could occur.
        Prams: (self), trade (Trade object)
        Output: None
        """
        try:
            self.client.accept_trade_offer(trade.id)
            return True
        except BaseException as BE:
            logging.warning(f'TRADE ACCEPT ERROR: {type(BE).__name__}: {BE}')
            return False


    def check_trades_content(self):
        """
        This will check the current trades in self._pending_trades and decide if they are good or not
        Then it will move the good trades to self._declined_trades and self._trades after acccepting/declining
        trade offers.
        Prams: (self)
        Output: None
        """
        for trade in range(len(self._pending_trades)-1,-1,-1):
            trade = self._pending_trades[trade]
            sell_value = 0
            buy_value = 0
            extra_sell = []
            extra_buy = []
            if not trade.items_to_give:
                self.accept(trade)
                self._pending_trades.remove(trade)
                self._trades.append(trade)
                continue
            exit_trade = False
            for item in trade.items_to_give:
                if not exit_trade:
                    if item not in sell_trades:
                        if item in currencies.values():
                            extra_sell.append(item)
                        else:
                            print('[TRADE]: Unknown item we\'re giving, declining')
                            self.decline(trade)
                            logging.info("DECLINING TRADE WITH UN-KNOWN ITEM")
                            exit_trade = True
                    else:
                        sell_value = add_values(sell_trades[item], sell_value)

            if exit_trade:
                continue

            for item in trade.items_to_receive:
                if item in buy_trades:
                    buy_value = add_values(buy_trades[item], buy_value)
                elif item in currencies.values():
                    extra_buy.append(item)

            sell_curr = sort(extra_sell)
            buy_curr = sort(extra_buy)
            sell_value += calculate(sell_curr[0], sell_curr[1], sell_curr[2], sell_curr[3], sell_curr[4])
            buy_value += calculate(buy_curr[0], buy_curr[1], buy_curr[2], buy_curr[3], buy_curr[4])
<commit_msg>Bug fixed, items needed to be floats<commit_after>import os
import sys
import json
import time
from distutils.version import LooseVersion
import importlib
import pip
from enum import Enum
import logging
import csv
import subprocess

apikey = ''
password = ''
username = ''
bkey = ''
buy_trades = {}
sell_trades = {}
items = {}
key_price = 0
bud_price = 0
escrow = None
whitelist = []
currencies = {'bud':'Earbuds', 'ref':'Refined Metal', 'rec':'Reclaimed Metal', 'scrap':'Scrap Metal', 'key':'Mann Co. Supply Crate Key'}
packages = ['steampy', 'requests']
declined_trades = []
past_time = time.time()
start_time = time.time()

logging.basicConfig(filename='trade.log', level=logging.DEBUG,
                    format='[%(asctime)s][%(levelname)s][%(name)s]: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')

start_text = """
  _____    _____  ____         _____    ____        _      ____  U _____ u       ____     U  ___ u _____   
 |_ " _|  |" ___||___"\       |_ " _|U |  _"\ u U  /"\  u |  _"\ \| ___"|/    U | __")u    \/"_ \/|_ " _|  
   | |   U| |_  uU __) |        | |   \| |_) |/  \/ _ \/ /| | | | |  _|"       \|  _ \/    | | | |  | |    
  /| |\  \|  _|/ \/ __/ \      /| |\   |  _ <    / ___ \ U| |_| |\| |___        | |_) |.-,_| |_| | /| |\   
 u |_|U   |_|    |_____|u     u |_|U   |_| \_\  /_/   \_\ |____/ u|_____|       |____/  \_)-\___/ u |_|U   
 _// \\\_  )(\\\,- <<  //       _// \\\_  //   \\\_  \\\    >>  |||_   <<   >>      _|| \\\_       \\\   _// \\\_  
(__) (__)(__)(_/(__)(__)     (__) (__)(__)  (__)(__)  (__)(__)_) (__) (__)    (__) (__)     (__) (__) (__) 

Created by: Zwork101    Github: https://github.com/Zwork101    Steam: https://steamcommunity.com/id/ZWORK101\n
"""

class TradeOfferStatus(Enum):
    INVALID = 1
    ACTIVE = 2
    ACCEPTED = 3
    EXPIRED = 4
    CANCELED = 6
    INVALID_ITEMS = 8
    WAIT_CONF = 9
    WAIT_SFAC = 10
    ESCROW = 11


class TradeManager:

    """
    The manager for trades. This will be used to organize trades and keep everything from falling apart.
    Prams: client (steampy.client.SteamClient object, and conf, steampy.confirmation.ConfirmationExecutor
    Public values: client and conf (see above)
    Public functions: accept, check_trades_content, get_new_trades, check_good_trades, check_bad_trades
    """

    def __init__(self, client, conf):
        self._trades = []
        self._pending_trades = []
        self._try_confs = []
        self._declined_trades = []
        self.client = client
        self.conf = conf


    def decline(self, trade):
        if decline_trades:
            self.client.decline_trade_offer(trade.id)
        self._declined_trades.append(trade.id)


    def accept(self, trade):
        """
        The accept function handles accepting trades. This is important, because different errors could occur.
        Prams: (self), trade (Trade object)
        Output: None
        """
        try:
            self.client.accept_trade_offer(trade.id)
            return True
        except BaseException as BE:
            logging.warning(f'TRADE ACCEPT ERROR: {type(BE).__name__}: {BE}')
            return False


    def check_trades_content(self):
        """
        This will check the current trades in self._pending_trades and decide if they are good or not
        Then it will move the good trades to self._declined_trades and self._trades after acccepting/declining
        trade offers.
        Prams: (self)
        Output: None
        """
        for trade in range(len(self._pending_trades)-1,-1,-1):
            trade = self._pending_trades[trade]
            sell_value = 0
            buy_value = 0
            extra_sell = []
            extra_buy = []
            if not trade.items_to_give:
                self.accept(trade)
                self._pending_trades.remove(trade)
                self._trades.append(trade)
                continue
            exit_trade = False
            for item in trade.items_to_give:
                if not exit_trade:
                    if item not in sell_trades:
                        if item in currencies.values():
                            extra_sell.append(item)
                        else:
                            print('[TRADE]: Unknown item we\'re giving, declining')
                            self.decline(trade)
                            logging.info("DECLINING TRADE WITH UN-KNOWN ITEM")
                            exit_trade = True
                    else:
                        sell_value = add_values(float(sell_trades[item]), float(sell_value))

            if exit_trade:
                continue

            for item in trade.items_to_receive:
                if item in buy_trades:
                    buy_value = add_values(float(buy_trades[item]), float(buy_value))
                elif item in currencies.values():
                    extra_buy.append(item)

            sell_curr = sort(extra_sell)
            buy_curr = sort(extra_buy)
            sell_value += calculate(sell_curr[0], sell_curr[1], sell_curr[2], sell_curr[3], sell_curr[4])
            buy_value += calculate(buy_curr[0], buy_curr[1], buy_curr[2], buy_curr[3], buy_curr[4])

{'fraction_non_alphanumeric': 0.1294186386210926, 'fraction_numerical': 0.007206154445418249, 'mean_word_length': 1.7869742198100407, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '3963616', 'n_tokens_mistral': 3442, 'n_tokens_neox': 3165, 'n_words': 694}