Recevez les publications wordpress de la semaine dernière

This is a simple script for fetching a list of your posts for the last seven days, or since the previous Monday. I sometimes use this to generate weekly summary posts over on SD Japan.

It should output to .md file or something, but for now I just copy the output from terminal and bring into Textmate, rendering Markdown with Marked.

Here's the code. Feedback and improvements welcome.

(I'm a beginner programmer, so this code is very ugly and really sucks. I'm mostly just testing out Kobito/Qiita here.)

get_weekly_posts.py



#!/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
import xmlrpclib
import datetime
from bs4 import BeautifulSoup
 
MAX_POSTS = 30
#adjust for your own domain
url = 'http://www.example.com/wp/xmlrpc.php'
#input your blog username and pw
myusername = 'USERNAME'
mypassword = 'PASSWORD'
#write tag to fetch
#tag_to_fetch = 'ADD ANY TAG'
category1 = 'SAMPLECATEGORY1'
category2 = 'SAMPLECATEGORY2'
category3 = 'SAMPLECATEGORY3'
category4 = 'SAMPLECATEGORY4'
category5 = 'SAMPLECATEGORY5'


#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)

print """###""", category1
for post in result:
  post_title = post['title']
  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']
#  if tag_to_fetch in tags and post_date[4:8] >= lastmonday_fourdigit:
  if category1 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])
   
print ''

print """###""", category2
for post in result:
  post_title = post['title']
  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']
#  if tag_to_fetch in tags and post_date[4:8] >= lastmonday_fourdigit:
  if category2 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])

print ''

print """###""", category3
for post in result:
  post_title = post['title']
  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']
#  if tag_to_fetch in tags and post_date[4:8] >= lastmonday_fourdigit:
  if category3 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])

print ''

print """###""", category4
for post in result:
  post_title = post['title']
  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']
#  if tag_to_fetch in tags and post_date[4:8] >= lastmonday_fourdigit:
  if category4 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])

print ''

print """###""", category5
for post in result:
  post_title = post['title']
  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']
#  if tag_to_fetch in tags and post_date[4:8] >= lastmonday_fourdigit:
  if category5 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])



Recommended Posts

Recevez les publications wordpress de la semaine dernière
Obtenir une adresse à partir d'un code postal
Obtenez l'adresse à partir de la latitude et de la longitude
[Python] Obtenez la couleur principale de la capture d'écran
Récupérez uniquement le texte du formulaire Django.
Récupérer le contenu de git diff depuis python
Obtenez un jour de la cérémonie conjointe de Zeller - et du calendrier perpétuel -
[Python] Get the day (anglais et japonais)
[Python] Récupérez le texte de la loi à partir de l'API e-GOV law
Récupérer le code retour d'un script Python depuis bat
Obtenir les messages Google+ AKB48
Obtenez la version GNOME
Obtenir le type MIME
Obtenez la version du package pour vous inscrire à PyPI à partir de Git
Obtenez la valeur tout en spécifiant la valeur par défaut de dict en Python
J'ai essayé d'obtenir diverses informations de l'API codeforces