Created
November 17, 2013 05:56
-
-
Save 1rick/7509834 to your computer and use it in GitHub Desktop.
generate weekly wordpress roundup list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""a script for fetching posts from wordpress, and then autogenerating markdown files for end-of-week-posts.""" | |
from __future__ import division, print_function | |
import xmlrpclib | |
import datetime | |
import os | |
from bs4 import BeautifulSoup | |
MAX_POSTS = 100 | |
#adjust for your own domain | |
url = 'http://YOUR_DOMAIN.com/xmlrpc.php' | |
#input your blog username and pw | |
myusername = 'YOUR_WP_USERNAME' | |
mypassword = 'YOUR_WP_PASSWORD' | |
#fill in your desired categories. note that you don't want to have a post assigned to more than one, or you'll have duplicates. | |
all_categories = ['Featured', 'Business', 'Design', 'Apps', 'Startups', 'Uncategorized'] | |
#for weekly roundup posts, figure out date for when the past week started, i.e. last monday | |
today = datetime.date.today() | |
last_monday = str(today - datetime.timedelta(days=today.weekday())) | |
lastmonday_fourdigit = last_monday[5:7] + last_monday[8:10] | |
server = xmlrpclib.ServerProxy(url) | |
result = server.metaWeblog.getRecentPosts(url, myusername, mypassword, MAX_POSTS) | |
f = open("weekly.md", "wb") | |
for category in all_categories: | |
print('', file=f) | |
print("""###""", category, file=f) | |
for post in result: | |
post_title = post['title'].encode('ascii', 'ignore') | |
post_date = str(post['date_created_gmt']) | |
tags = post['mt_keywords'] | |
categories = post['categories'] | |
description = post['description'] | |
desc_minus_image = BeautifulSoup(description).get_text() | |
permalink = post['permaLink'].encode('ascii', 'ignore') | |
# if tag_to_fetch in tags and post_date[4:8] >= lastmonday_fourdigit: | |
if category in categories and post_date[4:8] >= lastmonday_fourdigit: | |
print("""* [%s](%s) %s/%s""" % (post_title, permalink, post_date[4:6], post_date[6:8]), file=f) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment