summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2018-05-14 13:20:50 -0400
committerKen Kellner <ken@kenkellner.com>2018-05-14 13:20:50 -0400
commit0de31dbc37231c59ad890dd41437c91e84bac572 (patch)
tree4015c43632073203c738e0d0fb3701813ee72481
parent1a9bd939e0f65519f01287f455d5b19907fc379c (diff)
Basic RSS support
-rw-r--r--.gitignore1
-rwxr-xr-xbuild_rss.py51
-rw-r--r--makefile2
-rw-r--r--src/_navbar.yml2
-rw-r--r--src/buffalo-recycle-part1.Rmd5
5 files changed, 59 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index ccf4f58..43c785d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.html
+*.xml
data/*
diff --git a/build_rss.py b/build_rss.py
new file mode 100755
index 0000000..f8eb4ba
--- /dev/null
+++ b/build_rss.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python3
+
+from feedgen.feed import FeedGenerator
+import os
+import re
+import operator
+from datetime import datetime
+
+leader='https://kenkellner.com/blog/'
+
+links = os.listdir('build')
+links.remove('index.html')
+links.remove('feed.xml')
+
+src = []
+for i in links:
+ src.append('src/'+i.replace('.html','.Rmd'))
+
+dates = []
+for i in src:
+ for line in open(i):
+ if 'date: ' in line:
+ dates.append(line.split(': ')[1].strip('\n'))
+
+titles = []
+for i in src:
+ for line in open(i):
+ if 'title: ' in line:
+ titles.append(line.split(': ')[1].strip('\n'))
+
+dates, links, titles = zip(*sorted(zip(dates, links, titles)))
+
+fg = FeedGenerator()
+fg.id(leader)
+fg.link(href=leader+'feed.xml', rel='self')
+fg.title('Ken Kellner\'s Blog')
+fg.subtitle(' ')
+fg.language('en')
+
+for i in range(len(dates)):
+ fe = fg.add_entry()
+ fe.title(titles[i])
+ fe.id(leader+links[i])
+ fe.link(href=leader+links[i])
+ fe.author({'name': 'Ken Kellner', 'email': 'contact@kenkellner.com'})
+ fe.description('')
+ date_raw = dates[i]+' -0500'
+ fe.published(datetime.strptime(date_raw, '%Y-%m-%d %z'))
+
+fg.rss_str(pretty=True)
+fg.rss_file('build/feed.xml')
diff --git a/makefile b/makefile
index b50fbb2..4b8c331 100644
--- a/makefile
+++ b/makefile
@@ -8,6 +8,8 @@ all: $(RMD_OUT)
@mkdir -p build
@echo "Building index"
@Rscript build_RMD.R $(SRC)/index.Rmd $(BUILD)/index.html > /dev/null 2>&1
+ @echo "Building RSS"
+ @python3 build_rss.py
@echo "Done"
deploy:
diff --git a/src/_navbar.yml b/src/_navbar.yml
index eeda306..4983979 100644
--- a/src/_navbar.yml
+++ b/src/_navbar.yml
@@ -3,3 +3,5 @@ left:
href: https://kenkellner.com
- text: "Posts"
href: https://kenkellner.com/blog
+ - text: "RSS"
+ href: https://kenkellner.com/blog/feed.xml
diff --git a/src/buffalo-recycle-part1.Rmd b/src/buffalo-recycle-part1.Rmd
index 22ee47c..93cc7c7 100644
--- a/src/buffalo-recycle-part1.Rmd
+++ b/src/buffalo-recycle-part1.Rmd
@@ -36,13 +36,14 @@ head(buf_datasets$title)
I'm going to explore the first dataset listed, which provides monthly recycling rates for different Buffalo neighborhoods. The dataset is available in several formats:
```{r}
-buf_datasets$distribution[[1]]$mediaType
+ind = which(buf_datasets$title == 'Neighborhood Curbside Recycling Rates')
+buf_datasets$distribution[[ind]]$mediaType
```
You can get the URL for the CSV dataset with `$downloadURL`:
```{r}
-csv_url = buf_datasets$distribution[[1]]$downloadURL[1]
+csv_url = buf_datasets$distribution[[ind]]$downloadURL[1]
csv_url
```