-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.py
66 lines (56 loc) · 1.97 KB
/
api.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
try:
import simplejson
except:
import json as simplejson
from subprocess import *
import os
PHP = 'php' # the php command line program
CLI_PHP = os.path.join(os.path.dirname(__file__), 'cli.php')
def oi_services():
"""
# returns the dict:
{
'email': service_dict,
'social': service_dict
}
# where service_dict holds more entries of the form:
u'twitter': {
u'base_version': u'1.6.7',
u'check_url': u'http://twitter.com',
u'description': u'Get the contacts from a Twitter account',
u'name': u'Twitter',
u'type': u'social',
u'version': u'1.0.6'
}
"""
try:
output = Popen([PHP, CLI_PHP, '--', '--services'], stdout=PIPE).communicate()[0]
return simplejson.loads(output)
except Exception, e:
print e
def oi_get_contacts(email, password, provider):
"""
# returns a dict of the form:
{u'contacts': {u'[email protected]': u'afirstname alastname',
u'[email protected]': u'bfirstname blastname'},
u'errors': [],
u'oi_session_id': u'1238456503.6221'}
# if there are any errors, there will be a dict (see cli.php for the keys) in the place of that empty list
"""
try:
output = Popen([PHP, CLI_PHP, '--', '--contacts', email, password, provider], stdout=PIPE).communicate()[0]
return simplejson.loads(output)
except Exception, e:
print e
def oi_send_message(subject, body, provider, contacts, email, password):
"""
contacts - needs to be a list
# returns:
{'result': res, 'errors': []}
# if the result is False, there was an error; if it's -1 the plugin can't handle sending messages
"""
try:
output = Popen([PHP, CLI_PHP, '--', '--send-message', subject, body, provider, simplejson.dumps(contacts), email, password], stdout=PIPE).communicate()[0]
return simplejson.loads(output)
except Exception, e:
print e