"This article is starting at: http://www.karottc.com/blog/2015/07/26/zhihu-sarcasm/"
--by KAROTTC
There is a section in the daily newspaper, called? How to correct the groove? There are a lot of interesting and short answers, and basically I am going to take a look every day. So I wrote a script to catch them all, put them on their own server, and also every day on time to crawl the new data on the day, and then use Swift to write an app to get the data from their own server view.
The process of doing this is documented below.
Fetching data
To grasp the information of the Spit Groove data, the first step is to know its corresponding URL , this method is also very simple to grab a bag to know, the specific form is probably as follows:
http://news-at.zhihu.com/api/4/section/2/before/xxxxxx
, this is the URL that gets the list of headers for the entire spit slot;
http://news-at.zhihu.com/api/4/story/xxxxx
, this is the URL to get the content for a specific day.
Create a database
The amount of data is not large, I have built two tables, one to save the index, one to save the daily specific content. Such as:
Build the server
With the data, the next step is to provide the CGI interface to the external call to get the data and then display.
Then, I used nginx + Django to build a server, provided three interfaces, are returned in JSON format data, three interfaces are as follows:
http://104.128.85.9:8001/api/gethomelist
: Get the data list of the first screen;
http://104.128.85.9:8001/api/getnextlist?timestamp=1434666598
: Fetch new data when the dropdown is refreshed;
http://104.128.85.9:8001/api/getstorydetail?id=4827840
: Gets the specific content of a particular day.
As you can see, all of my three interfaces are designed to be made for app-side calls, so the next step is to complete an app to display the content.
App-side display
The app-side work is:
- Obtain data through a network request;
- Parse the JSON data and display it according to a certain layout.
Of course, I also only achieved a very simple effect, directly put the map:
The above two charts are the history list and the specific day content, and then put an application icon diagram:
There is an icon in the mess, this is my study of Swift to do an exercise, specifically can read this: Point me.
This is probably the whole process.
Annex Information
The above mentioned service and grab to know the data code here: Dot me.
App source code here: Dot me.
2015.07.26
Grasping The Daily Spit groove