Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST] Public API #72

Open
jsnells1 opened this issue Apr 13, 2020 · 23 comments
Open

[REQUEST] Public API #72

jsnells1 opened this issue Apr 13, 2020 · 23 comments

Comments

@jsnells1
Copy link

Would a public API be possible? In our discord we keep track of everyone's prices and use this website for predictions. I wanted to make a bot to keep track of everyone's entries and it might be cool to be able to send the numbers through a public endpoint and receive the same data the chart receives.

Just a thought, not sure if anyone else would find this useful.

@elxris
Copy link
Owner

elxris commented Apr 13, 2020

That would be awesome. I mean if it helps someone to make cool things, why not?

If I have the time I will see what I can do.

Please note that I will prioritize bugs over this request.

@jamesaspence
Copy link

I'd be happy to take this one! I could spin up a relatively simple nodeJS API.

@jamesaspence
Copy link

I guess my only questions to start with would be:

  1. Would this live in this same repo or be separate
  2. Would this API just calculate the same info that the frontend already calculates, or would it be able to do more (store data, etc.)?

@Jarvie8176
Copy link

Hey guys,

I've been working on a webapp for tracking turnip prices: https://kabu.wiarlawd.me

Maybe we could integrate it with turnip calculator?

Also API docs are avaiable at https://kabu.wiarlawd.me/api/docs

@jamesaspence
Copy link

@elxris
Copy link
Owner

elxris commented Apr 16, 2020

Can you explain a little about this repos? I just compiled the client, but I didn't have a chance to locally deploy the backend.

Although, I think this issue is requesting a pretty straight forward API. For some input, they want the same output that the chart receives. No authentication. No databases. No history.

@jamesaspence
Copy link

Yep, sorry the repos don't have an updated readme - in all honesty the APIs don't have a ton of relevance to this work, short of being related to turnip price tracking and being an API :) it allows login and storing of historical price data which we don't have here. the actn-backend is the important repo in that it's the REST API (please keep in mind it was a WIP and abandoned once I found this and other sites!).

And yes, I figured as much - I figure a simple node API that uses the same JS that powers the front end calculations would do the trick nicely. As mentioned before, happy to tackle that if you're interested in it as well!

@bunniesocks
Copy link

Would a public API be possible? In our discord we keep track of everyone's prices and use this website for predictions. I wanted to make a bot to keep track of everyone's entries and it might be cool to be able to send the numbers through a public endpoint and receive the same data the chart receives.

Just a thought, not sure if anyone else would find this useful.

I just finished a bot like this! If you keep everyone's prices in a database by island, you can pass the prices along to a string and append that to the share URL in a discord embed. My repo is private right now bc it's still kinda rough but I can share the command js file with you if you'd like

@jsnells1
Copy link
Author

jsnells1 commented Apr 17, 2020

Would a public API be possible? In our discord we keep track of everyone's prices and use this website for predictions. I wanted to make a bot to keep track of everyone's entries and it might be cool to be able to send the numbers through a public endpoint and receive the same data the chart receives.
Just a thought, not sure if anyone else would find this useful.

I just finished a bot like this! If you keep everyone's prices in a database by island, you can pass the prices along to a string and append that to the share URL in a discord embed. My repo is private right now bc it's still kinda rough but I can share the command js file with you if you'd like

My thought for using an api is to track who and when people are supposed to peak that way the bot can send notifications or members can use a command to get that same information. A share link would be simple to generate but the bot can't get much information from that.

EDIT: Also to other people's points, I do appreciate others sharing their repos but as the repo owner stated, I wanted something simple without an auth, history, etc. I posed this question on this repo since I really like the design of the frontend and I support the work in this project. I think I'd be nice to have one place support a public API instead of a lot people "reinventing the wheel" in their own projects (of course in some situations you would not want to use an external API).

@Jarvie8176
Copy link

Jarvie8176 commented Apr 17, 2020

Would a public API be possible? In our discord we keep track of everyone's prices and use this website for predictions. I wanted to make a bot to keep track of everyone's entries and it might be cool to be able to send the numbers through a public endpoint and receive the same data the chart receives.
Just a thought, not sure if anyone else would find this useful.

I just finished a bot like this! If you keep everyone's prices in a database by island, you can pass the prices along to a string and append that to the share URL in a discord embed. My repo is private right now bc it's still kinda rough but I can share the command js file with you if you'd like

My thought for using an api is to track who and when people are supposed to peak that way the bot can send notifications or members can use a command to get that same information. A share link would be simple to generate but the bot can't get much information from that.

