Wednesday, January 4, 2017

My first Rails project: Trump Promise Tracker

I'm excited to announce my first project using the Ruby On Rails web framework: Trump Promise Tracker, available at www.trumppromisetracker.com. The goal of TPT is to neutrally assess, based on the most literal interpretations, the truth value of Donald Trump's promises as a candidate. Building the site was mostly an endeavor to teach myself Rails, but also now this website exists, so that's nice!

I have a few goals for the content of the site and would love to have a few volunteers who would like to moderate the site with me to steer us towards those goals. This will require no programming knowledge! See the "Running TPT in the Future" section below if you are interested in that. In the meantime, I'm going to explain the development process and some of what I learned.

Gathering the Data


TPT was inspired by a Washington Post article listing 282 of Donald Trump's campaign promises. I wrote a Python script using BeautifulSoup that scraped all of the promises and sources embedded within, copying them into a CSV file. I then went through several times to edit the list, splitting "promises" that actually contained multiple pledges into their own entries, and removing ambiguous stuff that will never be settled such as his promises to "make America great again" or "give you everything." I generally tried to remove every instance of the word "and" by splitting that promise up; I was moderately successful, but sometimes that conjunction was necessary.

I uploaded the data through a rake job that I wrote with the help of a Stack Overflow thread. I actually did most things with the help of a Stack Overflow thread. I love Stack Overflow.

Building the Site


I started out knowing basically nothing about Rails, so I started reading Michael Hartl's Ruby On Rails Tutorial to gather enough to make me dangerous. I decided to use bitbucket for my git repository and Heroku for hosting. I created the app, established a resource for the promises, and populated the promise list through the rake job described above. I then added authentication through the Clearance gem for administrative accounts and began working on building a resource to handle the submission process for edits.

My original plan was to incorporate a unique submission system in which the submitter is required to pay some very small fee (25 cents was my goal) for submitting. The idea is that this would stop the spam that such a site would inevitably attract while providing some small amount of financing to hopefully cover the cost of hosting the site. Paypal has a micropayments option that would make this feasible (averaging about 12 cents in fees on each 25 cent payment) and incorporating a bitcoin option would be great as the fees are close to nonexistent. However, after spending a few days looking at the complexity of adding payments, I decided to put this on hold and just use a captcha instead.

Getting the edit resource to interact with the promise resource was something that I had to spend a lot of time researching. I ended up describing a has_many and belongs_to relationship between edits and promises in their respective models, making integration simpler, as each edit is attached to a promise. I plan to add a list of edits on each promise's page, something that intuitively seems fairly simple.

I used URL parameters to pass form data between resources, a useful but seemingly amateurish way of handling that job. I'm open to learning more back-end methods. The params method has a wealth of questions and answers online, which is useful for developing but often makes me feel like I'm not actually learning much about the method because I am able to find solutions that allow me to nearly copy and paste code. Granted, I successfully completed the project, but I worry that my implementation may have flaws in ways I don't understand. Working as a professional Rails developer with bosses and colleagues who can point these things out would be incredibly valuable.

Making the site less ugly and the log pages more useful required that I get involved in Bootstrap, a handy CSS framework released by Twitter that helps idiots beautify their pages. I don't claim TPT is anything wonderful to look at, but what I was able to do with the log pages is totally because of Bootstrap. The overall look of the site comes from the most basic template from Start Bootstrap, an excellent repository of Bootstrap themes to get a novice up and running.

Speaking of log pages, I really enjoyed building the functionality on the administrator site to Push or Reject suggestions. These were methods I had to build into the controllers for edits and new_promises and getting them to interact with the promises resource was a fun challenge. Getting everything working correctly (and then fixing all the stuff I broke along the way) was really cool. 

The last resource added was the new_promises resource, which was kind of an afterthought when I realized people would probably also like to suggest promises that I missed. I borrowed a bunch of code from the edits resource and would probably like to modularize the code some more in the future to simplify any changes that need to be made. In the meantime, however, the site is working and looking great.

Running TPT in the Future


I've never created a site that might actually be a going concern as a project. How much of my future time will it consume? Will I be so sick of it two months from now that I regret doing any of it? If this develops a following, will I really want to spend time moderating the submissions everyday?
Further development seems like a fun and profitable endeavor, but I'm not sure that moderation does. For that reason I hope to find some moderators who have an interest in tracking how President Trump measures up to Candidate Trump and are willing to put some time into providing this public service. I will provide all technical support and am open to ideas on how to expand the project to make it more useful, and we can include your name and bio on the About page so that you can show off and resume it. Just a thought!

Already I know a few things need work. Many of the sources the Washington Post provided are hour-long YouTube videos of Trump speaking; those links should point to where specifically in the video he made the pledge. Also, our pledges are paraphrases of his statements, something I did on purpose to avoid the perception that we were mocking him; this might not be the most accurate way of reporting, though, so we will see if any disagreements flow from that. Some of the sources in general might not be terribly accurate, and I hope the "crowd" can point out those instances. 

Alternatively, perhaps nobody is interested and I will get tired of moderating and this project will die, which I'm also not opposed to. The mission was to learn Rails, and the mission was accomplished. I'll keep this alive for as long as it seems reasonable to do so, but for me, TPT is already a success!

No comments: