public
Description: maemo fork of zapys lj client
Homepage:
Clone URL: git://github.com/egv/zapys-maemo.git
zapys-maemo / lj.py
100644 89 lines (74 sloc) 2.079 kb
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# -*- coding: UTF8 -*-
 
 
import xmlrpclib, time, md5
 
LJ_TIME_FORMAT = r"%Y-%m-%d %H:%M:%S"
 
class rpcServer:
username = ''
password = ''
initialized = False
 
last_event = {}
 
def __init__(self, user, password):
self.username = user
self.hpassword = md5.md5(password).hexdigest()
 
def connect(self):
if not self.initialized:
self.server = xmlrpclib.Server("http://www.livejournal.com/interface/xmlrpc:80")
self.initialized = True
 
def get_last(self):
 
self.connect()
result = self.server.LJ.XMLRPC.getevents({
'username': self.username,
'hpassword': self.hpassword,
'ver': '1',
'lineendings': '0x0A',
"selecttype": "lastn",
"itemid": -1,
"howmany": 1
})
 
return result['events'][0]
 
def del_event(self, itemid):
return self.server.LJ.XMLRPC.editevent({
'username': self.username,
'hpassword': self.hpassword,
'ver': '1',
"itemid": itemid,
})
 
# post is disct {subj, taglist, text}
def post(self, post, eventtime = None):
self.connect()
if eventtime == None:
moment = time.localtime()
else:
moment = time.strptime(eventtime, LJ_TIME_FORMAT)
 
return self.server.LJ.XMLRPC.postevent({
'username': self.username,
'hpassword': self.hpassword,
'clientversion': 'Zapys/0.8',
'ver':'1',
'event': post['text'],
'subject': post['subj'],
'props': {'taglist': post['tags'], 'opt_preformatted': True},
'year': moment[0],
'mon': moment[1],
'day': moment[2],
'hour' : moment[3],
'min': moment[4],
'lineendings':'0x0A'
})
 
# post is disct {subj, tags, text}
def edit(self, itemid, eventtime, post ):
moment = time.strptime(eventtime, LJ_TIME_FORMAT)
return self.server.LJ.XMLRPC.editevent({
'username': self.username,
'hpassword': self.hpassword,
'ver': '1',
"itemid": itemid,
'event': post['text'],
'subject': post['subj'],
'props': {'taglist': post['tags'], 'opt_preformatted': True},
'year': moment[0],
'mon': moment[1],
'day': moment[2],
'hour' : moment[3],
'min': moment[4],
})