def wordpress_public(domain="如:www.domain.com ", username="******", password='******', title='文章标题', content="文章内容", tags='标签,多个标签用逗号隔开如’标签1,标签2', category='分类名称'): import urllib, urllib2, cookielib, requests headers = { "Host": "%s" % domain, "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0", } cookieJar = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar)) urllib2.install_opener(opener) login_data = { "log": "%s" % username, "pwd": "%s" % password, } login_data = urllib.urlencode(login_data) login_url = 'http://%s/wp-login.php' % domain req = urllib2.Request(url=login_url, data=login_data, headers=headers) html = urllib2.urlopen(req).read() url = 'http://%s/wp-admin/edit.php?s=%s' % (domain, title) html = opener.open(url).read() if 'post-title page-title column-title' in html: print '标题已经已经存在,跳过不发布'.decode('utf8') else: tag = [] categorys = [] tag.append(tags) categorys.append(category) wp = Client('http://%s/xmlrpc.php' % domain, '%s' % username, '%s' % password) #登陆后台 wp.call(GetPosts()) wp.call(GetUserInfo()) post = WordPressPost() post.title = """%s""" % title #文章标题 post.content = """%s""" % content #文章内容 post.terms_names = { 'post_tag': tag, #标签 如果有多个标签的话需要以列表形式,如: 'post_tag': ['eo ', 'discuz'], 'category': categorys, #分类 如果是有多个分类的话需要以列表形式,如:'category': ['Introductions', 'Tests'] } post.post_status = 'publish' wp.call(NewPost(post)) print '发布成功,标题是:'.decode('utf8'), title.decode('utf8')
def testConnection(): client = initClient() print client.call(GetUserInfo())
def signin(request): """ signin page. It manages the legacy authentification (user/password) and openid authentification url: /signin/ template : authopenid/signin.htm """ logging.debug('in signin view') on_failure = signin_failure email_feeds_form = askbot_forms.SimpleEmailSubscribeForm() #we need a special priority on where to redirect on successful login #here: #1) url parameter "next" - if explicitly set #2) url from django setting LOGIN_REDIRECT_URL #3) home page of the forum login_redirect_url = getattr(settings, 'LOGIN_REDIRECT_URL', None) next_url = get_next_url(request, default=login_redirect_url) logging.debug('next url is %s' % next_url) if askbot_settings.ALLOW_ADD_REMOVE_LOGIN_METHODS == False \ and request.user.is_authenticated(): return HttpResponseRedirect(next_url) if next_url == reverse('user_signin'): next_url = '%(next)s?next=%(next)s' % {'next': next_url} login_form = forms.LoginForm(initial={'next': next_url}) #todo: get next url make it sticky if next is 'user_signin' if request.method == 'POST': login_form = forms.LoginForm(request.POST) if login_form.is_valid(): provider_name = login_form.cleaned_data['login_provider_name'] if login_form.cleaned_data['login_type'] == 'password': password_action = login_form.cleaned_data['password_action'] if askbot_settings.USE_LDAP_FOR_PASSWORD_LOGIN: assert (password_action == 'login') username = login_form.cleaned_data['username'] password = login_form.cleaned_data['password'] # will be None if authentication fails user = authenticate(username=username, password=password, method='ldap') if user is not None: login(request, user) return HttpResponseRedirect(next_url) else: return finalize_generic_signin( request=request, user=user, user_identifier=username, login_provider_name=provider_name, redirect_url=next_url) else: if password_action == 'login': user = authenticate( username=login_form.cleaned_data['username'], password=login_form.cleaned_data['password'], provider_name=provider_name, method='password') if user is None: login_form.set_password_login_error() else: login(request, user) #todo: here we might need to set cookies #for external login sites return HttpResponseRedirect(next_url) elif password_action == 'change_password': if request.user.is_authenticated(): new_password = \ login_form.cleaned_data['new_password'] AuthBackend.set_password( user=request.user, password=new_password, provider_name=provider_name) request.user.message_set.create( message=_('Your new password saved')) return HttpResponseRedirect(next_url) else: logging.critical('unknown password action %s' % password_action) raise Http404 elif login_form.cleaned_data['login_type'] == 'openid': #initiate communication process logging.debug('processing signin with openid submission') #todo: make a simple-use wrapper for openid protocol sreg_req = sreg.SRegRequest(optional=['nickname', 'email']) redirect_to = "%s%s?%s" % ( get_url_host(request), reverse('user_complete_signin'), urllib.urlencode({'next': next_url})) return ask_openid(request, login_form.cleaned_data['openid_url'], redirect_to, on_failure=signin_failure, sreg_request=sreg_req) elif login_form.cleaned_data['login_type'] == 'oauth': try: #this url may need to have "next" piggibacked onto callback_url = reverse('user_complete_oauth_signin') connection = util.OAuthConnection( provider_name, callback_url=callback_url) connection.start() request.session['oauth_token'] = connection.get_token() request.session['oauth_provider_name'] = provider_name request.session[ 'next_url'] = next_url #special case for oauth oauth_url = connection.get_auth_url(login_only=False) return HttpResponseRedirect(oauth_url) except util.OAuthError, e: logging.critical(unicode(e)) msg = _('Unfortunately, there was some problem when ' 'connecting to %(provider)s, please try again ' 'or use another provider') % { 'provider': provider_name } request.user.message_set.create(message=msg) elif login_form.cleaned_data['login_type'] == 'facebook': #have to redirect for consistency #there is a requirement that 'complete_signin' try: #this call may raise FacebookError user_id = util.get_facebook_user_id(request) user = authenticate(method='facebook', facebook_user_id=user_id) return finalize_generic_signin( request=request, user=user, user_identifier=user_id, login_provider_name=provider_name, redirect_url=next_url) except util.FacebookError, e: logging.critical(unicode(e)) msg = _('Unfortunately, there was some problem when ' 'connecting to %(provider)s, please try again ' 'or use another provider') % { 'provider': 'Facebook' } request.user.message_set.create(message=msg) elif login_form.cleaned_data['login_type'] == 'wordpress_site': #here wordpress_site means for a self hosted wordpress blog not a wordpress.com blog wp = Client(askbot_settings.WORDPRESS_SITE_URL, login_form.cleaned_data['username'], login_form.cleaned_data['password']) try: wp_user = wp.call(GetUserInfo()) custom_wp_openid_url = '%s?user_id=%s' % (wp.url, wp_user.user_id) user = authenticate(method='wordpress_site', wordpress_url=wp.url, wp_user_id=wp_user.user_id) return finalize_generic_signin( request=request, user=user, user_identifier=custom_wp_openid_url, login_provider_name=provider_name, redirect_url=next_url) except WpFault, e: logging.critical(unicode(e)) msg = _('The login password combination was not correct') request.user.message_set.create(message=msg)
from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo wp = Client('http://dciff-indie.org/xmlrpc.php', '*****@*****.**', 'dcif@ir2012') wp.call(GetPosts()) wp.call(GetUserInfo()) post = WordPressPost() post.title = 'My new title' post.content = 'This is the body of my new post.' post.terms_names = { 'post_tag': ['test', 'firstpost'], 'category': ['Introductions', 'Tests'] } wp.call(NewPost(post))
elif eleccion == 5: crear_nueva_entrada_automatica() else: exit() #%% # ============================================================================= # DATOS PARA VIAJEROAZUL # ============================================================================= os.chdir('YOUR/PATH') cliente = pagina_wordpres() #Obtener la información del usuario para lanzar una excepción si la autenticación falla cliente.call(GetUserInfo()) imprimir_menu_opciones() #%% from gensim.models import LdaModel from gensim.corpora.dictionary import Dictionary def get_topics(model, model_type = 'lda'): if model_type == 'lda': b = model.print_topics(num_topics=-1,num_words = 20) b = [i[1] for i in b] b = [i.split("+") for i in b] for pos,value in enumerate(b): b[pos] = [re.findall(r'"([^"]*)"', i)[0] for i in b[pos]] b =pd.DataFrame(b)
parser.add_argument('-t', '--title', type=str, default='My new title', help="Post Title") parser.add_argument('-c', '--content', type=str, default='This is the body of my new post.', help='Post Content') args = parser.parse_args() wp = Client('http://wordpress.tst/xmlrpc.php', 'admin', '123') print('Get Posts:') print(wp.call(GetPosts())) print('Current User:'******'utf-8') post.content = args.content.encode(encoding='utf-8') post.terms_names = { 'post_tag': ['test', 'firstpost'], 'category': ['Introductions', 'Tests'] } post.post_status = 'publish' wp.call(NewPost(post)) print('Publish Done.') if __name__ == "__main__": pass
def auth(username, password): global wp wp = Client(wp_url, username, password, transport=SpecialTransport()) wp.call(GetUserInfo())