Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SCRIPT] Poster automatiquement sur livejournal
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
Trevoke
Advocate
Advocate


Joined: 04 Sep 2004
Posts: 4099
Location: NY, NY

PostPosted: Tue Nov 22, 2005 2:29 pm    Post subject: [SCRIPT] Poster automatiquement sur livejournal Reply with quote

Tout d'abord, commencons par le soft qu'on va utiliser :
Code:
$ eix jlj
* net-misc/jlj
     Available versions:  2.5 2.7
     Installed:           2.7
     Homepage:            http://www.cis.rit.edu/~sdlpci/Software/perl/#jlj
     Description:         A simple console LiveJournal entry system.


Je vous laisse le soin de le configurer, c'est vraiment pas sorcier (on est loin d'un sendmail).
Le script va poster un chapitre du Tao (de 1 a 81 avec iteration, et retour au premier chapitre, etc) dans la communaute daily_tao.
Copier le script dans /etc/cron.daily/ (j'utilise fcron) me suffit pour qu'il poste a 3h10 du matin automatiquement ;-).

Code:
/home/alg/scripts/tao
root@Gen2Al: pts/4: 5 files 84Kb -> ls -lah
total 84K
drwxr-xr-x  4 alg users   9 2005-09-29 08:30 .
drwxr-xr-x  4 alg users  10 2005-11-21 09:06 ..
-rw-r--r--  1 alg users 40K 2005-09-29 08:29 beatricetao.txt
-rw-r--r--  1 alg users 504 2005-11-22 03:10 .body
-rw-r--r--  1 alg users 38K 2005-09-23 11:19 tao
-rw-r--r--  1 alg users   2 2005-11-22 03:10 .taocounter
-rwxr-xr-x  1 alg users 444 2005-11-22 08:55 Taoscript.sh


beatricetao.txt et tao sont mes deux fichiers sources. Ils sont formates comme des fichiers pour fortune, c'est-a-dire :

Quote:
The Tao that can be told is not the eternal Tao.
The name that can be named is not the eternal name.
The nameless is the beginning of heaven and Earth.
The named is the mother of the ten thousand things.
Ever desireless, one can see the mystery.
Ever desiring, one sees the manifestations.
These two spring from the same source but differ in name; this appears as darkness.
Darkness within darkness.
The gate to all mystery.
%
Under heaven all can see beauty as beauty only because there is ugliness.
All can know good as good only because there is evil.
Therefore having and not having arise together.
Difficult and easy complement each other.
Long and short contrast each other:
High and low rest upon each other;
Voice and sound harmonize each other;
Front and back follow one another.
Therefore the sage goes about doing nothing, teaching no-talking.
The ten thousand things rise and fall without cease,
Creating, yet not.
Working, yet not taking credit.
Work is done, then forgotten.
Therefore it lasts forever.
%


Il y a une ligne mais pas de % a la fin du fichier.

.body contient le corps du message, et .taocounter contient le numero du chapitre du Tao.

Code:
$ cat Taoscript.sh
#!/bin/bash

cd /home/alg/scripts/tao         #Le repertoire dans lequel il y a toutes les variables
TAO_COUNTER=`cat .taocounter`


if [[ $TAO_COUNTER > 80 ]]
   then TAO_COUNTER=0
fi


awk '/^%$/{nr++} nr==sec,/^%$/{if(!/^%$/)print}' sec=$TAO_COUNTER tao > .body
echo '%' >> .body
echo '%' >> .body
awk '/^%$/{nr++} nr==sec,/^%$/{if(!/^%$/)print}' sec=$TAO_COUNTER beatricetao.txt >> .body

let "TAO_COUNTER += 1"
echo $TAO_COUNTER > .taocounter

jlj -bf .body -ec daily_tao -es `cat .taocounter` -ne -s


La ligne de jlj, a la fin, nous indique :
-bf : utilise ceci pour le corps du message
-ec : poste dans cette communaute/journal
-es : utilise ceci comme sujet du message
-ne : on n'edite pas le message, on l'envoie tel quel
-s : on envoie le message!

Ce script n'est pas parfait; il ne devrait pas dependre du nombre de chapitres dans le Tao, mais je ne suis pas sur de quel genre de verification je devrais faire a la place, quelque chose du genre "si le corps est vide, alors on retourne a 0" peut-etre...
_________________
Votre moment detente
What is the nature of conflict?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum