Publishing to drupal with org2blog

org2blog is an org-mode plugin which allows to publish an org file to a wordpress blog. The connection between org-mode and wordpress is achived through an xmlrpc call using the metaweblog api.

My blog is powered by drupal which supports xmlrpc calls and the metaweblog api. The setup although was not straightforward. In this post I'm going to show the steps that I followed in order to make it work.


First of all in order to enable xmlrpc calls to our drupal blog we need to install the blog api:

root@mazinga:/var/www# drush dl blogapi
Project blogapi (7.x-2.0-rc1) downloaded to /var/www/sites/all/modules/blogapi.                                                                     [success]
Project blogapi contains 4 modules: blogapi_movabletype, blogapi_blogger, blogapi_metaweblog, blogapi.

root@mazinga:/var/www# drush en blogapi
The following projects have unmet dependencies:
blogapi requires services
Would you like to download them? (y/n): y
Project services (7.x-3.19) downloaded to /var/www/sites/all/modules/services. [success]
Project services contains 4 modules: services_oauth, rest_server, xmlrpc_server, services.
The following projects have unmet dependencies:
blogapi requires ctools
Would you like to download them? (y/n): y
Project ctools (7.x-1.12) downloaded to /var/www/sites/all/modules/ctools.     [success]
Project ctools contains 10 modules: ctools_ajax_sample, page_manager, views_content, bulk_export, 
ctools_plugin_example, ctools_custom_content, ctools_access_ruleset, term_depth, stylizer, ctools.
failed to open stream: No such file or                                         [warning]
The following extensions will be enabled: blogapi, ctools, services
Do you really want to continue? (y/n): y
blogapi was enabled successfully.                                              [ok]
ctools was enabled successfully.                                               [ok]
services was enabled successfully.                                             [ok]

Then we need to enable some stuff, so we have to log in as user/1 on our site, go to modules section and check:

  • BlogAPI
  • MetaWeblog Provider for BlogAPI
  • Services
  • XMLRPC Server

The services module has to be configured so go to Modules/services/Configure and select Edit Resources. Here we can choose which methods we would like to enable. I selected all the methods.

In Configuration/Web services/BlogAPI enable MetaWeblog as the default provider for xmlrpc APIs.

Configuration in drupal is almost done, the last step is to write down the endpoint of the xmlrpc service. This information is in: Modules/services/Configure/Modify/Path to endpoint


We need to install org2blog and enable it, then we define the handle to our blog:

(require 'org2blog-autoloads)
;;; org2blog
(setq org2blog/wp-blog-alist
         :url ""
         :default-categories ("linux")
         :tags-as-categories nil
         :id "blog"
         :username "XXXX"
         :password "YYYY" )))

The relevant parts here are:

  • url is composed by site_url plus xmlrpc path end point
  • id is the id our blog, we must specify this option otherwise org2blog defaults to id 1 which is not present in drupal

org2blog uses some wordpress apis which are not compatible with drupal: if we try to connect to our blog we get an error. We have to redefine two functions to bypass those errors:

(eval-after-load "metaweblog"
  '(defun wp-get-tags (blog-xmlrpc user-name password blog-id)
     "Retrieves list of tags from the weblog system. Uses wp.getTags"
     (xml-rpc-method-call blog-xmlrpc

(eval-after-load "metaweblog"
  '(defun wp-get-pagelist (blog-xmlrpc user-name password blog-id)
     (xml-rpc-method-call blog-xmlrpc

That should be all that is needed.

What's next

I have to understand how to upload images (I receive a SQL error when I publish a post with an image inside) and how to attach categories to a post, but I'm pretty satisfied with the actual integration: this post for example is published using org2blog!



Monitorare la dimensione di un filesystem

In Linux per conoscere quanto spazio resta ai filesystems si usa il comando df. Un esempio di output del comando è:

root@mazinga:~# df -lh
Filesystem                 Size  Used Avail Use% Mounted on
rootfs                      20G  3.3G   16G  18% /
udev                        10M     0   10M   0% /dev
tmpfs                       50M  144K   50M   1% /run
/dev/disk/by-label/DOROOT   20G  3.3G   16G  18% /
tmpfs                      5.0M     0  5.0M   0% /run/lock
tmpfs                      100M     0  100M   0% /run/shm

Se si volesse quindi monitorare lo stato di un particolare mount point si può usare uno script come il seguente:

# lo script confronta la percenuale di spazio utilizzata nel filesystem / con $SOGLIA
# se la percentuale supera $SOGLIA invia una mail a $RECIPIENTS
# imposto una soglia del 90%
# imposto i destinatari della mail
now=`date +%y%m%d-%H%M%S`
perc_root=`df -Ph -x tmpfs -x rootfs | grep "/$" |  tr -s ' ' '\t' | cut -f5 -s | cut -d '%' -f1`
msg="Analizzatore dell'uso dello spazio su disco (SOGLIA impostata a "${SOGLIA}"):\n\n"
if [[ "${perc_root}" -ge "${SOGLIA}" ]] ; then
    msg+="Il file system '/' sta utilizzando il "${perc_var}"% del suo spazio disponibile\n"
if "${found}" ; then
    echo -e ${msg} | mail -s "Controllo su spazio disco del ${now}" $RECIPIENTS

La parte interessante è il comando che ricava la percentuale da df:

  • la prima parte (df -Ph -x tmpfs -x rootfs) invoca il comando df usando il flag -x che permette di escludere un filesystem e il flag -P che imposta l'output in formato POSIX (i dati dei filesystem sono tutti nella stessa riga);
  • la seconda parte ( grep "/$" ) serve a puntare il filesystem desiderato;
  • la terza parte serve a puntare la colonna desiderata e ripulisce il campo dal carattere % in modo da poterlo usare in un test.

Lo script se messo in cron inizierà ad inviarvi una mail non appena lo spazio utilizzato nel filesystem root arriverà a superare il 90%.



Postgres da record set a csv

Oggi mi è capitato di dover ottenere un csv a partire da un record set di chiavi. Supponiamo quindi di avere un'entita che ha una chiave numerica e di voler ottenere un csv con tutte le chiavi.

L'entità è così formata:

test=> \d utente
           Table "public.utente"
 Column |         Type          | Modifiers 
 id     | numeric(9,0)          | not null
 name   | character varying(50) | 
    "utente_id_key" UNIQUE CONSTRAINT, btree (id)
test=> select * from utente;
 id |   name   
  1 | ciccio
  2 | paperino
  3 | pluto
  4 | minnie
  5 | paperina
(5 rows)

Per avere il csv di tutte le chiavi useremo la seguente query che sfrutta la funzione string_agg:

test=> select string_agg(id::text, ',') as csv from (select id from utente) as foo;
(1 row)

Questa e altre funzioni le trovate documentate nel sito di postgres.




Subscribe to gtrev RSS