def write_page(survey_id): survey = Survey(survey_id) pages = survey.wordpress_client.call(posts.GetPosts({'post_type': 'page'}, results_class=WordPressPage)) template = Template(filename='/home/tom/src/airbnb/web_page_template.mako') content = template.render( city=survey.city, city_underbar=survey.city_underbar, date = survey.date, listings = survey.listings, survey_id=survey.survey_id, url_root = URL_ROOT, ) page = WordPressPage() page.title = ('Airbnb survey ' + str(survey.survey_id) + ', for ' + survey.city + ', collected on ' + survey.date) page.content = content page.post_status = 'publish' # Find if the page exists for a_page in pages: if page.title==a_page.title: page.id = a_page.id survey.wordpress_client.call(posts.EditPost(page.id, page)) return page.id = survey.wordpress_client.call(posts.NewPost(page))
def update(self, _page_title, _page_id, _markdown): """ Update an existing wordpress page with generated markdown. Assumes you have a markdown file with content you want published to an existing wordpress page. :param _page_title: post page title :param _page_id: post page id :param _markdown: path to markdown file for upload """ wp = Client(self.endpoint, self.username, self.password) # define pages variable page = WordPressPage() page.title = _page_title # page id can be found by viewing via wp-admin dashboard in URL page.id = _page_id # set local content file to read handle info into a string with open(_markdown, "r") as _file: page.content = _file.read() # post new content to the page wp.call(EditPost(page.id, page))
def create_template_files(file_name): #1. create scss file #assets/scss/templates/_[name].scss try: fh = open(sass_directory + '_'+ file_name + '.scss','r') except: # if file does not exist, create it fh = open(sass_directory + '_'+ file_name + '.scss','w') #2. Import newly created Sass file to global one #assets/scss/templates/app.scss with open('assets/scss/foundation.scss', 'a') as f: f.write('\n@import "templates/' + file_name + '";') #f.writelines(lines) #3. create image folder #assets/images/[name] if not(os.path.exists(image_directory + file_name)): os.makedirs(image_directory + file_name) #4a. Create page template if not(os.path.exists(page_template_directory + file_name) ): with open(page_template_directory + file_name + '.php', 'a') as f: f.writelines(['<?php \n', '/* Template Name: '+ file_name.capitalize() +' */\n', ' get_header();\n', '?>', '\n\n', '<?php get_footer();']) #4b. Create page in wordpress and connect to the template page client = Client(site_host + 'xmlrpc.php', username, password) page = WordPressPage() page.title = file_name.capitalize() page.content = '' page.post_status = 'publish' page.template = 'page-templates/about.php' page.id = client.call(posts.NewPost(page))
def post_page(wpUrl, wpUserName, wpPassword, articleTitle, articleContent): client = Client(wpUrl, wpUserName, wpPassword) # Page page = WordPressPage() page.title = articleTitle page.content = articleContent # page.terms_names = {'post_tag': articleTags, 'category': articleCategories} page.post_status = 'publish' # post.thumbnail = attachment_id page.id = client.call(posts.NewPost(page)) print('Post Successfully posted. Its Id is: ', page.id) return page.id
def update_wiki(url, username, password, _page_title, _page_id, _markdown): wp = Client(url, username, password) # define pages variable page = WordPressPage() page.title = _page_title # page id can be found by viewing via wp-admin dashboard in URL page.id = _page_id # set local content file to read handle info into a string with open(_markdown, 'r') as _file: page.content = _file.read() # post new content to the page wp.call(EditPost(page.id, page))
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 page(): #get id page_id = re.search(':wp_id:((.*)|\n)', asc_file_read_str).group(1).strip() #get page status page_status = re.search(':wp_status:((.*)|\n)', asc_file_read_str).group(1).strip() #get title page_title = re.search(':wp_title:((.*)|\n)', asc_file_read_str).group(1).strip() #get slug page_slug = re.search(':wp_slug:((.*)|\n)', asc_file_read_str).group(1).strip() page_thumbnail = re.search(':wp_thumbnail:((.*)|\n)', asc_file_read_str).group(1).strip() #post to wordpress from wordpress_xmlrpc import Client, WordPressPage, WordPressPost from wordpress_xmlrpc.methods import posts client = Client(xmlrpc_url, username, password) page = WordPressPage() post = WordPressPost() #id New or Edit if not page_id: page.date = datetime.now().strftime("%s") page.id = client.call(posts.NewPost(page)) mode = "New" asc_file_re = re.sub(r':wp_id:((.*)|\n)', ':wp_id: ' + page.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: page.date_modified = datetime.now().strftime("%s") page.id = page_id mode = "Edit" #page status page.post_status = page_status #page title try: page.title = page_title except: print 'Title is not exist' #page slug try: page.slug = page_slug except: print 'Slug is not exist' #page content page.content = html #page thumbnail try: page.thumbnail = page_thumbnail except: page.thumbnail = '' client.call(posts.EditPost(page.id, page)) page_info = client.call(posts.GetPost(page.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 page_info: asc_file_read_slug_str = re.sub(r':wp_slug:((.*)|\n)', ':wp_slug: ' + page_info.slug, asc_file_read_slug_str) if mode == "New": new_date = int(page_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(page_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 + ' Page ID: ' + page.id + ' \nStatus: ' + page.post_status + '\nTitle: ' + page.title + '\nSlug: ' + page_info.slug + '\n'
'staging_dashboard_link', 'value': "<script type='text/javascript' src='https://stg-tableau.kipp.org/javascripts/api/viz_v1.js'></script><div class='tableauPlaceholder' style='width: 1200px; height: 100px;'><object class='tableauViz' width='1200' height='1000' style='display:none;'><param name='host_url' value='https%3A%2F%2Fstg-tableau.kipp.org%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='/t/KIPPLA' /><param name='name' value='" + user_wb.replace(' ', '').replace('&', '').replace( '/', '').replace('(', '').replace(')', '') + "/" + user_v.replace(' ', '').replace('&', '').replace( '/', '').replace('(', '').replace(')', '') + "' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='showAppBanner' value='false' /></object></div>" }) # thumbnail id of the image we just uploaded page.thumbnail = thumbnail_id # publish page page.post_status = 'publish' # create page page.id = client.call(posts.NewPost(page)) print(Fore.RED + '\nAdded ' + category + ': ' + view.name + '\n' + 'Owner: ' + owner.fullname + '\n') else: # add wordpress page info # get screenshot saved on computer and upload to wordpress # windows #image_path = 'View Thumbnails//' + user_wb+ '_' + user_v + '.jpg' # mac image_path = 'View Thumbnails/' + user_wb + '_' + user_v + '.jpg' filename = os.path.join(fileDir, image_path) data = { 'name': user_wb + '_' + user_v + '.jpg', 'type': 'image/jpg', }