Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Lance Moore
Courses Plus Student 40 Pointssurf forecasting site question
Hello I have been working on a surfing site but I am stuck , what program or programmers do I use to pull data from one page and have it show on another page in a loop every hour. I am lost . I need help bad thanks
7 Answers

Kevin Korte
28,149 PointsIt'll probably depend on the API that you are using to pull surf data. What API are you using? With that said, the data probably comes in as JSON, and than you could use a variety of different languages to parse it. I'd personally use PHP as today it's what I'm most comfortable with. Javascript is likely a possibility too, among other options.
I've done something similar before from weather.com's API and used PHP to parse the JSON when the call was made.

Riley Hilliard
Courses Plus Student 17,771 PointsKevin Korte is correct, you will likely want to use an API to grab this data. Surfline and Magic Seaweed are both popular online surf forcast sites, and they both provide public API's. Surfline provides an RSS feed, while Magic Seaweed actually has a REST API service that can be used, so in my opinion MagicSeaweed has a better/easier API to use.
I would recommend reading directly from the API to show the data. That means every page visit / refresh your code will actually be calling the external API to get new data rather than setting up an hourly data pull. Once you get that working, then go ahead and look into setting up a data refresh cycle. This is called caching, and this can be done (if you are not familiar with caching) through using a server-side language, like PHP. There are 2 ways I would set this up, but both involve writing to a file or database on your server:
The first way is by setting up a timestamp comparison. You could essentially setup a simple "if/else" block that would look at the file you are writing to, check the last time it was written/overwritten, and if that time is more than 1 hour old you tell the program to fetch new data from the API, overwrite the file, and then use that file's data for your site. If another request is made to the server and it has been less than 1 hour, the if/else block would then forward the request to your cached file instead of making another request to the API.
The other way is by creating a script that calls the API, and writes the data to the file on your server. You can setup what is called a "CronTab" or "Cron Job", which is essentially a configuration you can make to your server to run this script every 60 minutes. That would then call the external API and grab new data every 60 minutes. Then you can use your file on your server (The one your script is writing the API data to) as your data source for the web app you are building.

Lance Moore
Courses Plus Student 40 PointsHello Riley and Kevin thanks for the answer that was what I was trying to figure out magic seaweed does have the better api your right but can I take there api (I do not want to use there api if its illegal I would rather build my own ) and us it or do I need to make my own api as I will be a competitor to them . Would it be best to make my own api , I have no idea how too do this . What do you suggest I do . I no how to forecast surfing and have done it for a long time . any ideas thanks for help . Are you interested in this project also I am looking to hire someone to build this page .Thanks for the help . Own a couple sites but this is a hard one . Lance

Lance Moore
Courses Plus Student 40 PointsHello I checked magicseaweed api rules and like I thought we can not sell ads so I need to make my own or do it another way . Do you no anyone that can help me with this . I have a designer who can help and have basic frame work but I have not idea how to do this but willing to learn . I want to be able to make changes to the code to adjust the forecasting thanks Lance

Riley Hilliard
Courses Plus Student 17,771 PointsBuilding out a complex surf prediction program / database is not just something you can do simply. In one way or another you are still going to need to get the data. This is usually done with physical buoys in the water that report their data to your system you build. That system needs to read the wave patters sent by your global buoy network, crunch the data, build out geographical predictions, and then save that data into a database. Your application then needs to read your collected data and present it however you want on your site.
That is going to take a lot of investment, which is why using something like a 3rd party API initially (if one already exists) is where most people would start. Using an API essentially leverages someone else's infrastructure.
But let's say you have the buoy network already, building the data processing system is no small task in itself. Not impossible to do, but certainly a pretty ambitious project to set out on, and there are already a couple pretty big players in the online surf prediction space.

Lance Moore
Courses Plus Student 40 PointsHello Thanks Yes I am ambitious , I want to start start small with my home location 1st witch is in Nova Scotia, Canada, I have all the data for the buoys and have 25 years in surf forecasting . I can not use Magic-seaweed api as I want to beat them at it here. Here is the site I have built so far www.upwellsurf.com , I just want to start by getting tide chart to work and build slow . Thanks for your help , I am going to do it . Sounds like I need to do api 1st . Thanks for your help I guess that's why I hired 6 people and they said they could do it but quite . . Thanks allot for your help . I will let you no how I make out all the best . These are other sites I own , www.dacanesurfshop.com, wwwsupportdudeteam.com, I guess I am going to have no life Lance

Isaac Minogue
3,543 PointsHey you guys. Sorry to resurface this old post. But seems like a good place to start. I'm a designer by trade, and have just begun developing this last year, and am loving it. Interestingly enough, I've also set myself the goal of creating a basic surf forecast site, but the back-end stuff is proving a little tricky. I'd really like to leverage off someone else's API, but haven't had any joy so far – I requested an API key from Magic Seaweed, and read up on their documentation, (JSON seems doable, as I'm familiar with JS) but as it turns out, they aren't willing to offer them to anyone who might pose a threat to their business (and they assume I am...). Thing is, I'm not intending on making any money, I simply want to have a project to work on. I've done a few google trails and NOAA looks promising, but doesn't provide location specific enough data for me. Anyways, does anyone know of any other worldwide, open source forecast APIs? Thought I'd give it a try. Thanks heaps!