<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pasha Pourmand on Medium]]></title>
        <description><![CDATA[Stories by Pasha Pourmand on Medium]]></description>
        <link>https://medium.com/@pashapourmand?source=rss-a528bf10fe27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MX98hazDTksiCCIbKDbyGQ.jpeg</url>
            <title>Stories by Pasha Pourmand on Medium</title>
            <link>https://medium.com/@pashapourmand?source=rss-a528bf10fe27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:58:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pashapourmand/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mincast— post mortem analysis]]></title>
            <link>https://medium.com/@pashapourmand/making-a-weather-app-post-mortem-analysis-bada3a1587ae?source=rss-a528bf10fe27------2</link>
            <guid isPermaLink="false">https://medium.com/p/bada3a1587ae</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Pasha Pourmand]]></dc:creator>
            <pubDate>Mon, 03 Oct 2016 21:04:10 GMT</pubDate>
            <atom:updated>2016-10-07T03:10:33.015Z</atom:updated>
            <content:encoded><![CDATA[<p>It has been <em>quite</em> a while since I’ve done a write up or blog post of any sort, so please excuse the shoddy writing.</p><p>So! I have fiddled around with making web applications before but never really finished one all the way through. This time, however, I managed to completely build one, albeit on a basic level. What the application does is give the weather forecast for today + the next 5 days in a simple and straightforward UI.</p><p>Below is a screenshot of the site, if you want to actually visit it you can go <a href="https://mincast.herokuapp.com/">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mb_SVdJhZU1hO_gnjH9eHA.png" /></figure><p>So as you can see, it displays an icon for the summary, low/hi temperatures, and chance of precipitation for the day. Very minimal, but it gives you a good idea of how the week is going to look like.</p><p>In addition to the information show, if you hover over the icon of the weather, a tooltip with a summary for that day will appear as can be seen below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBY-OQjp9VL2GkqQ6vYfgQ.png" /></figure><h3>Technologies</h3><p>Let’s dive into the technical aspects of what I used to build this site. On the backend, I used Node.js and Heroku to host. To grab weather data, I used DarkSky’s API which allowed me 1000 free API calls per day. On the front end I used Bootstrap.</p><p>Alright, first we will check out what kind of packages I installed via npm. I used express.js, satelize, and ejs.</p><p><a href="http://expressjs.com/">Express</a>: used for routing and such, pretty straightforward, didn’t do anything fancy, only have one path and that’s for root(“/”).</p><p><a href="https://www.npmjs.com/package/satelize">Satelize</a>: a small package used to grab the geolocation of a user given an IP address. This was needed because I needed to figure out where the client (your browser) was located geographically so I could display the correct weather for that location.</p><p><a href="http://www.embeddedjs.com/">Ejs</a>: a client-side templating language so I could send variables/information from the backend to the front end very easily.</p><p><a href="http://getbootstrap.com/">Bootstrap</a>: I used this to basically help me with the grid layout of my site since it was extremely easy and quick to set up. Also for the fancy tool-tip stuff.</p><h3>Process of build</h3><p>Alright let’s talk about how I wanted to build this. Initially, I was just checking the weather at forecast.io and saw at the bottom that they were advertising they are moving to darksky.net. After a couple clicks, I found the developer page and thought to myself that maybe this is my next side project. I want to get better at web development in general so I figured this would be a fun exercise to break up the monotony of job hunting.</p><p>Ok. So. I signed up and have been given a secret key and the documentation. Now what? Maybe I should get a basic site going before I try using the API.</p><p>Okay, npm init and away we go.</p><h4>User interface</h4><p>I decided to do the front end first so I got cracking with Bootstrap. I had already drawn out some crude sketches on paper of how I wanted it to look like so I began with that.</p><p>The way that Bootstrap layout works is with a grid system. You essentially have 12 columns per row on the screen that can be split up however you want. Maybe one column takes up 8 and the other takes up 4. Or maybe you want 12 columns of size 1. For me, the very top of my website had to be one solid block so I wanted 1 column of size 12.</p><p>Next, I needed another couple of rows. 6 more to be exact. The row below the top would be the same, 1 column of size 12. The next row, however is 6 columns each with size 2. The following 4 columns were equivalent to the date row (6 x 2).</p><p>Cool, now we have the row for our title, a row for the status, a row for the dates, a row for the icons, a row for the temperatures, and a row for the chance of precipitation. Excellent. Well now we have an issue. How am I supposed to have icons for the weather?</p><p>After a bit of googling around, I came across <a href="https://erikflowers.github.io/weather-icons/">some weather icons</a>. These were perfect, I’ll just use these! Okay cool now I have everything I need on the front end, now to populate my rows with legit data.</p><h4>Server side</h4><p>Okay now I actually need to do the logic portion of the website.</p><p>Since I’d rather not have a user input their own location just yet (This is something I will implement eventually just so I can play around with Google’s location stuff), I need to grab the user’s IP address. I do that with the following snippet:</p><pre>var userip = req.headers[&quot;x-forwarded-for&quot;];<br>  if (userip){<br>    var list = userip.split(&quot;,&quot;);<br>    userip = list[list.length-1];<br>  }<br>  else{<br>    userip = req.connection.remoteAddress;<br>  }</pre><p>Basically, since I am using Heroku to host the site, I can grab the IP address that is requesting the call to my server and store it in a variable I’ve called <em>userip</em>.</p><p>Awesome, now that we have an IP address, we need to find the real life latitude and longitude of that IP address so that we can make the correct call to the weather API. We can use Satelize like I’ve done below:</p><pre>satelize.satelize({ip:userip}, function(err, payload) {<br>  userLatitude = payload[&#39;latitude&#39;];<br>  userLongitude = payload[&#39;longitude&#39;];<br>});</pre><p>Now we have the users longitude and latitude stored in variables for us to pass along to the API call!</p><p>Okay, now to actually call the API, get the data returned to us, and grab the parts we need. Here’s the function I wrote in order to call the API:</p><pre>function callWeatherAPI(){<br>  request({<br>    url: &#39;<a href="https://api.darksky.net/forecast/&#39;">https://api.darksky.net/forecast/&#39;</a> + secretKey + &#39;/&#39; +       userLatitude + &#39;,&#39; + userLongitude, //URL to hit<br>    method: &#39;GET&#39;, //Specify the method<br>  }, function(error, response, body){<br>    if(error){<br>      console.log(&quot;error!!&quot; + error);<br>    } <br>    else{<br>      var weatherData = JSON.parse(body);<br>      dailyWeatherObject = weatherData[&#39;daily&#39;][&#39;data&#39;];<br>    }<br>  });<br>}</pre><p>It’s a little bit convoluted but what it does is use the secret key given to me by DarkSky, latitude, and longitude of the user and returns a JSON object with all the data to me, where I just grab the weather information for daily weather.</p><p>At this point I noticed that the API returns a name for the icons that I want to use but the name isn’t exactly mapped to the ones I downloaded from earlier so I had to make a function that would take in 6 days (current day + 5 day forecast) worth of icons and translate them to the set that I have. This ended up being just a huge if-else chain and renaming the icons.</p><p>Now comes the data population part. I never realized how clean JSON is but this is literally how I got all the information I needed:</p><pre>for(var i = 0; i &lt; dailyWeatherObject.length; i++){<br>  var dt = new Date(dailyWeatherObject[i][&#39;time&#39;] * 1000);<br>  var icons = dailyWeatherObject[i][&#39;icon&#39;];</pre><pre>  var dmy = (dt.getMonth() + 1) + &#39;/&#39; + dt.getDate();<br>  sevenDays.push(dmy);<br>  sevenDayIcons.push(icons);<br>  sevenDaySummaries.push(dailyWeatherObject[i][&#39;summary&#39;]);<br>  sevenDayMinTemp.push(dailyWeatherObject[i][&#39;apparentTemperatureMin&#39;]);<br>    sevenDayMaxTemp.push(dailyWeatherObject[i][&#39;apparentTemperatureMax&#39;]);<br>    sevenDayChanceOfRain.push(Math.floor(dailyWeatherObject[i][&#39;precipProbability&#39;] * 100));<br>  }</pre><p>It looks a bit weird on the medium editor since it goes to a newline, but its pretty self explanatory. Now that I have all the info, I just pass it to the front end and display with the help of EJS!</p><p>Bam! Done!</p><p>Oh wait, one thing remains: I am only allowed 1000 free API calls, so how do I work around that? Simple, create a timer that only calls the API every 3 minutes. It’s a pretty big limitation for a website but since this is just a side project I don’t mind the data not being up to date instantly.</p><p>Anyway, that’s basically it! It took me a week-ish to finish everything and it’s not even 100% tweaked out to what I want so I might keep working on it. Eventually I’ll open source the code on github and provide a link here.</p><p>Thanks for reading!</p><p>Edit: I opened sourced it! <a href="https://github.com/ppourmand/mincast">Check it out</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bada3a1587ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>