Commit 28eb6be9 authored by Eliot Berriot's avatar Eliot Berriot

README

parents
# Setup:
Add a `~/.twiliorc` file containing twilio credentials:
ACCOUNTSID=abc123456
AUTHTOKEN=789456123
CALLERID=33644000000
Then clone the repository.
# Usage
Generate a message:
python pumpitup/message.py
PUMPITUP_TYPE=work python pumpitup/message.py
PUMPITUP_TYPE=sleep python pumpitup/message.py
If you don't have a PUMPITUP_TYPE environment variable set, it will
use the current weekday to determine the value:
- Monday-friday -> work
- Saturday-sunday -> sleep
# Send the message via SMS
Easy:
python pumpitup/message.py | ./twilio-sms <recipient>
python pumpitup/message.py | ./twilio-sms 33646791325
# Automate the whole thing
To send a message everyday at 10:
crontab -e
0 10 * * * cd /path/to/repo && python pumpitup/message.py | ./twilio-sms 33646791325
# coding: utf8
parts = {
'work': {
'header': "Tu n'es pas {thing} !",
'things': [
'un caca',
'une endive',
'un bol de gadoue',
'une limace de mer prométhéenne',
'une assistée',
'inutile',
'en détresse professionnelle',
'mauvaise en cuisine',
],
'body': "Aujourd'hui, tu vas {action} :)",
'actions': [
'enrichir le capitalisme',
'sauver le véganisme',
'faire des trucs cools',
'cuisiner un truc bon',
'déboiter de l\'aquafaba',
'sodomiser un carniste',
'marabouter ton mixeur',
'faire chier Macron',
'toucher ton chômage',
'inventer une nouvelle recette',
'sauver le monde',
'finir ton CAP',
'me faire un calin',
],
'greetings': [
'Hasta luego !',
'Alea jacta est.',
'Bougalouh !',
'Ça va couper chérie !',
'Bonne bourre !',
'Je t\'aime !',
'Qui ne dit mot consent.',
'Piou piou !',
]
},
'sleep': {
'header': "Coucou {thing} !",
'things': [
'jeune loutre',
'petite licorne amovible',
'jeune poisson des neiges',
'petit pot de paprika',
'toi',
'bébé maki',
'petite pousse de soja',
'poupette',
],
'body': "Aujourd'hui, tu peux {action} :)",
'actions': [
'te détendre',
'dormir',
'faire une sieste',
'te gratter les fesses',
'me battrer aux dames chinoises',
'parler pour ne rien dire',
'regarder l\'intégrale de Derrick',
'écouter Guillaume Meurice',
'relire Mein Kampf',
'aller courir',
'finir l\'assassin royal',
'commander chez Panasia',
'faire un bisou à ton copain qui t\'aime',
'reprendre Stardew Valley',
'glander',
'rester sous la couette',
'sucer des cailloux',
],
'greetings': [
'Profite, c\'est pas si souvent !',
'On est pas bien là ?',
'Tu la sens la grosse sieste ?',
'Yolo !',
]
}
}
import datetime
import os
import random
import data
LIMIT = 160
TYPES = ['work', 'sleep']
def message(message_type):
if not message_type:
today = datetime.datetime.today()
message_type = 'work' if today.weekday() < 5 else 'sleep'
c = get_combinations(data.parts[message_type])
print(random.choice(list(c)))
def get_combinations(parts):
for thing in parts['things']:
for action in parts['actions']:
for greeting in parts['greetings']:
header = parts['header'].format(thing=thing)
body = parts['body'].format(action=action)
yield '\n\n'.join([header, body, greeting])
if __name__ == '__main__':
message_type = os.environ.get('PUMPITUP_TYPE')
message(message_type)
import itertools
import pytest
from . import data
from . import message
combinations = itertools.chain(
*[message.get_combinations(data.parts[t]) for t in message.TYPES]
)
@pytest.mark.parametrize('m', combinations)
def test_combination_length(m):
assert len(m) < message.LIMIT
print(m, len(m))
#!/bin/bash
#####################################################################
#
# Copyright (c) 2010 Twilio, Inc.
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
######################################################################
function usage
{
if [ -n "$1" ]; then echo $1; fi
echo "Usage: twilio-sms [-v] [-c configfile] [-d callerid] [-u accountsid] [-p authtoken] number [number[number[...]]]"
exit 1
}
VERBOSE=0
while getopts ":c:u:p:d:v" opt; do
case "$opt" in
c) CONFIGFILE=$OPTARG ;;
d) CALLERID_ARG=$OPTARG ;;
u) ACCOUNTSID_ARG=$OPTARG ;;
p) AUTHTOKEN_ARG=$OPTARG ;;
v) VERBOSE=1 ;;
*) echo "Unknown param: $opt"; usage ;;
esac
done
# test configfile
if [ -n "$CONFIGFILE" -a ! -f "$CONFIGFILE" ]; then echo "Configfile not found: $CONFIGFILE"; usage; fi
# source configfile if given
if [ -n "$CONFIGFILE" ]; then . "$CONFIGFILE";
# source the default ~/.twiliorc if it exists
elif [ -f ~/.twiliorc ]; then . ~/.twiliorc;
fi
# if ACCOUNTSID, AUTHTOKEN, or CALLERID were given in the commandline, then override that in the configfile
if [ -n "$ACCOUNTSID_ARG" ]; then ACCOUNTSID=$ACCOUNTSID_ARG; fi
if [ -n "$AUTHTOKEN_ARG" ]; then AUTHTOKEN=$AUTHTOKEN_ARG; fi
if [ -n "$CALLERID_ARG" ]; then CALLERID=$CALLERID_ARG; fi
# verify params
if [ -z "$ACCOUNTSID" ]; then usage "AccountSid not set, it must be provided in the config file, or on the command line."; fi;
if [ -z "$AUTHTOKEN" ]; then usage "AuthToken not set, it must be provided in the config file, or on the command line."; fi;
if [ -z "$CALLERID" ]; then usage "CallerID not set, it must be provided in the config file, or on the command line."; fi;
# Get message from stdin, taking only first 160 chars
MSG=`cat`
MSG=${MSG:0:160}
# Verify MSG
if [ -z "$MSG" ]; then usage "No content for the SMS was read from STDIN."; fi;
# for each remaining shell arg, that's a phone number to call
for PHONE in "${@:$OPTIND}"; do
echo -n "Sending SMS to $PHONE from $CALLERID..."
# initiate a curl request to the Twilio REST API, to begin a phone call to that number
RESPONSE=`curl -fSs -u "$ACCOUNTSID:$AUTHTOKEN" -d "From=$CALLERID" -d "To=$PHONE" -d "Body=$MSG" "https://api.twilio.com/2010-04-01/Accounts/$ACCOUNTSID/SMS/Messages" 2>&1`
if [ $? -gt 0 ]; then echo "Failed to send SMS to $PHONE: $RESPONSE"
else echo "done"
fi
if [ "$VERBOSE" -eq 1 ]; then echo $RESPONSE; fi
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment