Блогът на Фил

Nothing to see here, move along
  • rss
  • Home
  • About
  • profiles

python livejournal

felipe

Днес реших да потърся начин да публикувам в блога си програмно чрез Python. След тестване на различни кодове успях да модифицирам този – http://hewgill.com/ljdump/ и се получи следното приложенийце, с което публикувах предишния запис:

#!/usr/bin/python

#
# ljdump.py – livejournal archiver
# Greg Hewgill <greg@hewgill.com> http://hewgill.com
# Version 1.2
#
# $Id: ljdump.py 17 2006-09-08 08:46:56Z greg $
#
# This program reads the journal entries from a livejournal (or compatible)
# blog site and archives them in a subdirectory named after the journal name.
#
# The configuration is read from “ljdump.config”. A sample configuration is
# provided in “ljdump.config.sample”, which should be copied and then edited.
# The configuration settings are:
#
#   server – The XMLRPC server URL. This should only need to be changed
#            if you are dumping a journal that is livejournal-compatible
#            but is not livejournal itself.
#
#   username – The livejournal user name. A subdirectory will be created
#              with this same name to store the journal entries.
#
#   password – The account password. This password is never sent in the
#              clear; the livejournal “challenge” password mechanism is used.
#
# This program may be run as often as needed to bring the backup copy up
# to date. Both new and updated items are downloaded.
#
# LICENSE
#
# This software is provided 'as-is', without any express or implied
# warranty.  In no event will the author be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
#    claim that you wrote the original software. If you use this software
#    in a product, an acknowledgment in the product documentation would be
#    appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
#    misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
#
# Copyright (c) 2005-2006 Greg Hewgill

import codecs, md5, os, pickle, pprint, re, sys, urllib2, xml.dom.minidom, xmlrpclib
from xml.sax import saxutils

def calcchallenge(challenge, password):
    return md5.new(challenge+md5.new(password).hexdigest()).hexdigest()

def flatresponse(response):
    r = {}
    while True:
        name = response.readline()
        if len(name) == 0:
            break
        if name[-1] == '\n':
            name = name[:len(name)-1]
        value = response.readline()
        if value[-1] == '\n':
            value = value[:len(value)-1]
        r[name] = value
    return r

def getljsession(username, password):
    r = urllib2.urlopen(Server+”/interface/flat”, “mode=getchallenge”)
    response = flatresponse(r)
    r.close()
    r = urllib2.urlopen(Server+”/interface/flat”, “mode=sessiongenerate&user=%s&auth_method=challenge&auth_challenge=%s&auth_response=%s” % (username, response['challenge'], calcchallenge(response['challenge'], password)))
    response = flatresponse(r)
    r.close()
    return response['ljsession']

def dochallenge(params, password):
    challenge = server.LJ.XMLRPC.getchallenge()
    params.update({
        'auth_method': “challenge”,
        'auth_challenge': challenge['challenge'],
        'auth_response': calcchallenge(challenge['challenge'], password)
    })
    return params

config = xml.dom.minidom.parse(“ljdump.config”)
Server = config.documentElement.getElementsByTagName(“server”)[0].childNodes[0].data
Username = config.documentElement.getElementsByTagName(“username”)[0].childNodes[0].data
Password = config.documentElement.getElementsByTagName(“password”)[0].childNodes[0].data

m = re.search(“(.*)/interface/xmlrpc”, Server)
if m:
    Server = m.group(1)

print “Fetching journal entries for: %s” % Username
try:
    os.mkdir(Username)
    print “Created subdirectory: %s” % Username
except:
    pass

ljsession = getljsession(Username, Password)

server = xmlrpclib.ServerProxy(Server+”/interface/xmlrpc”)

newentries = 0
newcomments = 0
errors = 0

lastsync = “”
lastmaxid = 0
try:
    f = open(“%s/.last” % Username, “r”)
    lastsync = f.readline()
    if lastsync[-1] == '\n':
        lastsync = lastsync[:len(lastsync)-1]
    lastmaxid = f.readline()
    if len(lastmaxid) > 0 and lastmaxid[-1] == '\n':
        lastmaxid = lastmaxid[:len(lastmaxid)-1]
    if lastmaxid == “”:
        lastmaxid = 0
    else:
        lastmaxid = int(lastmaxid)
    f.close()
except:
    pass
origlastsync = lastsync

r = server.LJ.XMLRPC.login(dochallenge({
    'username': Username,
    'ver': 1,
    'getpickws': 1,
    'getpickwurls': 1,
}, Password))
userpics = dict(zip(r['pickws'], r['pickwurls']))
userpics['*'] = r['defaultpicurl']

r = server.LJ.XMLRPC.syncitems(dochallenge({
        'username': Username,
        'ver': 1,
        'lastsync': lastsync,
    }, Password))
    #pprint.pprint(r)
e = server.LJ.XMLRPC.postevent(dochallenge({
                    'username': Username,
                    'ver': 1,
                    'selecttype': “one”,
                    'event': 'please work',
                    'subject':'test',
                    'year':'2008',
                    'mon':'8',
                    'day':'26',
                    'hour':'12',
                    'min':'8' 
                }, Password))

Share
Categories
Uncategorized
Comments rss
Comments rss
Trackback
Trackback

« test ’110497′ »

Leave a Reply

Click here to cancel reply.

Opportunity's Selfie

 
NASA's Mars Rover Opportunity catches its own late-afternoon shadow in this dramatically lit view eastward across Endeavour Crater on Mars. The rover used the panoramic camera (Pancam) between about 4:30 and 5:00 p.m. local Mars time to record images taken through different filters and combined into this mosaic view. Most of the component images were recorded during the 2,888th Martian day, or sol, of Opportunity's work on Mars (March 9, 2012). At that time, Opportunity was spending low-solar-energy weeks of the Martian winter at the Greeley Haven outcrop on the Cape York segment of Endeavour's western rim. In order to give the mosaic a rectangular aspect, some small parts of the edges of the mosaic and sky were filled in with parts of an image acquired earlier as part of a 360-degree panorama from the same location. Opportunity has been studying the western rim of Endeavour Crater since arriving there in August 2011. This crater spans 14 miles (22 kilometers) in diameter, or about the same area as the city of Seattle. This is more than 20 times wider than Victoria Crater, the largest impact crater that Opportunity had previously examined. The interior basin of Endeavour is in the upper half of this view. The mosaic combines about a dozen images taken through Pancam filters centered on wavelengths of 753 nanometers (near infrared), 535 nanometers (green) and 432 nanometers (violet). The view is presented in false color to make some differences between materials easier to see, such as the dark sandy ripples and dunes on the crater's distant floor. Image credit: NASA/JPL-Caltech/Cornell/Arizona State Univ.
Read More

Случаен цитат

“Seek and ye shall find”, they say, but they don’t say what you’ll find. — Чешърския котарак

I am reading now

Cryptonomicon
635 / Pages
Cryptonomicon

 

August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

чурулик

  • Писна ми от тия земетресения. Това последното го усетих (4.3) http://t.co/dWPgP0om
  • Абе каква е тая буря, снощи земетресение, сега потоп със светкавици... Подготовката за извънземното нашествие протича нормално :-)
  • more shaking

Blogroll

  • Блогът на Дино
  • Блогът на Камен
  • Блогът на Краси
  • Търсене в интернет

User-submitted Links

No recommended links yet. Add one?

  • Newest
  • Hot
  • Current
  • Top ranked

Spam

7,812
SPAM BLOCKED
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox