Пример #1
0
 def get_all_info(self):
     # Fetches every single item's historical data
     final_value = {}
     for i in range(1,14):
         with cm.ContextManager(f'data/group_{i}/daily/{str(date_today)}.json') as file:
             use_file = json.loads(file.read())
         
         for value in use_file.values():
             value = analysis.Analysis.create_list_fetch_all(value)
         # MERGES ALL THE JSON FILES TOGETHER
         final_value.update(use_file)
     # SO THIS VERY USEFUL LOOP THAT FETCHES ALL PAST DAY INFO
     onlyfiles = len(os.listdir("data/group_2/daily"))
     use_date = date_today
     for a in range(onlyfiles-1):
         use_date -= day_delta
         for i in range(1,14):
             with cm.ContextManager(f"data/group_{i}/daily/{str(use_date)}.json") as file:
                 lookback_file = json.loads(file.read())
             for key,value in lookback_file.items():
                 print(key,value)
                 final_value[key]['stock'].append(value['stock'])
                 final_value[key]['volume'].append(value['volume'])
                 final_value[key]['price'].append(value['price'])
                 # print(final_value[key])
     return Data_Access(final_value)
Пример #2
0
def option_two():
    # Item id-name references
    while True:
        with cm.ContextManager(
                f"{abspath}/data/mp_reference.json") as item_reference_file:
            reference_json = json.loads(item_reference_file.read())
        all_data = data_access.Data_Access.get_all_info()

        version_list = [
            'Fetch Item Info', 'All Data', 'Rankings', 'Back to Main Menu'
        ]
        for x in version_list:
            print(f"{version_list.index(x) +1}: {x}")

        version_input = int(input("Input Version: "))
        # try:
        if version_input != 4:
            data_object = services.Data_Access_Version(
                all_data.make_indicators(),
                version=version_input,
                reference=reference_json)

        elif version_input == 4:
            break
        """
Пример #3
0
def fetch_and_store_data(url):
    work_url = 'https://eu-trade.naeu.playblackdesert.com/Trademarket/GetWorldMarketList'
    

    # Dev V2 will just focus on sending a proper API request to the website
    # Dev V3 will focus on the group search and saving methods, and making sure everything runs just right

    # Using the API interaction module, it fetches and returns a raw message from the endpoint
    # Decodes the raw returned message into a processable data-type using the Analysis module

    # Open reference file to translate IDs
    with cm.ContextManager(f"{abspath}/data/mp_reference.json") as file: 
        use_file = json.loads(file.read())
    
        
    # List of item-groups as they are organised in bdo-mp
    # TO BE MOVED TO ITS OWN FILE
    group_list = [(1,"Main Weapons"),(5,"Sub Weapons"),(10,"Awakening Weapons"),(15,"Armors"),(20,"Accessories"),(25,"Materials"),(30,"Enchancements/Upgrades"),(35,"Consumables"),(40,"Life Tools"),(45,"Alchemy Stones"),(50,"Crystals"),(65,"Mount"),(70,"Ship"),(75,"Wagon"),(80,"Furniture")]
    sub_lists = [17,15,22,6,4,8,2,8,10,4,7,13,9,6,9]
    request_session = requests.Session()
    request_session.headers = use_headers
    with request_session as session:
        for i in group_list:
            sub_range = sub_lists[group_list.index(i)]
            final_print = []
            for x in range(1,sub_range+1):
            # rawest_msg = (api_requests.Api_Request.sub_class_request(url=work_url,mainkey=i[0],subkey=1,session=session).content).content
            # Step 1: (fetches the info from the mp for the currently selected group, selecting the group with the value from "group_list")
                raw_msg = json.loads((api_requests.Api_Request.sub_request(mainKey=i[0],subKey=x,session=session).content))['resultMsg']
                # Step 2: (decodes the message and converts it to usable data)
            
                decoded_msg = analysis.decode_msg(raw_msg)
                # This is how you find the index of a value in a list

                for a in use_file:
                    for item in decoded_msg:
                        if item[0] == a[0]:
                            final_print.append((a,item[1:]))
                        else:
                            pass
                            # print(item)
                """for a in decoded_msg:
                    # This sorts through all the item references in the json file and match them to the api returned data
                    # by ID, and return both data in a tuple
                    for item in use_file:
                        if item[0] == a[0]:
                            final_print.append((item,a[1:]))"""

            # THIS SEGMENT IS GOING TO BE MOVED TO SAVE_DATA MODULE
            to_save_json = analysis.reformat_sub_group(final_print)
            to_save_json = json.dumps(to_save_json,indent=4)
            date_today = str(datetime.date.today())
            folder_index = group_list.index(i)+1
            with open(f"{abspath}/data/group_{folder_index}/daily/{date_today}.json","w") as file:
                file.write(to_save_json)

            # Progress bar
            progress_percent = ((group_list.index(i)+1) / (len(group_list))) * 100
            print(f"Completion: {progress_percent}% - {i[1]}", end='\r')
Пример #4
0
import json
import data
import datetime
import requests
import data.context_manager as cm
import api_data.api_requests as api_requests
from analysis.analysis import Analysis as analysis
from data_access import data_access
import services

# Main file

# Temporary Link, will turn into a selection
abspath = os.path.abspath('bdo-marketplace-data')
print(abspath)
with cm.ContextManager(f"{abspath}/data/settings.json") as file:
    settings = json.loads(file.read())
temporary_link = 'https://eu-trade.naeu.playblackdesert.com/Trademarket/GetWorldMarketList'
offile_mode = False


# Option one hits the api and saves all the data for that day
def option_one(url):
    try:
        services.fetch_and_store_data(url)
    except requests.exceptions.ConnectionError as err:
        print(f"Could not connect to API: {err}\n")
        print("Marketplace info not fetched")
        print("Starting in Offline Mode")
        offline_mode = True
Пример #5
0
    # Formula: ratio(price_change,stock_change)*volume_change*price(this is to favor more expensive items)
    # the final print() prints out the top 10 best purchases, not taking into account price and relevancy
    top_10 = [reference_dict[a] for a in working_list[:10]]
    return top_10
    print(top_10)


if __name__ == "__main__":
    
    # I DID SOME MASSIVE THINGS HERE IN TEST_BRANCH_1, I CANNOT WAIT TO GO EVEN FURTHER WITH THIS, AFTER SOME BUG FIXES AND ERROR HANDLING
    # I WILL BE READY TO TRY BUILD AN API AND TEST IT ON A TELEGRAM BOT

    # 
    all_item_info = Data_Access.get_all_info()._data

    with cm.ContextManager('../data/mp_reference.json') as item_reference_file:
        reference_json = json.loads(item_reference_file.read())

    # print(reference_json)
    # This currently has absolutely no error handling treat it with a grain of salt
    version_input = int(input("Version n: "))
    version = version_input

    """if version == 1:
        input_name = input("Input part of searched item, it'll return all items with it in their name: ")

        returned_item_from_input = list(filter(lambda a: input_name in a[1],reference_json))
        # Prints out all the searched for items' past data
        for items in returned_item_from_input:
            try:
                print("------------------------")