-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.py
39 lines (30 loc) · 1.07 KB
/
cron.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# * coding: utf-8 *
import json, urllib2
from urllib import urlencode
from datetime import datetime
from django.core.management import setup_environ
import settings
setup_environ(settings)
from identica.models import Mensaje
#http://diekershoff.homeunix.net/tobias/2011-04-26/using-python-to-update-your-statusnet-account
user = "usuario"
pwd = "XXXXX"
apibase = "https://identi.ca/api"
# connection magic
pwd_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
pwd_mgr.add_password(None, apibase, user, pwd)
handler = urllib2.HTTPBasicAuthHandler(pwd_mgr)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
print("Procesando mensajes pendientes:")
for m in Mensaje.objects.filter(fecha__lte=datetime.now(), enviado=False):
print "Enviando mensaje: ["+str(m)+"]"
# now define a message
msg = str(m)
# url encode it nicely and set your own client name – no links in source!
themsg = urlencode({'status':msg,'source':'mensajero'})
# and send the notice
urllib2.urlopen(apibase+'/statuses/update.json?s',themsg)
m.enviado=True
m.save()