def push_posts(self, title, feature_img, staff, content, img_list, tag_list, categrory): post = WordPressPost() post.title = title post.content = content post.categrory = [] post.categrory.append(categrory) if tag_list: post.terms_names = { 'post_tag': tag_list, 'category': post.categrory } else: post.terms_names = {'post_tag': '', 'category': post.categrory} post.post_status = 'publish' #如果特色图片存在,那么加到图片列表最后一张 if feature_img: img_list.append(feature_img) #上传图片到wp if img_list: for i in range(len(img_list)): img_name = img_list[i].split('/')[-1] filename = img_list[i] #上传的图片本地文件路径 # prepare metadata data = {'name': img_name, 'type': 'image/jpeg'} #data['name']=img_name # read the binary file and let the XMLRPC library encode it into base64 with open(filename, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read()) response = self.wp.call(media.UploadFile(data)) #取最后一张图片作为特色图片 if i == len(img_list) - 1: attachment_id = response['id'] post.thumbnail = attachment_id ''' response == { 'id': 6, 'file': 'picture.jpg' 'url': 'http://www.example.com/wp-content/uploads/2012/04/16/picture.jpg', 'type': 'image/jpeg', } ''' postid = self.wp.call(NewPost(post)) print('正在发布[ID]:%s,[标题]:%s' % (postid, post.title)) # if os.path.isfile(self.wp_log): # with open(self.wp_log,'a+') as f: # f.writelines(str(postid)+'\n') return postid
def main(): blog_settings = yaml.load(Path('./blog.yml').read_text()) wp = Client(blog_settings['xmlrpc-url'], blog_settings['username'], blog_settings['password']) articles = wp.call(GetPosts()) [article.title for article in articles] post = WordPressPost() post.title = 'My new title' post.content = 'This is the body of my new post.' wp.call(NewPost(post)) post.post_status = 'publish' wp.call(EditPost(post.id, post))
def post_event(self, indico_event): post_view = IndicoEventWordpressPostView(indico_event) post = WordPressPost() post.title = post_view.get_title() post.date = post_view.get_date() post.content = post_view.get_content() post.post_status = 'publish' post.comment_status = 'closed' post_id = self.client.call(NewPost(post)) return post_id
def post_wordpress(title, content, post_status, comment_status, post_tags, categories): wp = get_wordpress_client() post = WordPressPost() post.title = title post.content = content post.post_status = post_status post.comment_status = comment_status post.terms_names = { # 'post_tag': ['test', 'firstpost'], # 'category': ['Introductions', 'Tests'] 'post_tag': post_tags, 'category': categories } return wp.call(NewPost(post))
def newPost(self, title, content, category=None): try: post = WordPressPost() post.title = title post.content = content post.date = datetime.datetime.now() post.post_status = 'publish' if category is not None: post.terms_names = {'category': category} postID = self.client.call(NewPost(post)) wpPost = self.client.call(GetPost(postID)) return self.baseURL + "/" + wpPost.slug except Exception as e: print(e) print("Unable to post!")
def wpsend(content, title): try: # 链接地址,登录用户名,密码 wp = Client('http://127.0.0.1/xmlrpc.php', 'bruce', '12345678') # print(content) post = WordPressPost() post.title = str(title) post.content = " ''' " + content + " ''' " post.post_status = 'publish' post.terms_names = {'post_tag': ['福利'], 'category': ['福利', 'magnet']} wp.call(NewPost(post)) localtime = time.localtime(time.time()) print('文档已上传 {}'.format(time.strftime("%Y-%m-%d %H:%M:%S", localtime))) except: print('没有上传成功')
def post(self, entry): """ Post entry to Wordpress. """ # get text with readability post = WordPressPost() post.title = entry.title post.content = "Source: <a href='{}'>{}</a><hr\>{}".format( entry.link, urlparse(entry.link).netloc, self.get_content(entry.link)) post.terms_names = { 'post_tag': entry.keywords, 'category': ["AutomatedPost"] } post.post_status = 'publish' self.client.call(NewPost(post))
def post_article(title, body, category, tag): """发布一篇文章""" try: post = WordPressPost() post.title = title post.content = body post.post_status = "publish" # draft草稿 post.post_type = "post" # page页面 post.comment_status = 'open' # 允许评论 post.date_modified = datetime.datetime.now() post.terms_names = {'category': category, 'post_tag': tag} wp.call(NewPost(post)) log("发布文章:%s..." % title[0:20]) except Exception as e: log_error("文章发布失败!", e)
def _take_action(self, parsed_args): with open(parsed_args.filename, 'r', encoding=parsed_args.encoding) as f: raw_body = f.read() formatted_body = markdown.markdown(raw_body) if parsed_args.dry_run: print('New %s post "%s":\n' % (parsed_args.status, parsed_args.title)) print(formatted_body) else: post = WordPressPost() post.title = parsed_args.title post.content = formatted_body post.post_status = parsed_args.status self.wp.call(NewPost(post))
def upload (self): wp_url = 'http://www.py4seo.com/xmlrpc.php' login = '******' passw = '123456' client = Client(wp_url, login, passw) posts = client.call(GetPosts({'number': 10000})) post = WordPressPost() for ttl, content in self.trans_posts.items(): post.title = ttl post.content = content post.id = client.call(NewPost(post)) post.post_status = 'publish' client.call(EditPost(post.id, post)) url = f'http://py4seo.com/?p={post.id}' print(f'ЗАПОСТИЛИ СТАТЬЮ С ТАЙТЛОМ {ttl}' + ' - ' + url)
def _add_page(page_data): page = WordPressPage() page.title = page_data['fields']['title'] page.slug = page_data['fields']['slug'] page.order = page_data['fields']['_order'] page.date = _return_datetime(page_data['fields']['publish_date']) page.date_modified = _return_datetime(page_data['fields']['updated']) page.content = page_data['fields']['content'] if page_data['fields']['status'] == 1: page.publish_status = 'publish' try: page.id = API.call(NewPost(page)) print("created page", page.id, page.title) except Fault as err: pprint(page) print(err.faultCode, err.faultString)
def create_new_post(wp_instance, title='', content='', author='', tags=[], category=['USAF']): post = WordPressPost() post.title = title content = reformat_url_with_htmltag(content) post.content = content tags.append(author) tags = tags + generate_tags(content) category.append(author) # By far, only classify the 'Kadena' and 'Andersen' AFB if 'Kadena' in tags: category.append('Kadena') if 'Andersen' in tags: category.append('Andersen') post.terms_names = { 'post_tag': tags, 'category': category } post.post_status = 'publish' # insert the new post post_id = wp_instance.call(NewPost(post)) # update the published date to the tweet datetime re_object = re.compile('(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s.*\s\d{4}') original_time = re_object.search(content).group() post.date = parse_post_formated_time(original_time) post.date_modified = post.date # update the post author to the tweet screen name post.post_author = 2 wp_instance.call(EditPost(post_id, post)) return post_id
def post(filename): wp = Client('https://doricardo.com/images/xmlrpc.php', 'user', 'pass') # set to the path to your file filename = '/path/to/my/post.jpg' filename = 'post.jpg' # prepare metadata data = { 'name': 'post.jpg', 'type': 'image/jpeg', # mimetype } # read the binary file and let the XMLRPC library encode it into base64 with open(filename, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read()) response = wp.call(media.UploadFile(data)) #response = { # 'id': 100, # 'file': 'StoriesBras18-1.jpg', # 'url': 'https://i1.wp.com/www.trisportmag.com.br/wp-content/uploads/2018/11/StoriesBras18-1.jpg', # 'type': 'image/jpeg' #} attachment_id = response['id'] #fonte = open('post.txt','r') #content = fonte.read() with open('post_model.json') as fonte: data = json.load(fonte) title = data['title'] description = data['description'] urlmedia = data['media'] category = data['category'] tags = data['tags'] print(title + " " + description) post = WordPressPost() post.title = title post.content = description post.post_status = 'publish' post.thumbnail = attachment_id wp.call(NewPost(post)) print("Conteúdo posta com sucesso")
def push_posts(self, title, content, categrory, tag, img_list): post = WordPressPost() post.title = title post.content = content post.categrory = [] post.categrory.append(categrory) if tag: post.tag = [] post.tag.append(tag) post.terms_names = { 'post_tag': post.tag, 'category': post.categrory } else: post.terms_names = {'post_tag': '', 'category': post.categrory} post.post_status = 'publish' if img_list: for i in range(len(img_list)): img_name = img_list[i].split('/')[-1] filename = './' + img_name #上传的图片本地文件路径 # prepare metadata data = { 'name': 'picture.jpg', 'type': 'image/jpeg', } data['name'] = img_name # read the binary file and let the XMLRPC library encode it into base64 with open(filename, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read()) response = self.wp.call(media.UploadFile(data)) if i == len(img_list) - 1: attachment_id = response['id'] post.thumbnail = attachment_id ''' response == { 'id': 6, 'file': 'picture.jpg' 'url': 'http://www.example.com/wp-content/uploads/2012/04/16/picture.jpg', 'type': 'image/jpeg', } ''' postid = self.wp.call(NewPost(post)) print('正在发布[ID]:%s,[标题]:%s' % (postid, post.title)) return postid, len(post.content)
def sends(data): # print targeturl #u=content1[i][0] #链接WordPress,输入xmlrpc链接,后台账号密码 wp = Client('http://www.stock-t.com/wordpress/xmlrpc.php', 'jiehunt', 'yxpbl1982') post = WordPressPost() post.title = 'MyStockRecommend' # post.post_type='test' post.content = data post.post_status = 'publish' #发送到WordPress #print 'here3' wp.call(NewPost(post)) time.sleep(3) print('posts updates')
def create_year_page(self, year: int) -> None: date_from, date_to = self._api.get_year_date_range(year=year) posts = self._api.get_items(item_type='posts', date_from=date_from, date_to=date_to) posts = sorted(posts, key=lambda item: item['date']) categories = self._api.get_items(item_type='categories', search='{}_'.format(year)) category_planned = _get_planned_category(categories=categories) category_not_planned = _get_not_planned_category(categories=categories) posts_planned = [ post for post in posts if category_planned in post['categories'] ] posts_not_planned = [] if not category_not_planned \ else [post for post in posts if category_not_planned in post['categories']] events_planned = [ EventLink(event_number=i + 1, title=post['title']['rendered'], link=post['link'], date=format_iso_date(post['date'])) for i, post in enumerate(posts_planned) ] events_not_planned = [ EventLink(event_number=i + 1, title=post['title']['rendered'], link=post['link'], date=format_iso_date(post['date'])) for i, post in enumerate(posts_not_planned) ] page = WordPressPage() page.post_status = 'publish' page.title = 'Akcie {}'.format(year) page.content = get_year_page_content( events_planned=events_planned, events_non_planned=events_not_planned) page.date = datetime(year=year, month=1, day=1) page_id = self._client.call(NewPost(page)) notice('Created page {} for year {}'.format(page_id, year))
def Upload(self, directory, filename): """Uploads/Updates/Replaces files""" db = self._loadDB(directory) logger.debug("wp: Attempting upload of %s" % (filename)) # See if this already exists in our DB if db.has_key(filename): pid = db[filename] logger.debug('wp: Found %s in DB with post id %s' % (filename, pid)) else: pid = None fullfile = os.path.join(directory, filename) fid = open(fullfile, 'r') # Read meta data and content into dictionary post = self._readMetaAndContent(fid) #Connect to WP self._connectToWP() # If no pid, it means post is fresh off the press # and not uploaded yet! if not pid: # Get a PID by uploading pid = self.wp.call(NewPost(post)) if pid: logger.debug("wp: Uploaded post with pid %s", pid) db[filename] = pid self._saveDB(directory, db) return True else: logger.error("wp: Couldn't upload post") return False else: # Already has PID, replace post logger.debug("wp: Replacing post with pid %s", pid) #FIXME: Check return value?! self.wp.call(EditPost(pid, post)) return True return False
def requests_digest(): c = conn.cursor() c.execute('select id, name, obit_headline, obit_url, requested_at from requests where request_blogged_at is null') unblogged = c.fetchall() post = WordPressPost() today = datetime.strftime(datetime.today(),'%B %-d, %Y') post.title = 'New requests for FBI files, ' + today post.terms_names = { 'category':['Requests'], 'post_tag':[] } post.content = """We've recently requested the FBI files of the following individuals: <ul>""" for entry in unblogged: name = entry[1] obit_headline = entry[2] obit_url = entry[3] post.content += "\n<li>{name} (<a href=\"{obit_url}\">New York Times obit</a>)</li>".format(**locals()) post.terms_names['post_tag'].append(name.lower()) post.post_status = 'publish' post_id = wp.call(NewPost(post)) post_url = wp.call(GetPost(post_id)).link.replace('http','https') post_date = str(wp.call(GetPost(post_id)).date) post_title = wp.call(GetPost(post_id)).title for entry in unblogged: entry_id = entry[0] c.execute('update requests set request_blogged_at = ?, request_blog_url = ? where id = ?',(post_date,post_url,entry_id)) conn.commit() conn.close() ftd_tweets.tweet_digest_post(post_title,post_url)
def post_wp(d,usite,uname,upass): wp = Client(usite, uname, upass) # wp.call(GetPosts()) # wp.call(GetUserInfo()) post = WordPressPost() post.title = d[2] post.content = d[1] post.terms_names = {'post_tag': d[5],'category': d[4]} post.post_status = 'publish' try: wp.call(NewPost(post)) except Exception as ex: print(str(ex)) excw = open("exception.txt", "a+") excw.write(str(ex)+" : "+time.asctime()+"\n") excw.write("\n--------------------------------------------------------------------------------\n") excw.close() print ("----------------------Wordpress-Post-Done-----------------------")
def post_article(data, title, categories): article = [] for d in data: if d.startswith('/home'): # i still dont like this add_photo(article, d) else: add_text(article, d) post = WordPressPost() post.title = title post.content = '\n'.join(article) # oof post.post_status = 'publish' post.terms_names = { 'post_tag': ['test', 'firstpost'], 'category': categories } id = wp.call(NewPost(post)) a = wp.call(posts.GetPost(id)) return a.link
def post_new(self, title, content, categories=['Mac OS X'], individual_tags='', status='private', date=dt.datetime.now()): post = WordPressPost() post.title = title post.description = content tags = 'automatically posted' if ( self.additional_tags == '') else self.additional_tags + ', automatically posted' tags = individual_tags + tags post.tags = tags post.date_created = date post.post_status = status post.categories = categories self.__wp.call(NewPost(post, True))
def wpsend(content, title, vido_info_kind): try: # 链接地址,登录用户名,密码 wp = Client('http://wh-nb6ulvw9jakg3k41rni.my3w.com/xmlrpc.php', 'bruce', 'flzx3qc@ysyhl9t') # print(content) post = WordPressPost() post.title = str(title) post.content = " ''' " + content + " ''' " post.post_status = 'publish' post.terms_names = { 'post_tag': ['影视'], 'category': ['影视', '链接资源', vido_info_kind] } wp.call(NewPost(post)) localtime = time.localtime(time.time()) print('文档已上传 {}'.format(time.strftime("%Y-%m-%d %H:%M:%S", localtime))) except: print('没有上传成功')
def wpsend(content, title): try: # 链接地址,登录用户名,密码 wp = Client('http://magnetkey.xyz/xmlrpc.php', 'bruce', 'flzx3qc@ysyhl9t') # wp = Client('http://192.168.190.145/xmlrpc.php', 'bruce','12345678') # print(content) post = WordPressPost() post.title = str(title) post.content = " ''' " + content + " ''' " post.post_status = 'publish' post.terms_names = { 'post_tag': ['magnet'], 'category': ['福利', 'magnet'] } wp.call(NewPost(post)) print('文档已上传 {}'.format(daytime)) except: print('没有上传成功')
def wpsend(content, title, vido_info_kind): try: # 链接地址,登录用户名,密码 wp = Client('http://magnetkey.xyz/xmlrpc.php', 'bruce', 'flzx3qc@ysyhl9t') # wp = Client('http://192.168.190.145/xmlrpc.php', 'bruce','12345678') post = WordPressPost() post.title = str(title) post.content = " ''' " + content + " ''' " post.post_status = 'publish' post.terms_names = { 'post_tag': ['magnet', vido_info_kind], 'category': ['福利', 'magnet', vido_info_kind] } wp.call(NewPost(post)) localtime = time.localtime(time.time()) print('文档已上传 {}'.format(time.strftime("%Y-%m-%d %H:%M:%S", localtime))) except: print('没有上传成功')
def post_wordpress(loginid, loginpw, domain, title, content, post_tag, category, post_status): """Word Pressへの簡易投稿 Args: loginid (str): Your login ID. loginpw (str): Your login PassWord. domain (str): Your WordPress domain name. title (str): Post title. content (str): Post contents. post_tag (str[]): Post tag. category (str[]): Post category. post_status (str): Post status. Returns: None """ url = "http://" + domain + "/xmlrpc.php" try: wp = Client('%s/xmlrpc.php' % url, loginid, loginpw) except ServerConnectionError: sys.exit("Cannot Connect to the server. Please check your network.") except: sys.exit("Cannot find configuration!") post = WordPressPost() post.title = title post.content = content post.terms_names = {"post_tag": post_tag, "category": category} post.status = post_status try: wp.call(NewPost(post)) except InvalidCredentialsError: sys.exit("Username or Password is incorrect") except XmlrpcDisabledError: sys.exit("XML-RPC services are disabled in WordPress") print("Finish post!")
def wpsend(content, title): try: # 链接地址,登录用户名,密码 wp = Client('http://magnetkey.xyz/xmlrpc.php', 'bruce', 'flzx3qc@ysyhl9t') post = WordPressPost() # 设置标题内容 post.title = str(title) # 文章正文内容 post.content = " ''' " + content + " ''' " # 可见性,publish:全部可见;'private':私有 post.post_status = 'publish' # 设置标签,分类 post.terms_names = {'post_tag': ['短资讯'], 'category': ['短资讯', '虎扑']} # # 新建文章 wp.call(NewPost(post)) localtime = time.localtime(time.time()) print('文档已上传 {}'.format(time.strftime("%Y-%m-%d %H:%M:%S", localtime))) except: print('没有上传成功')
def post_to_wordpress_system(self,article): post_tag_list = [] category_list = [] wp_client = Client('http://jpnewfilm.com/xmlrpc.php', 'jpadmin', 'qQ2@wW') post = WordPressPost() post.title = article.title post.content = article.body_wordpress post.post_status = 'publish' post.terms_names = { 'post_tag': post_tag_list, 'category': category_list, } try: post_time = datetime.today() result = wp_client.call(NewPost(post)) except Exception as e: Msg = u'@@@发布文章%s 有错误!(errmsg:%s)' % (article.id, e) wp_logging(Msg=Msg)
def insertPostFromDB(): conn = sqlite3.connect('qtfy.db') c = conn.cursor() idx = 0 db = qtfy_db('qtfy.db') for row in c.execute("select mid, name, url, desc, info, img from movie"): if idx>2: break post = WordPressPost() print row[0] post.title = row[1] lk = db.get_movielnks(row[0]) post.content = gen_webpage(row[3], row[4], row[5], lk) # row[3] + row[4] post.terms_names={'post_tag':['liu', 'jing']} post.post_status = "publish" idx += 1 print wp.call(NewPost(post)) conn.commit() conn.close()
def new_post(site_id, article_id, category=None, post_tag=None): site = Site.objects.get(pk=site_id) client = Client(site.url + '/xmlrpc.php', site.username, site.password) article = Article.objects.get(pk=article_id) post = WordPressPost() post.title = article.title post.content = article.context # ## post.post_status='publish' # ## 文章默认发布为草稿 post.post_status = 'publish' if category: post.terms_names = {'category': category} if post_tag: post.terms_names = {'post_tag': post_tag} post_id = client.call(NewPost(post)) return post_id
def _add_blogpost(post_data): ''' Adds a blog post parsed from blog.blogpost Model published status codes are as follows: PUBLISHED = 1, DRAFT = 2, DELETED = 3 :param post_data: Python dict of post structure. See modelsamples/blogpost_sample.txt for structure. :return: ''' post = WordPressPost() post.post_type = 'news' post.title = post_data['fields']['title'] post.content = post_data['fields']['content'] post.date = _return_datetime(post_data['fields']['publish_date']) post.date_modified = _return_datetime(post_data['fields']['updated']) post.slug = post_data['fields']['slug'] if post_data['fields']['status'] == 2: post.post_status = 'publish' # Assign Author if post_data['fields']['user']: wp_userid = _get_wordpress_user_id_by_email( _get_django_user_email_by_id(post_data['fields']['user'])) if wp_userid: post.user = wp_userid # TODO set catagories and tags to proper taxonomy # post.terms_names = { # 'category': ['Blogpost'] # } # if post_data['fields']['categories']: # categories = [] # for category in dp.get_content(DJANGO_DATA, 'blog.blogcategory'): # if category['pk'] in post_data['fields']['categories']: # categories.append(category['fields']['title']) # post.terms_names['post_tag'] = categories try: if post_data['fields']['status'] != 3: post.id = API.call(NewPost(post)) print("created post", post.id, post.title) except Fault as err: pprint(post) print(err.faultCode, err.faultString)