EDIT: Also to other people's points, I do appreciate others sharing their repos but as the repo owner stated, I wanted something simple without an auth, history, etc. I posed this question on this repo since I really like the design of the frontend and I support the work in this project. I think I'd be nice to have one place support a public API instead of a lot people "reinventing the wheel" in their own projects (of course in some situations you would not want to use an external API).

Right. I thought you wanted a solution for both tracking and predicting the prices. I have a simple web API set up (https://kabu.wiarlawd.me/api/predictions?input=) that generates prediction data. Right now it only generates random data as a stub. If @elxris permits I could port the prediction logic within utils/patterns.js into my web API.

Ideally I want to contribute to this repo by extracting an interface of this computation, so it can be used a js library, but I don't know where to put the code since this repo's structure is for a single react app.

@jamesaspence
Copy link

Well we could always create another directory, api, or even just server, and have it live side by side with the react app. I'm not sure what the owner uses for hosting but it's pretty trivial to spin up a koa / express app that will proxy requests to the react app through to the front end while also handling requests to a subpath (i.e. /api)

@elxris
Copy link
Owner

elxris commented Apr 19, 2020

@Jarvie8176 You're free to port every part you want!

@jamesaspence Right now I'm not hosting anything. All files are served through Github and Cloudflare CDN's. I have one Firebase Function to generate the previews under the share modal. (I want to enable Open Graph previews, but that will come later). I'm seeing that it could be possible to host a static API through Cloudflare Workers. (Static in a sense of no databases involved)

@elxris
Copy link
Owner

elxris commented Apr 22, 2020

If anyone finds this helpful this is an API I just mounted.

GET https://api.ac-turnip.com/data/?f=100-90-90

This would be a request to the API for 100 base price and Mon 90 AM, 90 PM values.
If you don't have a value, like the base price it would be

GET https://api.ac-turnip.com/data/?f=-90-90

If you have more data just keep appending it with a -

Example response.

{
  "filter": [
    100,
    90,
    90
  ],
  "minMaxPattern": [
    [38, 142],
    [85, 142],
    [58, 202],
    [48, 602],
    [38, 602],
    [38, 602],
    [33, 602],
    [29, 602],
    [24, 602],
    [19, 602],
    [14, 202],
    [9, 201]
  ],
  "avgPattern": [
    102.61,
    107.51,
    100.05,
    98.59,
    99.72,
    104.46,
    106.26,
    105.92,
    101.46,
    93.45,
    83.76,
    86.73
  ],
  "minWeekValue": 85,
  "preview": "https://ac-turnip.com/p-100-90-90.png"
}

@jsnells1
Copy link
Author

Nice! I'll check this out more when I have the time. Probably this weekend.

@SebPautot
Copy link

I'm trying to have a lot of AC:NH websites API Documentation in one place :
https://animal-crossing-api.glitch.me/ac-turnip.com
So I did this one's and added it to the website.
@elxris's example helped a lot.

@jamesaspence
Copy link

@elxris is the source code for the API available anywhere out of curiosity?

@elxris
Copy link
Owner

elxris commented Apr 28, 2020

@jamesaspence No, it’s a serverless function on a CloudFlare Worker. I created it on the fly with the web editor. I may work on creating a branch or a directory on the sources to disclose how I build it. The same as the preview generator.

@magicmonkey88
Copy link

@elxris Thank you so much for releasing your api. 😃 I've made a command on my Discord Bot with it, and works wonders. 👌

@zenahirsch
Copy link

Thanks for this endpoint! I made a little thing with it: https://zenahirsch.com/stalk-market/

The data I'm receiving from the API doesn't quite seem to match the actual dashboard data, not sure why.

https://api.ac-turnip.com/data/?f=98-91-114-137-143-140
https://ac-turnip.com/share?f=98-91-114-137-143-140

Still really cool though!

@elxris
Copy link
Owner

elxris commented May 6, 2020

Yeah! Sorry about that. I will see if I can update the API. API is v1. Web is v2.

@424626154
Copy link

@elxris
这个API非常棒,但是我在中国,经常超时,我是否可以自己搭建一个API?或者别的解决方式?

This API is very good, but I often run out of time in China. Can I build an API by myself? Or some other solution?

@elxris
Copy link
Owner

elxris commented May 7, 2020

I am using CloudFlare Workers to set up the API, but I think you can build an api for your needs as the code is publicly available.

I suggest you to use node.js.
Since 2.0 it’s in Rust. But the WASM is available and you could use it with node.

@elxris
Copy link
Owner

elxris commented Aug 31, 2020

Update: API and Web App predictions should match because now both use Rust-WASM powered calculator. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants