File: livejournal.py

package info (click to toggle)
gnome-blog 0.9.1-8
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,116 kB
  • ctags: 178
  • sloc: python: 1,341; sh: 632; makefile: 136; xml: 8
file content (72 lines) | stat: -rw-r--r-- 2,049 bytes parent folder | download | duplicates (9)
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
import xmlrpclib
import time

from gtk import TRUE, FALSE

import gettext
_ = gettext.gettext

from gnomeblog import hig_alert
from gnomeblog import gnome_blog_globals
from gnomeblog import proxy

appkey = "6BF507937414229AEB450AB075001667C8BC8338"
ver = 'GNOME-gnome-blog/' + gnome_blog_globals.version

class Blog:
    def __init__(self):
        pass

    def postEntry (self, username, password, url, title, entry, client, gconf_prefix):

        #check for GNOME proxy configurations and use if required
        proxy_transport = proxy.GnomeProxyTransport(client)
        server = proxy_transport.get_server(url);

        info = {
          'username': username,
          'password': password,
          'clientversion': ver
        }

        try:
          cookie = server.LJ.XMLRPC.login(info)
        except xmlrpclib.Fault, e:
            hig_alert.reportError(_("Could not post Blog entry"), _("Your username or password is invalid. Please double-check the preferences."))
            return FALSE

        success = TRUE

        curtime = time.localtime()
        info = {
          'username': username,
          'password': password,
          'subject': title,
          'event': entry,
          'lineendings': 'unix',
          'year': curtime[0],
          'mon': curtime[1],
          'day': curtime[2],
          'hour': curtime[3],
          'min': curtime[4],
          'props': {
            'opt_preformatted': 1,
          }
        }

        try:
          server.LJ.XMLRPC.postevent(info)

        except xmlrpclib.Fault, e:
          hig_alert.handleBloggerAPIFault(e, _("Could not post blog entry"), username, username, url)
          success = FALSE
        except xmlrpclib.ProtocolError, e:
          hig_alert.reportError(_("Could not post Blog entry"), _('URL \'%s\' does not seem to be a valid LiveJournal XML-RPC server. Web server reported: %s.') % (url, hig_alert.italic(e.errmsg)))
          success = FALSE

        print ("Success is....")
        print (success)

        return success

blog = Blog()