⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lj_client.py

📁 pyLJclient是一个跨平台的livejournal客户端
💻 PY
字号:
#!/usr/bin/python# pyLJclient - a python based live journal client with a wxPython gui# Copyright (C) 2002 Sameer Chowdhury# refer to "about this software.txt" for info on licensingfrom wxPython.wx import *from lj import lj_journal, identity, offline_journal, config, moodsfrom lj.post_panel import PostPanelfrom lj.login_screen import getLoginfrom lj.error_windows import fatal_error, nonfatal_errorfrom lj.lj_exceptions import *import sys# main frame optionsID_POST = 100ID_LOGIN = 101ID_EXIT  = 103ID_LOGOUT = 104ID_MERGE = 105ID_ABOUT = 106ID_PREF = 107ID_REFRESH = 108ID_VIEWHISTORY = 109# the main frameclass MainFrame(wxFrame):    def __init__(self, parent, ID, title):        wxFrame.__init__(self, parent, ID, title, size = (600, 400),                    style=wxDEFAULT_FRAME_STYLE)        self.CreateStatusBar()        self.SetStatusText("Welcome to the Python live journal client")        menu = wxMenu()	menu.Append(ID_MERGE, "&Merge","Merge Offline Journal")        menu.Append(ID_LOGOUT, "&Logout","Logout")	# menu.Append(ID_VIEWHISTORY, "&View History","View History")        menu.AppendSeparator()        menu.Append(ID_EXIT, "E&xit", "Terminate the program")	help_menu = wxMenu()	help_menu.Append(ID_ABOUT, "&About", "About pyljclient")	edit_menu = wxMenu()	edit_menu.Append(ID_PREF, "&Preferences", "Preferences")        menuBar = wxMenuBar()        menuBar.Append(menu, "&File")	menuBar.Append(edit_menu, "&Edit")	menuBar.Append(help_menu, "&Help")        self.SetMenuBar(menuBar)        EVT_MENU(self, ID_POST, self.OnPost)        EVT_MENU(self, ID_EXIT,  self.TimeToQuit)        EVT_MENU(self, ID_LOGOUT, self.Logout)	EVT_MENU(self, ID_MERGE, self.Merge)	EVT_MENU(self, ID_ABOUT, self.About)	#EVT_MENU(self, ID_VIEWHISTORY, self.ViewHistory)	# self.main_sizer = wxBoxSizer(wxVERTICAL)	# self.SetAutoLayout(1)	# self.SetSizer(self.main_sizer)	# self.main_sizer.Fit(self)	# self.main_sizer.SetSizeHints(self)	#image = wxImage('bitmaps/robin.jpg', wxBITMAP_TYPE_JPEG).ConvertToBitmap()        self.panel = None	self.nb = None	(self.username, self.password, self.hpassword, 	    self.online_journal, self.offline_journal)='','','','',''	self.pic_url_association={}        self.present_login()    def ViewHistory(self, event):	if self.panel:	    self.panel.Destroy()	self.panel = history_list.runHistory(self)	self.Fit()	self.Refresh()    def go_online(self):	while(1):	    success = self.login()	    if success:		return 1    def About(self, event):	win = wxDialog(self, -1, "About", wxDefaultPosition, wxSize(350, 200))	msg = config.getClientName()+'\nVersion: '+config.getClientVersion()	l1 = wxStaticText(win, -1, msg, pos=(10,50))	wxButton(win, wxID_OK,     " OK ", wxPoint(75, 120), wxDefaultSize).SetDefault()	win.ShowModal()    def Merge(self, event):	# check to see if offline journal exists and has entries	# then check if online journal exists	# if online journal doesn't exist, try to logon with supplied username and password	# if logon fine, then iterate through each offline journal entry and post it	if self.offline_journal:	    if not self.online_journal:		print "self.online_journal doesn't exist"		if not self.go_online():		# logging on unsuccessful, operation cannont continue		    return -1	    # print "val self.online_journal--->", len(self.online_journal)	    if self.online_journal:		while self.offline_journal.has_events():		    event = self.offline_journal.pop_event()		    self.online_journal.post_event(event)    def present_login(self):        while (1):            retrieve_id_success = self.retrieve_id()	    print "ID retrieved = %s"%str(retrieve_id_success)            if retrieve_id_success:		# print "entering self.login()..."		login_success = self.login()		# print "Login success =%s"%str(login_success)		if login_success:		    break        self.showPostPanel()    def clear_user(self):	self.username, self.password, self.hpassword, self.online_journal, self.offline_journal='','','','',''    def Logout(self, event):        self.panel.Destroy()        self.panel = None        identity.clear_identity()	self.clear_user()	print "identity cleared, read_identity value=%s..."%str(identity.read_identity())        self.present_login()    # dumb id writer, returns username and hpassword    def write_id(self):	if self.remember_id and self.password and self.username:	    identity.write_identity(self.username, self.password)	    return identity.read_identity()	elif self.username and self.password:	    import md5	    hpassword = md5.new(self.password).hexdigest()	    return (self.username, hpassword)    # retrieves the id WITHOUT checking if username and password are valid on lj    # dumb id retriever    def retrieve_id(self):        self.remember_id = 0        # get login info from local file 	user_identity = identity.read_identity()        if user_identity:            (self.username, self.hpassword) = user_identity[0], user_identity[1]	    self.remember_id = 1	    print "identity found in file..."	    return 1	# if no local file, get login info from user        else:            login_info = getLogin(self)	    # if user gave the information that he wants to login and 	    # info appears ok, set username, password, and rememberid values and return 1	    if login_info['success']:	    	(self.username, self.password, self.remember_id) = (login_info['username'], 		    login_info['password'], login_info['remember_id'])		return 1	    # looks like the user didn't fill out login info correctly	    # take action appropriately	    else:		# if the user hit cancel at the login prompt exit the program 		if login_info['action'] == 'cancel':		    self.Close(true)		    sys.exit(0)		# if the user didn't fill in all the parameters tell him he didn't		# exit abnormally 		elif login_info['action'] == 'missing parameters':		    nonfatal_error(self, "Must provide valid username and password")		    return 0		# i don't know what the problem is, just exit quietly		else:		    return 0    # try to login user with supplied username and either password or hpassword    # if successful, call write_id    def login(self):	print "now in login... checking user identity against server..."	self.journal_access_list = []        try:	    if self.hpassword:		print "hpassword found..."		self.online_journal = lj_journal.LJ_Journal(self.username, hpassword = self.hpassword)		print "user login success at server using hpassword..."	    elif self.password:		self.online_journal = lj_journal.LJ_Journal(self.username, self.password)		print "Login successful..."		self.username, self.hpassword = self.write_id()		self.online_journal.hpassword = self.hpassword	    else:		raise "Missing Password"	    # login successful, now set various properties so post_panel can display them	    self.offline_journal = offline_journal.OfflineJournal()	    self.journal_access_list = self.online_journal.getWriteJournals()	    if not self.journal_access_list:		self.journal_access_list = ['Default']	    self.moods = self.online_journal.moods	    self.pic_url_association = self.online_journal.get_pic_url_association()	    self.moods.list.sort(lambda x,y: cmp(x.name, y.name))	# what to do if offline	except NetworkError, e:	    nonfatal_error(self, str(e)+"\nNow working in offline mode")	    self.online_journal = ''	    self.journal_access_list = ['Default']	    self.offline_journal = offline_journal.OfflineJournal()	    self.moods = moods.Moods()	    return 1 	except UnknownUser, e:	    nonfatal_error(self, str(e))	    return 0	    a = """	except:	    errorType, errorValue, errorTB =  sys.exc_info()	    print "-------------   start   -------------------"	    print "errorType: ", errorType	    print "errorValue: ", errorValue	    import traceback	    traceback.print_exc(file=sys.stdout)   	    print "------------     end    -------------------"            return 0	""" 	else:            return 1	    def TimeToQuit(self, event):        self.Close(true)    def OnPost(self, event):        self.showPostPanel()    def showPostPanel(self):        if self.panel:            self.panel.Destroy()            self.panel = None	if self.online_journal:	    panel = PostPanel(self, -1, self.online_journal, self.journal_access_list, self.moods, 		self.pic_url_association)	elif self.offline_journal:	    panel = PostPanel(self, -1, self.offline_journal, self.journal_access_list, self.moods,		self.pic_url_association)	else:	    raise "A suitable journal was not found"	# self.nb = LJNB(self, -1, [panel])	self.panel = panel	# print self.panel.GetSize()	self.SetSize(panel.GetSize())	self.Fit()	self.Refresh()	# self.panel =self.nb       class MyApp(wxApp):    def OnInit(self):        frame = MainFrame(NULL, -1, "Livejournal Client")        frame.Show(true)        self.SetTopWindow(frame)        return trueapp = MyApp(0)app.MainLoop()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -