diff --git a/.gitignore b/.gitignore index f81aaec..6c1a8dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ _site -.sass-cache -roster.* -.ipynb_checkpoints +.*.sw[op] .DS_Store -notebooks/.DS_Store \ No newline at end of file +.ipynb_checkpoints/ diff --git a/03_lecture_code_kunal_040416.ipynb b/03_lecture_code_kunal_040416.ipynb deleted file mode 100644 index 3f57e74..0000000 --- a/03_lecture_code_kunal_040416.ipynb +++ /dev/null @@ -1,969 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Accessing Databases via Web APIs: Lecture Code\n", - "* * * * *" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Import required libraries\n", - "import requests\n", - "# from urllib3 import quote_plus\n", - "import json\n", - "from __future__ import division\n", - "import math" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 1. Constructing API GET Request\n", - "\n", - "In the first place, we know that every call will require us to provide a) a base URL for the API, b) some authorization code or key, and c) a format for the response. So let's put store those in some variables." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# set key\n", - "key=\"6e23901ee0fc07f0f6cee3a45b566bc5:13:73313103\"\n", - "\n", - "# set base url\n", - "base_url=\"http://api.nytimes.com/svc/search/v2/articlesearch\"\n", - "\n", - "# set response format\n", - "response_format=\".json\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You often want to send some sort of data in the URL’s query string. This data tells the API what information you want. In our case, we want articles about Duke Ellington. Requests allows you to provide these arguments as a dictionary, using the `params` keyword argument. In addition to the search term `q`, we have to put in the `api-key` term." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# set search parameters\n", - "search_params = {\"q\":\"Duke Ellington\",\n", - " \"api-key\":key} " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we're ready to make the request. We use the `.get` method from the `requests` library to make an HTTP GET Request." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# make request\n", - "r = requests.get(base_url+response_format, params=search_params)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, we have a [response](http://docs.python-requests.org/en/latest/api/#requests.Response) object called `r`. We can get all the information we need from this object. For instance, we can see that the URL has been correctly encoded by printing the URL. Click on the link to see what happens." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "http://api.nytimes.com/svc/search/v2/articlesearch.json?api-key=6e23901ee0fc07f0f6cee3a45b566bc5%3A13%3A73313103&q=Duke+Ellington\n" - ] - } - ], - "source": [ - "print(r.url)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Click on that link to see it returns!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Challenge 1: Adding a date range\n", - "\n", - "What if we only want to search within a particular date range? The NYT Article Api allows us to specify start and end dates.\n", - "\n", - "Alter the `search_params` code above so that the request only searches for articles in the year 2005.\n", - "\n", - "You're gonna need to look at the documentation [here](http://developer.nytimes.com/docs/read/article_search_api_v2) to see how to do this." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "http://api.nytimes.com/svc/search/v2/articlesearch.json?end_date=20051231&api-key=6e23901ee0fc07f0f6cee3a45b566bc5%3A13%3A73313103&q=Duke+Ellington&begin_date=20050101\n" - ] - } - ], - "source": [ - "#YOUR CODE HERE\n", - "\n", - "\n", - "search_params = {\"q\":\"Duke Ellington\",\n", - " \"api-key\":key,\n", - " \"begin_date\": 20050101,\n", - " \"end_date\": 20051231,\n", - " } \n", - "# Uncomment to test\n", - "r = requests.get(base_url+response_format, params=search_params)\n", - "print(r.url)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Challenge 2: Specifying a results page\n", - "\n", - "The above will return the first 10 results. To get the next ten, you need to add a \"page\" parameter. Change the search parameters above to get the second 10 resuls. " - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "#YOUR CODE HERE\n", - "\n", - "# Uncomment to test\n", - "# r = requests.get(base_url+response_format, params=search_params)\n", - "# r.url" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 2. Parsing the response text" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can read the content of the server’s response using `.text`" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\"response\":{\"meta\":{\"hits\":77,\"time\":36,\"offset\":0},\"docs\":[{\"web_url\":\"http:\\/\\/www.nytimes.com\\/2005\\/10\\/02\\/nyregion\\/02bookshelf.html\",\"snippet\":\"A WIDOW'S WALK:.\",\"lead_paragraph\":\"A WIDOW'S WALK: A Memoir of 9\\/11 By Marian Fontana Simon & Schuster ($24, hardcover) Theresa and I walk into the Blue Ribbon, an expensive, trendy restaurant on Fifth Avenue in Park Slope. We sit at a banquette in the middle of the room and read the eclectic menu, my eyes instinctively scanning the prices for the least expensive item.\",\"abstract\":null,\"print_page\":\"9\",\"blog\":[],\"source\":\"The New York Times\",\"multimedia\":[],\"headline\":{\"main\":\"NEW YORK BOOKSHELF\\/NONFICTION\",\"kicker\":\"New York Bookshelf\"},\"keywords\":[{\"name\":\"persons\",\"value\":\"ELLINGTON, DUKE\"},{\"name\":\"persons\",\"value\":\"HARRIS, DANIEL\"}],\"pub_date\":\"2005-10-02T00:00:00Z\",\"document_type\":\"article\",\"news_desk\":\"The City Weekly Desk\",\"section_name\":\"New York and Region\",\"subsection_name\":null,\"byline\":{\"person\":[{\"firstname\":\"N.\",\"middl\n" - ] - } - ], - "source": [ - "# Inspect the content of the response, parsing the result as text\n", - "response_text= r.text\n", - "print(response_text[:1000])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "What you see here is JSON text, encoded as unicode text. JSON stands for \"Javascript object notation.\" It has a very similar structure to a python dictionary -- both are built on key/value pairs. This makes it easy to convert JSON response to a python dictionary." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Convert JSON response to a dictionary\n", - "data=json.loads(response_text)\n", - "# data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "That looks intimidating! But it's really just a big dictionary. Let's see what keys we got in there." - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "#data" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": { - "collapsed": false, - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "dict_keys(['response', 'copyright', 'status'])" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data.keys()" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'OK'" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# this is boring\n", - "data['status']" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'Copyright (c) 2013 The New York Times Company. All Rights Reserved.'" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# so is this\n", - "data['copyright']" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# this is what we want!\n", - "#data['response']" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "dict_keys(['meta', 'docs'])" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data['response'].keys()" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'hits': 77, 'offset': 0, 'time': 36}" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data['response']['meta']" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# data['response']['docs']\n", - "type(data['response']['docs'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "That looks what we want! Let's put that in it's own variable." - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "docs = data['response']['docs']" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'_id': '4fd2872b8eb7c8105d858553',\n", - " 'abstract': None,\n", - " 'blog': [],\n", - " 'byline': {'original': 'By N.R. Kleinfield',\n", - " 'person': [{'firstname': 'N.',\n", - " 'lastname': 'Kleinfield',\n", - " 'middlename': 'R.',\n", - " 'organization': '',\n", - " 'rank': 1,\n", - " 'role': 'reported'}]},\n", - " 'document_type': 'article',\n", - " 'headline': {'kicker': 'New York Bookshelf',\n", - " 'main': 'NEW YORK BOOKSHELF/NONFICTION'},\n", - " 'keywords': [{'name': 'persons', 'value': 'ELLINGTON, DUKE'},\n", - " {'name': 'persons', 'value': 'HARRIS, DANIEL'}],\n", - " 'lead_paragraph': \"A WIDOW'S WALK: A Memoir of 9/11 By Marian Fontana Simon & Schuster ($24, hardcover) Theresa and I walk into the Blue Ribbon, an expensive, trendy restaurant on Fifth Avenue in Park Slope. We sit at a banquette in the middle of the room and read the eclectic menu, my eyes instinctively scanning the prices for the least expensive item.\",\n", - " 'multimedia': [],\n", - " 'news_desk': 'The City Weekly Desk',\n", - " 'print_page': '9',\n", - " 'pub_date': '2005-10-02T00:00:00Z',\n", - " 'section_name': 'New York and Region',\n", - " 'slideshow_credits': None,\n", - " 'snippet': \"A WIDOW'S WALK:.\",\n", - " 'source': 'The New York Times',\n", - " 'subsection_name': None,\n", - " 'type_of_material': 'News',\n", - " 'web_url': 'http://www.nytimes.com/2005/10/02/nyregion/02bookshelf.html',\n", - " 'word_count': 629}" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "docs[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 3. Putting everything together to get all the articles." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "That's great. But we only have 10 items. The original response said we had 171 hits! Which means we have to make 171 /10, or 18 requests to get them all. Sounds like a job for a loop! \n", - "\n", - "But first, let's review what we've done so far." - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "number of hits: 77\n", - "collecting page 0\n", - "collecting page 1\n", - "collecting page 2\n", - "collecting page 3\n", - "collecting page 4\n", - "collecting page 5\n", - "collecting page 6\n", - "collecting page 7\n" - ] - } - ], - "source": [ - "# set key\n", - "key=\"6e23901ee0fc07f0f6cee3a45b566bc5:13:73313103\"\n", - "# set base url\n", - "base_url=\"http://api.nytimes.com/svc/search/v2/articlesearch\"\n", - "# set response format\n", - "response_format=\".json\"\n", - "# set search parameters\n", - "search_params = {\"q\":\"Duke Ellington\",\n", - " \"api-key\":key,\n", - " \"begin_date\":\"20050101\", # date must be in YYYYMMDD format\n", - " \"end_date\":\"20051231\"}\n", - "# make request\n", - "r = requests.get(base_url+response_format, params=search_params)\n", - "# convert to a dictionary\n", - "data=json.loads(r.text)\n", - "# get number of hits\n", - "hits = data['response']['meta']['hits']\n", - "print(\"number of hits: \" + str(hits))\n", - "# get number of pages\n", - "pages = int(math.ceil(hits/10))\n", - "# make an empty list where we'll hold all of our docs for every page\n", - "all_docs = [] \n", - "# now we're ready to loop through the pages\n", - "for i in range(pages):\n", - " print(\"collecting page \" + str(i))\n", - " # set the page parameter\n", - " search_params['page'] = i\n", - " # make request\n", - " r = requests.get(base_url+response_format, params=search_params)\n", - " # get text and convert to a dictionary\n", - " data=json.loads(r.text)\n", - " # get just the docs\n", - " docs = data['response']['docs']\n", - " # add those docs to the big list\n", - " all_docs = all_docs + docs" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "77" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(all_docs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Challenge 3: Make a function\n", - "\n", - "Turn the code above into a function that inputs a search term, and returns all the documents containing that search term in 2014." - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "#YOUR CODE HERE\n", - "\n", - "def search_nyt_2014(term, year = 2014):\n", - " # set key\n", - " key=\"6e23901ee0fc07f0f6cee3a45b566bc5:13:73313103\"\n", - " # set base url\n", - " base_url=\"http://api.nytimes.com/svc/search/v2/articlesearch\"\n", - " # set response format\n", - " response_format=\".json\"\n", - " # set search parameters\n", - " search_params = {\"q\":term,\n", - " \"api-key\":key,\n", - " \"begin_date\":str(year)+\"0101\", # date must be in YYYYMMDD format\n", - " \"end_date\":str(year)+\"1231\"}\n", - " # make request\n", - " r = requests.get(base_url+response_format, params=search_params)\n", - " # convert to a dictionary\n", - " data=json.loads(r.text)\n", - " # get number of hits\n", - " hits = data['response']['meta']['hits']\n", - " print(\"number of hits: \" + str(hits))\n", - " # get number of pages\n", - " pages = int(math.ceil(hits/10))\n", - " # make an empty list where we'll hold all of our docs for every page\n", - " all_docs = [] \n", - " # now we're ready to loop through the pages\n", - " for i in range(pages):\n", - " print(\"collecting page \" + str(i))\n", - " # set the page parameter\n", - " search_params['page'] = i\n", - " # make request\n", - " r = requests.get(base_url+response_format, params=search_params)\n", - " # get text and convert to a dictionary\n", - " data=json.loads(r.text)\n", - " # get just the docs\n", - " docs = data['response']['docs']\n", - " # add those docs to the big list\n", - " all_docs = all_docs + docs\n", - " return all_docs" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "number of hits: 572\n", - "collecting page 0\n", - "collecting page 1\n", - "collecting page 2\n", - "collecting page 3\n", - "collecting page 4\n", - "collecting page 5\n", - "collecting page 6\n", - "collecting page 7\n", - "collecting page 8\n", - "collecting page 9\n", - "collecting page 10\n", - "collecting page 11\n", - "collecting page 12\n", - "collecting page 13\n", - "collecting page 14\n", - "collecting page 15\n", - "collecting page 16\n", - "collecting page 17\n", - "collecting page 18\n", - "collecting page 19\n", - "collecting page 20\n", - "collecting page 21\n", - "collecting page 22\n", - "collecting page 23\n", - "collecting page 24\n", - "collecting page 25\n", - "collecting page 26\n", - "collecting page 27\n", - "collecting page 28\n", - "collecting page 29\n", - "collecting page 30\n", - "collecting page 31\n", - "collecting page 32\n", - "collecting page 33\n", - "collecting page 34\n", - "collecting page 35\n", - "collecting page 36\n", - "collecting page 37\n", - "collecting page 38\n", - "collecting page 39\n", - "collecting page 40\n", - "collecting page 41\n", - "collecting page 42\n", - "collecting page 43\n", - "collecting page 44\n", - "collecting page 45\n", - "collecting page 46\n", - "collecting page 47\n", - "collecting page 48\n", - "collecting page 49\n", - "collecting page 50\n", - "collecting page 51\n", - "collecting page 52\n", - "collecting page 53\n", - "collecting page 54\n", - "collecting page 55\n", - "collecting page 56\n", - "collecting page 57\n" - ] - } - ], - "source": [ - "stuff = search_nyt_2014(\"marco rubio\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 4. Formatting and Exporting\n", - "\n", - "Let's take another look at one of these documents." - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'_id': '53755d9c79881068df7c36a4',\n", - " 'abstract': \"Paul Krugman Op-Ed column criticizes Republican Sen Marco Rubio for declaring overwhelming scientific consensus on climate change to be false; contends Republicans have reached a point where allegiance to false doctrines has become crucial badge of identity; compares party's resistance to science about climate change to its insistence that runaway inflation is a problem.\",\n", - " 'blog': [],\n", - " 'byline': {'contributor': '',\n", - " 'original': 'By PAUL KRUGMAN',\n", - " 'person': [{'firstname': 'Paul',\n", - " 'lastname': 'KRUGMAN',\n", - " 'organization': '',\n", - " 'rank': 1,\n", - " 'role': 'reported'}]},\n", - " 'document_type': 'article',\n", - " 'headline': {'content_kicker': 'Op-Ed Columnist',\n", - " 'kicker': 'Op-Ed Columnist',\n", - " 'main': 'Points of No Return',\n", - " 'print_headline': 'Points of No Return'},\n", - " 'keywords': [{'is_major': 'Y',\n", - " 'name': 'subject',\n", - " 'rank': '1',\n", - " 'value': 'Global Warming'},\n", - " {'is_major': 'Y',\n", - " 'name': 'subject',\n", - " 'rank': '2',\n", - " 'value': 'United States Politics and Government'},\n", - " {'is_major': 'N',\n", - " 'name': 'organizations',\n", - " 'rank': '3',\n", - " 'value': 'Republican Party'},\n", - " {'is_major': 'Y', 'name': 'persons', 'rank': '4', 'value': 'Rubio, Marco'},\n", - " {'is_major': 'Y',\n", - " 'name': 'subject',\n", - " 'rank': '5',\n", - " 'value': 'Inflation (Economics)'},\n", - " {'is_major': 'N',\n", - " 'name': 'glocations',\n", - " 'rank': '6',\n", - " 'value': 'United States'}],\n", - " 'lead_paragraph': 'False doctrines on climate science have become badges of identity for Republicans, and that’s more frightening than some of the environmental change underway.',\n", - " 'multimedia': [{'height': 126,\n", - " 'legacy': {'wide': 'images/2014/10/30/opinion/krugman-new-1114/krugman-new-1114-thumbWide.jpg',\n", - " 'wideheight': '126',\n", - " 'widewidth': '190'},\n", - " 'subtype': 'wide',\n", - " 'type': 'image',\n", - " 'url': 'images/2014/10/30/opinion/krugman-new-1114/krugman-new-1114-thumbWide.jpg',\n", - " 'width': 190},\n", - " {'height': 900,\n", - " 'legacy': {'xlarge': 'images/2014/10/30/opinion/krugman-new-1114/krugman-new-1114-articleLarge.jpg',\n", - " 'xlargeheight': '900',\n", - " 'xlargewidth': '600'},\n", - " 'subtype': 'xlarge',\n", - " 'type': 'image',\n", - " 'url': 'images/2014/10/30/opinion/krugman-new-1114/krugman-new-1114-articleLarge.jpg',\n", - " 'width': 600},\n", - " {'height': 75,\n", - " 'legacy': {'thumbnail': 'images/2014/10/30/opinion/krugman-new-1114/krugman-new-1114-thumbStandard.jpg',\n", - " 'thumbnailheight': '75',\n", - " 'thumbnailwidth': '75'},\n", - " 'subtype': 'thumbnail',\n", - " 'type': 'image',\n", - " 'url': 'images/2014/10/30/opinion/krugman-new-1114/krugman-new-1114-thumbStandard.jpg',\n", - " 'width': 75}],\n", - " 'news_desk': 'Editorial',\n", - " 'print_page': '27',\n", - " 'pub_date': '2014-05-16T00:00:00Z',\n", - " 'section_name': 'Opinion',\n", - " 'slideshow_credits': None,\n", - " 'snippet': 'False doctrines on climate science have become badges of identity for Republicans, and that’s more frightening than some of the environmental change underway.',\n", - " 'source': 'The New York Times',\n", - " 'subsection_name': None,\n", - " 'type_of_material': 'Op-Ed',\n", - " 'web_url': 'http://www.nytimes.com/2014/05/16/opinion/krugman-points-of-no-return.html',\n", - " 'word_count': '786'}" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "stuff[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is all great, but it's pretty messy. What we’d really like to to have, eventually, is a CSV, with each row representing an article, and each column representing something about that article (header, date, etc). As we saw before, the best way to do this is to make a lsit of dictionaries, with each dictionary representing an article and each dictionary representing a field of metadata from that article (e.g. headline, date, etc.) We can do this with a custom function:" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "def format_articles(unformatted_docs):\n", - " '''\n", - " This function takes in a list of documents returned by the NYT api \n", - " and parses the documents into a list of dictionaries, \n", - " with 'id', 'header', and 'date' keys\n", - " '''\n", - " formatted = []\n", - " for i in unformatted_docs:\n", - " dic = {}\n", - " dic['id'] = i['_id']\n", - " dic['headline'] = i['headline']['main'].encode(\"utf8\")\n", - " dic['date'] = i['pub_date'][0:10] # cutting time of day.\n", - " formatted.append(dic)\n", - " return(formatted) " - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "all_formatted = format_articles(stuff)" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'date': '2014-05-16',\n", - " 'headline': b'Points of No Return',\n", - " 'id': '53755d9c79881068df7c36a4'},\n", - " {'date': '2014-12-18',\n", - " 'headline': b'2014: Rubio Criticizes Obama on Cuba',\n", - " 'id': '5493863779881048d26b30e3'},\n", - " {'date': '2014-11-11',\n", - " 'headline': b'A Well-Timed Book Tour for Rubio',\n", - " 'id': '5462503079881072f4f7304b'},\n", - " {'date': '2014-05-12',\n", - " 'headline': b'Rubio on a Presidential Bid, and Climate Change',\n", - " 'id': '536fc5c2798810420b81d1ee'},\n", - " {'date': '2014-03-02',\n", - " 'headline': b'Rubio Proposes Steps U.S. Should Take With Russia',\n", - " 'id': '531288fb79881022a8e2e718'}]" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_formatted[:5]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Challenge 4: Export the data to a CSV." - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "number of hits: 87\n", - "collecting page 0\n", - "collecting page 1\n", - "collecting page 2\n", - "collecting page 3\n", - "collecting page 4\n", - "collecting page 5\n", - "collecting page 6\n", - "collecting page 7\n", - "collecting page 8\n" - ] - } - ], - "source": [ - "import csv\n", - "stuff = search_nyt_2014(\"berkeley police california\", 2015)" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "\n", - "testfile = open('test.csv','w')\n", - "f = csv.writer(testfile)\n", - "f.writerow([\"date\", \"headline\", \"id\"])\n", - "for x in format_articles(stuff):\n", - " f.writerow([x[\"date\"],x[\"headline\"],x[\"id\"]])\n", - "testfile.close()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.4.4" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/03_lecture_code_kunal_040416.pdf b/03_lecture_code_kunal_040416.pdf deleted file mode 100644 index 9fcfc85..0000000 Binary files a/03_lecture_code_kunal_040416.pdf and /dev/null differ diff --git a/CNAME b/CNAME deleted file mode 100644 index e4c7849..0000000 --- a/CNAME +++ /dev/null @@ -1 +0,0 @@ -python.berkeley.edu diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 5f0a77e..0000000 --- a/LICENSE +++ /dev/null @@ -1,89 +0,0 @@ - -Creative Commons Attribution-NonCommercial 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -Section 1 – Definitions. - -Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. -Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. -Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. -Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. -Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. -Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. -Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. -Licensor means the individual(s) or entity(ies) granting rights under this Public License. -NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. -Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. -Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. -You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. -Section 2 – Scope. - -License grant. -Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: -reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and -produce, reproduce, and Share Adapted Material for NonCommercial purposes only. -Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. -Term. The term of this Public License is specified in Section 6(a). -Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. -Downstream recipients. -Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. -No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. -No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). -Other rights. - -Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. -Patent and trademark rights are not licensed under this Public License. -To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. -Section 3 – License Conditions. - -Your exercise of the Licensed Rights is expressly made subject to the following conditions. - -Attribution. - -If You Share the Licensed Material (including in modified form), You must: - -retain the following if it is supplied by the Licensor with the Licensed Material: -identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); -a copyright notice; -a notice that refers to this Public License; -a notice that refers to the disclaimer of warranties; -a URI or hyperlink to the Licensed Material to the extent reasonably practicable; -indicate if You modified the Licensed Material and retain an indication of any previous modifications; and -indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. -You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. -If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. -If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. -Section 4 – Sui Generis Database Rights. - -Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: - -for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; -if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and -You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. -For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. -Section 5 – Disclaimer of Warranties and Limitation of Liability. - -Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. -To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. -The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. -Section 6 – Term and Termination. - -This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. -Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: - -automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or -upon express reinstatement by the Licensor. -For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. -For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. -Sections 1, 5, 6, 7, and 8 survive termination of this Public License. -Section 7 – Other Terms and Conditions. - -The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. -Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. -Section 8 – Interpretation. - -For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. -To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. -No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. -Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. diff --git a/README.md b/README.md index 66ca61c..d4db7c9 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,10 @@ -# Python at Berkeley -Python resources of Berkeley curated in one place +python-berkeley +=============== -## Using the site -Visit [http://python.berkeley.edu](http://python.berkeley.edu). In particular, please visit: -* [New to Python](http://python.berkeley.edu/learn): the best resources for new learners -* [Community](http://python.berkeley.edu/community): a list of people, organizations, and projects in Berkeley using Python -* [Resources](http://python.berkeley.edu/resources): an extended list of resources for using and learning Python, both online and in-person -* [Past Meetings](http://python.berkeley.edu/past): The Python learners' group meets regularly, and topics from past meetings are here. +A repo that exists to host GitHub Pages for: -## Weekly Python Learners' group (in-person) -This group meets to learn both fundamentals of programming and specialized topics in Python, with emphasis on visualization and data science. All skill levels are welcome --- even if you're never programmed before! Check the [website](http://python.berkeley.edu) for meeting times and locations. +http://python.berkeley.edu -## Contributing to the site -These pages are community-curated and are open to changes. The [Resources](http://python.berkeley.edu/resources) page especially could use some help. Please make an issue or pull request with your changes. If you're unsure how to do this, please email the D-Lab front desk at [dlab-frontdesk@berkeley.edu](mailto:dlab-frontdesk@berkeley.edu). -* To run this site locally, download this repository and run ```jekyll serve --future```. -* The main pages on the website are located in ```pages/```. The home page is in ```index.md```. -* To add a meeting, look in ```_posts/``` and follow the format of the file name & content. -* To change general webpage styles, look in ```_includes/``` and ```_layouts/```. -* In the past, we've held other Python-based events. They are not directly linked on the main page for simplicity. - * We had several D-Lab Python trainings. Their homepages are in the ```trainings/``` folder. - * Dav Clark ran a Python working group in 2013-2014. His pages are located in ```_site``` and ```events```. -* I know there are other random files (.ipynb, .csv, .xlsx, .pdf) just "sitting" in the repository. They probably ARE linked on some other pages. If someone cleans this up (like putting all Spring 2016 files in a folder), please update the links on the meeting pages (check files in the ```_posts``` folder.) +Check the gh-pages branch for the Jekyll code! ---- -Thanks for visiting! +_Go Bears_ ! diff --git a/_config.yml b/_config.yml deleted file mode 100644 index 9f0c6ce..0000000 --- a/_config.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Site settings -title: Python Practice -email: dlab-frontdesk@berkeley.edu -description: > - New to programming? Here is a collection of learning resources for the - Python programming language and information about projects that use it on - the UC Berkeley campus. -gems: - - jekyll-redirect-from -future: true #so you see future posts! -github_username: dlab-berkeley/python-berkeley #for github link in footer -permalink: /:year-:month-:day-:title/ -viewsourceroot: https://github.com/dlab-berkeley/python-berkeley/edit/gh-pages/ #link in footer to edit this page - - - - -############################################ -## NOT SURE ABOUT THESE SETTINGS ## - -############################################ -newsourceroot: https://github.com/dlab-berkeley/python-berkeley/blob/gh-pages/ -############################################ -# url: "http://yourdomain.com" # the base hostname & protocol for your site -# twitter_username: jekyllrb -############################################ -# for duoshuo.com commenting system, uncomment following line if you do not want to include duoshuo.com. -#duoshuo_shortname: lixizhi -#duoshuo_url: "http://lixizhi.github.io" -# disqus.com commenting system. please note that it is exclusive with duoshuo.com -#disqus_shortname: lixizhi -#disqus_url: "http://lixizhi.github.io" -######################################### -# Build settings -# This is default -markdown: kramdown -kramdown: - smart_quotes: ["apos", "apos", "quot", "quot"] #smart quotes do stupid things with this theme, so turns them off -# The default highlighter for Jekyll, and the ONLY one on GitHub -# highlighter: rouge diff --git a/_includes/JB/analytics b/_includes/JB/analytics deleted file mode 100644 index 951a0e3..0000000 --- a/_includes/JB/analytics +++ /dev/null @@ -1,16 +0,0 @@ -{% if site.safe and site.JB.analytics.provider and page.JB.analytics != false %} - -{% case site.JB.analytics.provider %} -{% when "google" %} - {% include JB/analytics-providers/google %} -{% when "getclicky" %} - {% include JB/analytics-providers/getclicky %} -{% when "mixpanel" %} - {% include JB/analytics-providers/mixpanel %} -{% when "piwik" %} - {% include JB/analytics-providers/piwik %} -{% when "custom" %} - {% include custom/analytics %} -{% endcase %} - -{% endif %} \ No newline at end of file diff --git a/_includes/JB/analytics-providers/getclicky b/_includes/JB/analytics-providers/getclicky deleted file mode 100644 index e9462f4..0000000 --- a/_includes/JB/analytics-providers/getclicky +++ /dev/null @@ -1,12 +0,0 @@ - - diff --git a/_includes/JB/analytics-providers/google b/_includes/JB/analytics-providers/google deleted file mode 100644 index 9014866..0000000 --- a/_includes/JB/analytics-providers/google +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/_includes/JB/analytics-providers/mixpanel b/_includes/JB/analytics-providers/mixpanel deleted file mode 100644 index 4406eb0..0000000 --- a/_includes/JB/analytics-providers/mixpanel +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/_includes/JB/analytics-providers/piwik b/_includes/JB/analytics-providers/piwik deleted file mode 100755 index 077a373..0000000 --- a/_includes/JB/analytics-providers/piwik +++ /dev/null @@ -1,10 +0,0 @@ - \ No newline at end of file diff --git a/_includes/JB/categories_list b/_includes/JB/categories_list deleted file mode 100644 index 83be2e2..0000000 --- a/_includes/JB/categories_list +++ /dev/null @@ -1,37 +0,0 @@ -{% comment %}{% endcomment %} - -{% if site.JB.categories_list.provider == "custom" %} - {% include custom/categories_list %} -{% else %} - {% if categories_list.first[0] == null %} - {% for category in categories_list %} -
  • - {{ category | join: "/" }} {{ site.categories[category].size }} -
  • - {% endfor %} - {% else %} - {% for category in categories_list %} -
  • - {{ category[0] | join: "/" }} {{ category[1].size }} -
  • - {% endfor %} - {% endif %} -{% endif %} -{% assign categories_list = nil %} \ No newline at end of file diff --git a/_includes/JB/comments b/_includes/JB/comments deleted file mode 100644 index 4e9e600..0000000 --- a/_includes/JB/comments +++ /dev/null @@ -1,16 +0,0 @@ -{% if site.JB.comments.provider and page.comments != false %} - -{% case site.JB.comments.provider %} -{% when "disqus" %} - {% include JB/comments-providers/disqus %} -{% when "livefyre" %} - {% include JB/comments-providers/livefyre %} -{% when "intensedebate" %} - {% include JB/comments-providers/intensedebate %} -{% when "facebook" %} - {% include JB/comments-providers/facebook %} -{% when "custom" %} - {% include custom/comments %} -{% endcase %} - -{% endif %} \ No newline at end of file diff --git a/_includes/JB/comments-providers/disqus b/_includes/JB/comments-providers/disqus deleted file mode 100644 index 618a7b7..0000000 --- a/_includes/JB/comments-providers/disqus +++ /dev/null @@ -1,14 +0,0 @@ -
    - - -blog comments powered by Disqus diff --git a/_includes/JB/comments-providers/facebook b/_includes/JB/comments-providers/facebook deleted file mode 100644 index 6b3e5e0..0000000 --- a/_includes/JB/comments-providers/facebook +++ /dev/null @@ -1,9 +0,0 @@ -
    - -
    \ No newline at end of file diff --git a/_includes/JB/comments-providers/intensedebate b/_includes/JB/comments-providers/intensedebate deleted file mode 100644 index ab0c3c9..0000000 --- a/_includes/JB/comments-providers/intensedebate +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/_includes/JB/comments-providers/livefyre b/_includes/JB/comments-providers/livefyre deleted file mode 100644 index 704b803..0000000 --- a/_includes/JB/comments-providers/livefyre +++ /dev/null @@ -1,6 +0,0 @@ - - \ No newline at end of file diff --git a/_includes/JB/liquid_raw b/_includes/JB/liquid_raw deleted file mode 100644 index a5c1783..0000000 --- a/_includes/JB/liquid_raw +++ /dev/null @@ -1,32 +0,0 @@ -{% comment%}{% endcomment%} - -{% if site.JB.liquid_raw.provider == "custom" %} - {% include custom/liquid_raw %} -{% else %} -
    {{text | replace:"|.", "{" | replace:".|", "}" | replace:">", ">" | replace:"<", "<" }}
    -{% endif %} -{% assign text = nil %} \ No newline at end of file diff --git a/_includes/JB/pages_list b/_includes/JB/pages_list deleted file mode 100644 index 42f827a..0000000 --- a/_includes/JB/pages_list +++ /dev/null @@ -1,39 +0,0 @@ -{% comment %}{% endcomment %} - -{% if site.JB.pages_list.provider == "custom" %} - {% include custom/pages_list %} -{% else %} - {% for node in pages_list %} - {% if node.title != null %} - {% if group == null or group == node.group %} - {% if page.url == node.url %} -
  • {{node.title}}
  • - {% else %} -
  • {{node.title}}
  • - {% endif %} - {% endif %} - {% endif %} - {% endfor %} -{% endif %} -{% assign pages_list = nil %} -{% assign group = nil %} \ No newline at end of file diff --git a/_includes/JB/posts_collate b/_includes/JB/posts_collate deleted file mode 100644 index 03c37fa..0000000 --- a/_includes/JB/posts_collate +++ /dev/null @@ -1,55 +0,0 @@ -{% comment %}{% endcomment %} - -{% if site.JB.posts_collate.provider == "custom" %} - {% include custom/posts_collate %} -{% else %} - {% for post in posts_collate %} - {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %} - {% capture this_month %}{{ post.date | date: "%B" }}{% endcapture %} - {% capture next_year %}{{ post.previous.date | date: "%Y" }}{% endcapture %} - {% capture next_month %}{{ post.previous.date | date: "%B" }}{% endcapture %} - - {% if forloop.first %} -

    {{this_year}}

    -

    {{this_month}}

    - - {% else %} - {% if this_year != next_year %} - -

    {{next_year}}

    -

    {{next_month}}

    - -

    {{next_month}}

    -