Eorzea Market Note Eorzea Market Note

EorzeaMarketNote Web API

EorzeaMarketNote Web API using Python example

Overview

Here is a example to display information on the Mandragora server's potion.

All sources

Please clone the example source from the following git repository.

The example for Python is contained in the python directory.

Premise

The example is based on the following tools and libraries.

How to run

The command to execute the example is as follow.

pipenv install
pipenv run example.py

Main source(example.py)

from datetime import datetime
import requests
import requests_cache
import time

requests_cache.install_cache('cache', backend='sqlite', expire_after=180)


def run():
    try:
        response = requests.get(
            'https://ff14marketnoteapi.ownway.info/research/1/market_research',
            params={'dc': 'Mana'})

        if response.status_code == 200:
            aggregate_date = datetime.fromtimestamp(time.mktime(parsedate(response.headers['Last-Modified'])))
            print("Aggregate date:{0}".format(aggregate_date.isoformat()))

            data = response.json()
            data_in_world = data.get('Mandragora')
            latest_market_researches = data_in_world.get(
                'l') if data_in_world else None
            optional_infos = data_in_world.get('o') if data_in_world else None

            item_key = '7992765ec34'
            potion_l = latest_market_researches.get(
                item_key) if latest_market_researches else None
            potion_o = optional_infos.get(
                item_key) if optional_infos else None
            if potion_l:
                price_nq = potion_l[0]
                price_hq = potion_l[1]
                stock_nq = potion_l[2]
                stock_hq = potion_l[3]
                circulation1_nq = potion_l[4]
                circulation1_hq = potion_l[5]
                circulation2_nq = potion_l[6]
                circulation2_hq = potion_l[7]
                circulation_nq = round(
                    24 * circulation1_nq / circulation2_nq, 2) if circulation1_nq and circulation2_nq else None
                circulation_hq = round(
                    24 * circulation1_hq / circulation2_hq, 2) if circulation1_hq and circulation2_hq else None
                researched_time = epoch_to_datetime(
                    potion_l[8]) if potion_l[8] else None
                print("Potion's price(NQ):{0}".format(price_nq))
                print("Potion's price(HQ):{0}".format(price_hq))
                print("Potion's stock(NQ):{0}".format(stock_nq))
                print("Potion's stock(HQ):{0}".format(stock_hq))
                print(
                    "Potion's circulation pieces/day(NQ):{0}".format(circulation_nq))
                print(
                    "Potion's circulation pieces/day(HQ):{0}".format(circulation_hq))
                print("Potion's researched time:{0}".format(
                    researched_time.isoformat()))

            if potion_o:
                material_cost_hq_first = potion_o[0]
                material_cost_price_first = potion_o[1]
                print("Potion's material cost(HQ first):{0}".format(
                    material_cost_hq_first))
                print("Potion's material cost(Price first):{0}".format(
                    material_cost_price_first))
        else:
            print("Error StatusCode:" + response.status_code)

    except Exception as e:
        print("Error Message:" + e)


def epoch_to_datetime(epoch):
    return datetime(*time.localtime(epoch)[:6])


if __name__ == '__main__':
    run()