Skip to content

Instantly share code, notes, and snippets.

@francoiscolas
Last active August 29, 2015 14:15
Show Gist options
  • Save francoiscolas/e475931237e2b1f715dc to your computer and use it in GitHub Desktop.
Save francoiscolas/e475931237e2b1f715dc to your computer and use it in GitHub Desktop.
A shell script to create rollerblading events without having to use the ugly ovs website!
#!/bin/bash
if [ $# -le 0 ]
then
echo "Usage: $0 DAY-MONTH..."
exit 1
fi
USERNAME=francolas
if [ -z "$PASSWORD" ]
then
read -p "$USERNAME's password: " -s PASSWORD
echo
fi
# Fetch PHPSESSID and TOKEN values
echo -n "Fetching PHPSESSID and TOKEN values... "
declare $(curl -s -i http://angers.onvasortir.com | awk '
match($0, /(PHPSESSID=[^;]+)/, cap) {
print cap[1]
}
match($0, /<input.*value=.([a-z0-9]{40}).>/, cap) {
print "TOKEN=" cap[1]
}'
)
echo "Done"
# Authenticate
echo -n "Authenticating... "
curl -s -X POST -b"PHPSESSID=$PHPSESSID" -d"Pseudo=$USERNAME&Password=$PASSWORD&tok=$TOKEN&token2=$USERNAME" http://angers.onvasortir.com/page_action_connect_new.php
echo "Done"
# Create new events
EVENT_TITLE="Rando roller tous niveaux."
EVENT_ADDR="Place la Fayette, Angers"
EVENT_YEAR=`date +%Y`
EVENT_DESC="
<p>Bonjour &agrave; tous,</p>
<p>&nbsp;</p>
<p>Je vous propose une rando roller en deux temps. Une premi&egrave;re partie pour&nbsp;<strong>tous les niveaux</strong>, avec un rythme plut&ocirc;t cool.</p>
<p>&nbsp;</p>
<p>Ensuite, une rando <strong>plus&nbsp;sportive&nbsp;et plus&nbsp;rapide</strong>&nbsp;pour ceux qui sont&nbsp;tr&egrave;s &agrave; l'aise&nbsp;et veulent se d&eacute;penser :). L'itin&eacute;raire est choisi ensemble au fur et &agrave; mesure.</p>
<p>&nbsp;</p>
<p>D&eacute;part &agrave; 20h.&nbsp;<span style=\"font-size: 12px;\">Prenez des lumi&egrave;res et/ou gillets reflechissants. Protections recommand&eacute;es.</span></p>
<p>&nbsp;</p>
<p>Dur&eacute;e premi&egrave;re partie: 1h</p>
<p>Dur&eacute;e deux&egrave;me partie: 1h</p>
<p>D&eacute;part/retour: Place Lafayette</p>
<p>&nbsp;</p>
<p>&Agrave; bient&ocirc;t!</p>"
for DATE in "$@"
do
echo -n "Creating roller event on $DATE... "
RETVALUE=$(curl -s -i -X POST \
-b"PHPSESSID=$PHPSESSID" \
-F"Modele=" \
-F"Brouillon=0" \
-F"VideoModele=" \
-F"AgeOrga=1987" \
-F"MAX_FILE_SIZE=1000000" \
-F"file_name=@" \
-F"Dailymotion=" \
-F"Tel=" \
-F"Ouverte=tous" \
-F"TypeSortie=Sport" \
-F"Intitule=$EVENT_TITLE" \
-F"SortieTheme1=85" \
-F"SortieTheme2=" \
-F"DateCal=$DATE-$EVENT_YEAR" \
-F"Heure=19" \
-F"Minute=50" \
-F"Delai=0" \
-F"Descriptif=$EVENT_DESC" \
-F"NbMaxi=20" \
-F"Invites=oui" \
-F"Adresse=$EVENT_ADDR" \
-F"Departement=1" \
-F"RDV=$EVENT_ADDR" \
http://angers.onvasortir.com/sortie_action_create.php | awk '/^Location: sortie_read_new.php/ { print "SUCCESS" }')
if [ "$RETVALUE" = "SUCCESS" ]
then
echo "Done"
else
echo "Error"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment