def _create_wp_post(song, content): # Create the NewPost object - see docs at # http://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/wordpress.html # We're missing some fields but ehhhh who knows if they even exist anymore post = WordPressPost() post.title = str(song) post.content = content post.comment_status = 'open' post.ping_status = 'closed' post.post_status = 'publish' post.post_type = 'post' post.excerpt = song.tagline post.date = datetime.now(tz=timezone.utc) post.date_modified = datetime.now(tz=timezone.utc) return NewPost(post)
def push_kuaijiwang(): try: # 检测是否登录成功 # 登录WordPress后台 client = Client("https://www.yebing.cn/xmlrpc.php", "yebing", "yeye910103") except ServerConnectionError: print('登录失败') else: print('登录成功') # wp = client.call(posts.GetPosts({'orderby': 'post_modified', 'number': 50})) # for w in wp: # print(w.link) for item in kuaijiwangarticle.find({"status": 0}): if item['fenlei'] in fenlei_catgory.keys(): if item['tags'].split(",")[0]: # 判断是否有标签,有标签的直接发布,没有的手工 # NewPost()方法,新建一篇文章 newpost = WordPressPost( ) # 创建一个类实例,注意,它不是一个函数。只要在一个类名后面加上括号就是一个实例 newpost.title = item['title'] newpost.content = item['content'] newpost.excerpt = item['summay'] newpost.post_status = 'publish' # private表示私密的,draft表示草稿,publish表示发布 newpost.comment_status = "open" newpost.terms_names = { 'post_tag': item['tags'].split(",")[:2], # 文章所属标签,没有则自动创建 'category': fenlei_catgory.get(item['fenlei']) } # 文章所属分类,没有则自动创建} time.sleep(random.randint(30, 120)) aid = client.call(posts.NewPost(newpost)) if aid: kuaijiwangarticle.update_one({'_id': item['_id']}, {'$set': { 'status': 1 }}) ar_url = "https://www.yebing.cn/article_{}.html".format( aid) print(ar_url) flush(ar_url)
def buildPost(self, item): post = WordPressPost() post.title = self.spin.spin(item['title']) post.content = self.spin.spin(item['content']) post.excerpt = self.spin.spin(item['excerpt']) terms = [] for x in item['tag'].split(','): x = x.strip() if len(x) != 0: terms.append(x) if len(terms) == 0: terms.append(item['category']) post.terms_names = { 'post_tag': terms, 'category': item['category'], } return post
def post_article(title, content, thumbnail_id=None, excerpt='', tags=[], categories=[], comment_status='open', post_status='publish'): article = WordPressPost() article.title = title article.content = content article.excerpt = excerpt article.terms_names = {"post_tag": tags, "category": categories} article.comment_status = comment_status if thumbnail_id: article.thumbnail = thumbnail_id article.post_status = post_status article.id = _client.call(posts.NewPost(article)) return article.id
def entry_to_wppost(entry, client): post = WordPressPost() # Convert entry values to Post value post.user = get_author_by_display_name(entry.author, client) post.date = entry.published_parsed post.post_status = "draft" post.title = entry.title post.content = entry.content[0].value post.excerpt = entry.summary post.link = entry.link # There is some given tags if len(entry.tags): entry.tags = [t.term for t in entry.tags] # Add category (with the first tag) post.terms_names = { 'category': entry.tags[0:1], 'post_tag': [], } # Add tags if len(entry.tags) > 1: post.terms_names['post_tag'] = entry.tags[1:] return post
def push_wp(): try: # 检测是否登录成功 # 登录WordPress后台 client = Client("https://www.yebing.cn/xmlrpc.php", "yebing", "yeye910103") except ServerConnectionError: print('登录失败') else: print('登录成功') # wp = client.call(posts.GetPosts({'orderby': 'post_modified', 'number': 50})) # for w in wp: # print(w.link) for item in article.find({"status": 0}): # NewPost()方法,新建一篇文章 newpost = WordPressPost() # 创建一个类实例,注意,它不是一个函数。只要在一个类名后面加上括号就是一个实例 newpost.title = item['title'] newpost.content = item['content'] newpost.excerpt = item['summary'] newpost.post_status = 'draft' # private表示私密的,draft表示草稿,publish表示发布 newpost.comment_status = "open" newpost.terms_names = { 'post_tag': item['keyword'].split(","), # 文章所属标签,没有则自动创建 'category': ["会计实务"] } # 文章所属分类,没有则自动创建} print(item['keyword'].split(",")) time.sleep(random.randint(30, 80)) aid = client.call(posts.NewPost(newpost)) if aid: article.update_one({'_id': item['_id']}, {'$set': { 'status': 1 }}) print(aid) # 发布新建的文章,返回的是文章id
def post(): #get id post_id = re.search(':wp_id:((.*)|\n)', asc_file_read_str).group(1).strip() #get status post_status = re.search(':wp_status:((.*)|\n)', asc_file_read_str) #get title post_title = re.search(':wp_title:((.*)|\n)', asc_file_read_str) #get slug post_slug = re.search(':wp_slug:((.*)|\n)', asc_file_read_str) #get category post_category = re.search(':wp_category:((.*)|\n)', asc_file_read_str) post_category_str = post_category.group(1).strip().split(", ") if len(post_category_str) == 0: post_category_str = [] elif post_category.group(1).strip() == '': post_category_str = [] elif len(post_category_str) == 1: post_category_str = post_category.group(1).strip(), #get tag post_tag = re.search(':wp_tag:((.*)|\n)', asc_file_read_str) post_tag_str = post_tag.group(1).strip().split(", ") if len(post_tag_str) == 0: post_tag_str = [] elif post_tag.group(1).strip() == '': post_tag_str = [] elif len(post_tag_str) == 1: post_tag_str = post_tag.group(1).strip(), #get excerpt post_excerpt = re.search(':wp_excerpt:((.*)|\n)', asc_file_read_str) #get thumbnail post_thumbnail = re.search(':wp_thumbnail:((.*)|\n)', asc_file_read_str) #post to wordpress from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods import posts client = Client(xmlrpc_url, username, password) post = WordPressPost() date_ = datetime.now() #id New or Edit if not post_id: post.date = date_.strftime("%s") post.id = client.call(posts.NewPost(post)) mode = "New" asc_file_re = re.sub(r':wp_id:((.*)|\n)', ':wp_id: ' + post.id , asc_file_read_str) asc_file_write = open(filepath, 'w') try: asc_file_write.write( asc_file_re ) finally: asc_file_write.close() else: post.date_modified = date_.strftime("%s") post.id = post_id mode = "Edit" post.post_status = post_status.group(1).strip() try: post.title = post_title.group(1).strip() except: print 'Title is not exist' try: post.slug = post_slug.group(1).strip() except: print 'Slug is not exist' post.content = html try: post.excerpt = post_excerpt.group(1).strip() except: post.excerpt = '' post.terms_names = { 'category': post_category_str, 'post_tag': post_tag_str, } try: post.thumbnail = post_thumbnail.group(1).strip() except: post.thumbnail = '' client.call(posts.EditPost(post.id, post)) post_info = client.call(posts.GetPost(post.id, post)) #get post info from wordpress asc_file_read_slug = open(filepath, 'r') asc_file_read_slug_str = asc_file_read_slug.read() if post_info: asc_file_read_slug_str = re.sub(r':wp_slug:((.*)|\n)', ':wp_slug: ' + post_info.slug, asc_file_read_slug_str) if mode == "New": new_date = int(post_info.date.strftime("%s"))+(timezone___*60*60) new_date = datetime.fromtimestamp(new_date).strftime("%Y-%m-%d %H:%M:%S") asc_file_read_slug_str = re.sub(r':wp_date:((.*)|\n)', ':wp_date: ' + new_date, asc_file_read_slug_str) elif mode == "Edit": edit_date = int(post_info.date_modified.strftime("%s"))+(timezone___*60*60) edit_date = datetime.fromtimestamp(edit_date).strftime("%Y-%m-%d %H:%M:%S") asc_file_read_slug_str = re.sub(r':wp_modified:((.*)|\n)', ':wp_modified: ' + edit_date, asc_file_read_slug_str) asc_file_re_slug_write = open(filepath, 'w') try: asc_file_re_slug_write.write( asc_file_read_slug_str ) finally: asc_file_re_slug_write.close() print '==========================\n' + mode + ' Post ID: ' + post.id + ' \nStatus: ' + post.post_status + '\nTitle: ' + post.title + '\nSlug: ' + post_info.slug + '\nCategory: ' + post_category.group(1).strip() + '\nTag: ' + post_tag.group(1).strip() + '\n'
} post_excerpt = """ <span class="tpt-ex-address">%s %s</span> <span class="tpt-ex-price">%s</span> <span class="tpt-ex-mls">MLS : %s</span>""" % (streetnumber, streetname, listpricefix, mlsnumber) # Prepare the post wp = wordpress_xmlrpc.Client(wp_url, wp_username, wp_password, transport=SpecialTransport()) post = WordPressPost() post.title = addressfix post.content = replace_words(template_text, reps) post.excerpt = post_excerpt post.terms_names = { 'post_tag': [mlsnumber], 'category': [listingcategory], } # Check if post exists already print "Post title : " + post.title print "Checking if post exists .." #post_id = find_id(post.title) post_id = find_id(mlsnumber) if post_id: # check if sold date variable is set and update existing post to reflect the property as sold if solddate == "": print "Sorry, a post ID exists already" else:
def createWPEvent(eventType, event): configuration = json.loads(open('config.json').read()) wp = Client('https://greateraustinsecularhub.org/xmlrpc2.php', configuration['wpUser'], configuration['wpKey']) post = WordPressPost() post.post_type = 'events' if eventType == 'meetup': post.title = event['name'] post.content = "" #If the event is public, note the details. eventLocation = "See event details" if event['visibility'] == 'public': eventLocation = event['venue']['name'] eventTags = getTags(event['name'], event['description']) post.terms_names = { 'post_tag': eventTags, #'venue': [eventLocation], 'organizer': [event['group']['name']] } eventStartDateTime_Datetime = datetime.fromtimestamp((event['time']+event['utc_offset'])/1000) eventEndDateTime_Datetime = datetime.fromtimestamp((event['time']+event['utc_offset']+event['duration'])/1000) eventStartTime = eventStartDateTime_Datetime.strftime("%H:%M") eventEndTime = eventEndDateTime_Datetime.strftime("%H:%M") eventStartTime_Pretty = eventStartDateTime_Datetime.strftime("%-I:%M %P") eventEndTime_Pretty = eventEndDateTime_Datetime.strftime("%-I:%M %P") eventStartDateTime = eventStartDateTime_Datetime.strftime("%Y-%m-%d") eventEndDateTime = eventEndDateTime_Datetime.strftime("%Y-%m-%d") post.excerpt = configuration['wpInfoBox'] % (event['group']['name'], eventStartTime_Pretty, eventEndTime_Pretty, eventLocation, ', '.join(eventTags), event['event_url'], event['event_url'], event['description'][:200]) post.custom_fields = [{'key': 'fc_allday','value': 0}, {'key': 'fc_start','value':eventStartDateTime}, {'key': 'fc_start_time','value': eventStartTime}, {'key':'fc_end','value':eventEndDateTime}, {'key':'fc_end_time','value': eventEndTime}, {'key':'fc_interval', 'value':''}, {'key':'fc_end_interval', 'value':''}, {'key': 'fc_dow_except', 'value':''}, {'key':'fc_color', 'value':'#'}, {'key':'fc_text_color', 'value':'#'}, {'key':'fc_click_link', 'value':'view'}, {'key':'fc_click_target', 'value':'_blank'}, {'key':'fc_exdate', 'value':''}, {'key':'fc_rdate', 'value':''}, {'key':'fc_event_map', 'value':''}, {'key':'enable_featuredimage', 'value':1}, {'key':'enable_postinfo', 'value':1}, {'key':'enable_postinfo_image', 'value':1}, {'key':'enable_venuebox', 'value':1}, {'key':'enable_venuebox_gmap', 'value':1}, {'key':'rhc_top_image', 'value':''}, {'key':'rhc_dbox_image', 'value':''}, {'key':'rhc_tooltip_image', 'value':''}, {'key':'rhc_month_image', 'value':''}, {'key': 'meetupID', 'value': event['id']}, {'key': 'meetupLastUpdated', 'value': int(event['updated']/1000)}] #pdb.set_trace() post.post_status = 'publish' #pprint(post) post.id = wp.call(NewPost(post)) time.sleep(0.5) return
apt_num = '(apt #' + apt_num + ')' #Replacements from the template reps = {'%STREETNUMBER%':streetnumber, '%STREETNAME%':streetname + ' ' + streetsuffix, '%APT_NUM%':apt_num, '%POSTALCODE%':postalcode, '%LISTPRICE%':listpricefix, '%MLSNUMBER%':mlsnumber, '%BATHROOMS%':bathrooms, '%BEDROOMS%':bedrooms, '%SQFOOTAGE%':squarefoot, '%DESCRIPTION%':description, '%VIRTUALTOUR%':virtualtour, '%WPBLOG%':siteurl, '%PHONEMSG%':phonemsg, '%MAPLAT%':lat, '%MAPLNG%':lng, '%BASE64IMAGES%':listing_gallery_base64, '%GOOGLEMAPAPI%':google_map_api_key, '%WALKSCORECODE%':walkscore_code } post_excerpt = """ <span class="tpt-ex-address">%s %s</span> <span class="tpt-ex-price">%s</span> <span class="tpt-ex-mls">MLS : %s</span>""" % (streetnumber, streetname, listpricefix, mlsnumber) # Prepare the post wp = wordpress_xmlrpc.Client(wp_url,wp_username,wp_password,transport=SpecialTransport()) post = WordPressPost() post.title = addressfix post.content = replace_words(template_text, reps) post.excerpt = post_excerpt post.terms_names = { 'post_tag': [mlsnumber], 'category': [listingcategory], } # Check if post exists already print "Post title : " + post.title print "Checking if post exists .." #post_id = find_id(post.title) post_id = find_id(mlsnumber) if post_id: # check if sold date variable is set and update existing post to reflect the property as sold if solddate == "" : print "Sorry, a post ID exists already" else :
'type': img.headers['Content-Type'], # mimetype 'bits': img_data } img_attachment = wp.call(media.UploadFile(data)) except: print("Error getting image") post = WordPressPost() post.title = e.title post.content = """ <p><i>Este post fue publicado originalmente en <a href="%s">%s</a> por %s</i></p> %s""" % (link, blog_name, author_string, content) post.post_status = 'draft' post.excerpt = summary post.terms_names = { 'post_tag': ['r', 'contribucion'], 'category': ['Blogs'] } if img_attachment: post.thumbnail = img_attachment['id'] id = wp.call(posts.NewPost(post)) sql = ''' INSERT INTO scraped(date_published, date_scraped, source_id, feed_url, post_url, post_id, wp_id) VALUES(?, ?, ?, ?, ?, ?, ?) ''' c.execute( sql, ( published, # date_published str(datetime.datetime.now()), # date_scraped blog_id, #source_id