def main(self, url, login, password, path): try: self.client = wordpress_xmlrpc.Client(url, login, password) except wordpress_xmlrpc.exceptions.ServerConnectionError as exc: if '301 Moved Permanently' in exc.args[0]: print("301 redirect, trying HTTPS protocol.") ssl_url = url.replace('http://', 'https://') self.client = wordpress_xmlrpc.Client(ssl_url, login, password) # This is just to make sure that the credentials are OK before we jump # to XML parsing. self.client.call(wordpress_xmlrpc.methods.users.GetUsers()) # Parse the XML. Give 2 seconds for parsing to prevent abuse. signal.alarm(PARSE_TIMEOUT) if path.endswith('.gz'): target = gzip.open(path) else: target = path self.tree = parse(target) signal.alarm(0) entries = self.tree.findall('.//entry') for n, entry in enumerate(entries, 1): print("%d/%d" % (n, len(entries))) self.handle_post(entry) print("Done. You can now change wordpress password.")
def create_post(self, title, content): conn = wp_rpc.Client(self.url, self.user, self.password) self.post.title = title self.post.content = content self.post.post_status = 'publish' self.post.id = conn.call(wp_methods.posts.NewPost(self.post)) return self.post.id
def __init__(self, url, username, password): self._url = self.__url_normalize(url) self._rpc = self.__parse_url(self._url) self._username = username self._password = password self._client = wordpress_xmlrpc.Client(self._rpc, self._username, self._password)
def __init__(self, blog_url, username, password, debug=False): if blog_url.endswith('/'): rpc_url = '{}xmlrpc.php'.format(blog_url) else: rpc_url = '{}/xmlrpc.php'.format(blog_url) self._client = wordpress_xmlrpc.Client(rpc_url, username, password) self._debug = debug
def getDefaultClient(self): try: if self.config.has_key('public_key') and self.config.has_key( 'private_key'): return wp.Client(url=self.url + '/xmlrpc.php', public_key=self.config['public_key'], private_key=self.config['private_key']) else: return UPClient(url=self.url + '/xmlrpc.php', username=self.username, password=self.password) except Exception, e: print('Could not create client. {}'.format(e)) exit(2)
def _login(self): config_dict = config.get_blog_config() address = (self.address or config_dict["url"]) + self.API # authentication errors are never raised from here; socket related errors # can be raised on connection troubles; ServerConnectionError can be # raised by wordpress_xmlrpc on xmlrpc client ProtocolError but actually, on invalid # XML-RPC protocol, the OSError is raised by xmlrpc instead of the above try: self._iface = wordpress_xmlrpc.Client(address, config_dict["user_name"], config_dict["password"]) except OSError as exc: raise exceptions.BlogInternetError(exc) from exc except Exception as exc: raise exceptions.BlogMethodError(exc) from exc
def main(): global wp_client global dry_run op = OptionParser() op.add_option('', '--dryrun', action="store_true", help="perform a dry-run") op.add_option('', '--directory', metavar="DIRECTORY", help="directory to parse") op.add_option('', '--url', metavar="URL", help="the URL to connect to") op.add_option('', '--username', metavar="USERNAME", help="username to connect to URL with") op.add_option('', '--password', metavar="PASSWORD", help="password to connect to URL with") opts, args = op.parse_args() if not opts.directory: print "you must specify a directory?" op.print_usage() sys.exit(1) elif not opts.url: print "you must specify a url?" op.print_usage() sys.exit(1) elif not opts.username: print "you must specify a username?" op.print_usage() sys.exit(1) elif not opts.password: print "you must specify a password?" op.print_usage() sys.exit(1) logging.basicConfig(level = logging.DEBUG, format = "%(asctime)s: [%(levelname)s] - %(message)s") if opts.dryrun: logging.info("performing dry run!") dry_run = True url = "%s%s" % (opts.url, 'xmlrpc.php') postpath = os.path.join(opts.directory, 'posts') pagepath = os.path.join(opts.directory, 'pages') wp_client = wordpress_xmlrpc.Client(url, opts.username, opts.password) logging.info("sending posts from %s to %s" % (postpath, url)) update(UploadType.POST, postpath) logging.info("sending pages from %s to %s" % (pagepath, url)) update(UploadType.PAGE, pagepath)
async def make_client() -> xmlrpc.Client: from app.config.wordpress import wp_password, wp_username, wp_xmlrpc_url [username, password, xmlrpc_url] = await asyncio.gather(wp_username(), wp_password(), wp_xmlrpc_url()) if not username or not password or not xmlrpc_url: logging.critical( f"Incomplete or invalid WP XMLRPC information set (username = '******'; password = '******'; XMLRPC url = '{xmlrpc_url}'). Skipping uploading to WordPress." ) return None else: logging.debug( f"Creating WordPress client (username = '******'; password = '******'; XMLRPC url = '{xmlrpc_url}')..." ) return xmlrpc.Client(xmlrpc_url, username, password)
def post_draft(title, body): cfg_filename = path('~/.wphelper').expanduser() cfg = configparser.ConfigParser() if not cfg.read(cfg_filename): raise RuntimeError('Did not find configuration file {}'.format(cfg_filename)) site_url = cfg['site']['url'] xmlrpc_url = site_url + '/xmlrpc.php' username = cfg['site']['username'] password = cfg['site']['password'] wp = wordpress_xmlrpc.Client(xmlrpc_url, username, password) post = wordpress_xmlrpc.WordPressPost() post.title = title post.content = body post.post_status = 'draft' post.terms_names = { 'post_tag': ['PyMOTW', 'python'], } wp.call(wordpress_xmlrpc.methods.posts.NewPost(post))
def GetTitle(text): textList = text.split() try: try: wp = wordpress_xmlrpc.Client( 'http://www.' + textList[0] + '/xmlrpc.php', textList[1], textList[2]) # 获取前100个帖子 getPost = wordpress_xmlrpc.methods.posts.GetPosts({ 'orderby': 'post_modified', 'number': 100 }) post = wp.call(getPost) except socket.error: print '[-] 报告爷网站找不到主机 http://www.' + textList[0] print >> logFile, '[-] 报告爷网站找不到主机 http://www.' + textList[0] try: # 如果没有获取到数据 则不处理 if not post == []: # 如果有数据 for i in post: # 删除hello 文章 # if wp.call(wordpress_xmlrpc.methods.posts.DeletePost(1)): # 删除全部文章 if wp.call(wordpress_xmlrpc.methods.posts.DeletePost( i.id)): print '[+] 报告爷 删除成功!\t' + textList[0] else: print '[-] 报告爷 删除失败!\t' + textList[0] print >> logFile, '[-] 报告爷 删除失败!\t' else: print '[+] 报告爷 文章已被删除!\t' + textList[0] except UnboundLocalError: print '[-] POST 数据错误' + textList[0] print >> logFile, '[-] POST 数据错误' + textList[0] except xmlrpclib.Error: print '[-] xmlrpclib 数据错误 http://www.' + textList[0] print >> logFile, '[-] xmlrpclib 数据错误 http://www.' + textList[0] except wordpress_xmlrpc.InvalidCredentialsError: print '[-] 用户或密码错误 http://www.' + textList[0] print >> logFile, '[-] 用户或密码错误 http://www.' + textList[0]
def Post(self): """@Doc:发送帖子""" wp = wordpress_xmlrpc.Client(self.host, self.user, self.pwd) post = wordpress_xmlrpc.WordPressPost() post.title = self.title post.content = self.content post.post_status = 'publish' """ # 栏目ID # post.taxonomy = self.entity # post.terms_names = { # 'post_tag': [self.entity], # # 'category': ['多动症常识', '治疗多动症的医生'] # } """ id = wp.call(NewPost(post)) host = self.host.replace('xmlrpc.php', '') if not id: raise RuntimeError("POST Send failed") else: print '[+] 报告爷 帖子发送成功' + host + str(id) + '.html' print >> okFile, '[+] 报告爷 帖子发送成功' + host + str(id) + '.html'
def _login(self): address = (self.address or self.config_dict["address"]) + self.API # authentication errors are never raised from here; socket related errors # can be raised on connection troubles; ServerConnectionError can be # raised by wordpress_xmlrpc on xmlrpc client ProtocolError but actually, on invalid # XML-RPC protocol, the OSError is raised by xmlrpc instead of the above if not (internet_on()): raise exceptions.BlogInternetError() for key in ['user_name', 'address', 'password']: if not (self.config_dict[key]): raise exceptions.BlogEmptyConfError() try: self._iface = wordpress_xmlrpc.Client( address, self.config_dict["user_name"], self.config_dict["password"]) self._last_req_ts = time.time() except OSError as exc: raise exceptions.BlogConfigurationError(exc) from exc except Exception as exc: raise exceptions.BlogMethodError(exc) from exc
def create_wp_client(): try: conn = sqlite3.connect(db_path) cur = conn.cursor() cur.execute( "SELECT wp_uri, wp_username, wp_password FROM configuration") config = cur.fetchone() wp_uri = config[0] wp_username = config[1] wp_password = config[2] client = wp.Client(wp_uri, wp_username, wp_password) return client except sqlite3.Error, err: if conn: conn.rollback() print "Error when getting configuration: %s" % err.args[0] sys.exit(1)
if tw_enabled == "true": tw_consumer = ConfigSectionMap("twitter")['consumer'] tw_secret = ConfigSectionMap("twitter")['secret'] tw_token = ConfigSectionMap("twitter")['access_token'] tw_token_secret = ConfigSectionMap("twitter")['access_token_secret'] tw_hashtags = ConfigSectionMap("twitter")['hashtags'] tw_bitlyuser = ConfigSectionMap("twitter")['bitly_user'] tw_bitlykey = ConfigSectionMap("twitter")['bitly_key'] walkscore_enabled = ConfigSectionMap("walkscore")['enabled'] if walkscore_enabled == "true": walkscore_api_key = ConfigSectionMap("walkscore")['walkscore_api_key'] walkscore_id = ConfigSectionMap("walkscore")['walkscore_id'] # Get blog URL wp_site = wordpress_xmlrpc.Client(wp_url, wp_username, wp_password, transport=SpecialTransport()) siteurl = wp_site.call(options.GetOptions(['home_url']))[0].value # declare variables based on arguments past_date = date.today() - timedelta(int_date) the_day = past_date.strftime('%d') the_mon = past_date.strftime('%m') the_yr = past_date.strftime('%-Y') locale.setlocale(locale.LC_ALL, 'en_US.UTF8') # check if slash was added to rootdir if rootdir.endswith('/'): print "Slash detected in rootdir .." else: rootdir = rootdir + "/"
# plt.show() plt.savefig(str(stock[i]) + '.png', bbox_inches='tight', format='png', dpi=200) # Save as STOCK.PNG else: # Print Last Updated Price if Not Recent print('Closing Prices Last Updated: ' + str(f.index[len(f.index) - 1])) quit() # Quit if Prices Aren't Updated wpUser = str( input('Enter WordPress Username: '******'Enter WordPress Password: '******'https://bspt82221685.wordpress.com/xmlrpc.php' # WordPress URL (XMLRPC) wp = wordpress_xmlrpc.Client(wpURL, wpUser, wpPW) # Login to WordPress wpPost = wordpress_xmlrpc.WordPressPost() # Create New Post wpMM = str(datetime.now().strftime('%m')) # MM wpDD = str(datetime.now().strftime('%d')) # DD wpYYYY = str(datetime.now().strftime('%Y')) # YYYY wpPost.title = 'Stock Market Movers: ' + wpMM + '/' + wpDD + '/' + wpYYYY # Add Title htmlIMG = [] for i in range(len(stock)): # Upload Charts to WordPress imgName = 'https://bspt82221685.files.wordpress.com/' + wpYYYY + '/' + wpMM + '/' + str( stock[i]).lower() + '.png' htmlIMG.append('<figure class="wp-block-image"><a href="' + imgName + '"><img src="' + imgName + '" alt=""/></a></figure>') # Add HTML Tags to Figure data = { 'name': str(stock[i]).lower() + '.png',
def _Client(): return wordpress_xmlrpc.Client(config.WORDPRESS_SITE, config.WORDPRESS_USER, config.WORDPRESS_PASSWORD)