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 post_page(wpUrl, wpUserName, wpPassword, articleTitle, articleContent, pageId): # This function updates/creates a page in a wordpress site 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 client.call(posts.EditPost(int(pageId), page)) return pageId
def _update_a_draft(self): postid = self.get_postid() if not postid: slog.warning('Please provide a post id!') return afile, aname = self.conf.get_draft(postid) html, meta, txt, medias = self._get_and_update_article_content(afile) if not html: return if meta.poststatus == 'draft': slog.warning('The post status of draft "%s" is "draft", ' 'please modify it to "publish".'%postid) return # Update all taxonomy before create a new article. self.get_terms_from_wp(['category']) self.get_terms_from_wp(['post_tag']) if meta.posttype == 'page': post = WordPressPage() else: post = WordPressPost() post.terms = self.get_terms_from_meta(meta.category, meta.tags) if not post.terms: slog.warning('Please provide some terms.') return post.content= html post.title = meta.title post.slug = meta.nicename post.date = meta.date post.user = meta.author post.date_modified = meta.modified post.post_status = meta.poststatus postid = self.wpcall(NewPost(post)) if postid: write_by_templ(afile, afile, {'POSTID':postid, 'SLUG':postid}, True) else: return newfile, newname = None, None if meta.posttype == 'page': newfile, newname = self.conf.get_article(meta.nicename, meta.posttype) else: newfile, newname = self.conf.get_article(postid, meta.posttype) slog.info('Move "%s" to "%s".'%(afile, newfile)) shutil.move(afile, newfile)
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 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 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 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 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 post(self): handler, post = self.make_handler_post() if 'blog' not in post: print('You need to specify which blog to post on ' 'in either brc.py or header of %s.' % handler.filename) sys.exit(1) self.auth() kind = post['kind'] title = post['title'] if kind == 'post': wpost = WordPressPost() else: wpost = WordPressPage() wpost.title = title wpost.content = post['content'] wpost.post_status = 'draft' if post['draft'] else 'publish' wpost.terms_names = { 'post_tag': post.get('labels', []), 'category': post.get('categories', []), } resp = {} if 'id' in post: print('Updating a %s: %s' % (kind, title)) self.service.call(posts.EditPost(post['id'], wpost)) else: print('Posting a new %s: %s' % (kind, title)) wpost.id = self.service.call(posts.NewPost(wpost)) wpost = self.service.call(posts.GetPost(wpost.id)) resp['id'] = wpost.id resp['url'] = wpost.link for k in ('service', 'blog', 'kind', 'draft'): resp[k] = post[k] handler.merge_header(resp) handler.write()
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(utype, title, categories, tags, content): logging.info("uploading post \"%s\"" % title) if utype == UploadType.POST: p = posts.WordPressPost() else: p = WordPressPage() p.title = title p.content = content p.post_status = 'publish' if utype == UploadType.POST: p.terms_names = { 'post_tag': tags, 'category': categories } wp_client.call(posts.NewPost(p))
'TNTP': 767, 'Student': 770, 'KTC': 782, 'Big KIPPsters': 4263, 'HR': 3440, } # authentication to tableau server tableau_auth = TSC.TableauAuth('kippndc\josgonzalez', 'Lakai219', 'KIPPLA') # tableau server server = TSC.Server('https://stg-tableau.kipp.org/', use_server_version=True) # authorization for wordpress client = Client('https://kastle.kippla.org/xmlrpc.php', 'Jose Test', 'lakai219') # create wordpress page to be added page = WordPressPage() fileDir = os.path.dirname(os.path.realpath('__file__')) print(fileDir) workbooks = [] views = [] category = None category2 = None isWorkbook = False isView = False user_wb = None user_v = None owner = None with server.auth.sign_in(tableau_auth): req_options = TSC.RequestOptions()
for row in list_results[:101]: l = tr() i=i+1 l.add(td(i)) l.add(td(row[1])) l.add(td(row[2])) l.add(td(row[3])) l.add(td(row[4])) l.add(td(row[5])) l.add(td(row[6])) l.add(td(row[7])) h.add(l) now_date = datetime.datetime.utcnow() last_week = now_date - datetime.timedelta(days=7) today = str(now_date.month) + "-" + str(now_date.day) + "-" + str(now_date.year) week_ago = str(last_week.month) + "-" + str(last_week.day) + "-" + str(last_week.year) wpai = # wp = Client(wpapi, username, password) css - # new_page = WordPressPost() new_page.title = "from" + str(week_ago) +"to" + str(today) table_ = str(h) content = # new_page.content = content upload_page = WordPressPage() page_id = # upload_page.title = # upload_page.content = str(css) + str(content) wp.call(posts.EditPost(page_id, upload_page)) wp.call(posts.NewPost(new_page))
def _update_a_draft(self): postid = self.get_postid() if not postid: slog.warning('Please provide a post id!') return afile, aname = self.conf.get_draft(postid) html, meta, txt, medias = self._get_and_update_article_content(afile) if not html: return if meta.poststatus == 'draft': slog.warning('The post status of draft "%s" is "draft", ' 'please modify it to "publish".' % postid) return # Update all taxonomy before create a new article. self.get_terms_from_wp(['category']) self.get_terms_from_wp(['post_tag']) if meta.posttype == 'page': post = WordPressPage() else: post = WordPressPost() post.content = html post.title = meta.title post.slug = meta.nicename post.date = meta.date post.user = meta.author post.date_modified = meta.modified post.post_status = meta.poststatus post.terms = self.get_terms_from_meta(meta.category, meta.tags) if not post.terms: slog.warning('Please provide some terms.') return postid = self.wpcall(NewPost(post)) if postid: write_by_templ(afile, afile, { 'POSTID': postid, 'SLUG': postid }, True) else: return newfile, newname = None, None if meta.posttype == 'page': newfile, newname = self.conf.get_article(post.nicename, meta.posttype) else: newfile, newname = self.conf.get_article(postid, meta.posttype) slog.info('Move "%s" to "%s".' % (afile, newfile)) shutil.move(afile, newfile)
) + "</b> habitants amb un índex d'envelliment de <b>" + aging + "</b><br>" content += "La seva renda és de <b>" + familyRent + "</b><br>" if len(marketDay) > 1: content += "Hi ha mercat <b>" + marketDay + "</b>" else: content += "No està disponible els dies de mercat" content += "<br><br>Aquestes dades són relatives, no absolutes; per a una franja horària donada, l’afluència es calcula en una escala de 0 a 100, on 100 és el moment de més afluència de tota la setmana, i 0 és el moment en què el mercat està buit. <br>Això ens permet realitzar anàlisis comparatives.<br>" content += "<br> {{CODE_load_bokeh-" + str(marketId) + "}} " content += "{{" + newCode + "}}" + "<br>" firstGraph = False customFields = [{ "key": "CODE_load_bokeh-" + str(marketId), "value": bokehJs }, { "key": newCode, "value": graphHtml }] else: content += "{{" + newCode + "}}" + "<br>" customFields.append({"key": newCode, "value": graphHtml}) print("el contenido es " + content) pageEdited = WordPressPage() pageEdited.content = content pageEdited.title = marketName pageEdited.custom_fields = customFields clean_custom_fields(pageId, "") client.call(posts.EditPost(pageId, pageEdited)) time.sleep(30)
# of the tag and add it to the t_tags list for later use t_tags = [] for e in posts_tags: if e['post_id'] == p['id']: for t in tags: if t['id'] == e['tag_id']: t_tags.append(t['name']) # Creating the Wordpress post object post = WordPressPost() # Trying to parse the post date to be displayed correctly in Wordpress # If the parsing fails we do nothing but continue with the import try: post.date = dateutil.parser.parse(date) except: continue post.terms_names = {'post_tag': t_tags} post.slug = p['slug'] post.content = p['html'] post.title = p['title'] post.post_status = 'publish' # Finally publishing the post post.id = client.call(posts.NewPost(post)) else: page = WordPressPage() page.title = p['title'] page.content = p['html'] page.post_status = 'publish' page.id = client.call(posts.NewPost(page))
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'
'EL': 743, 'SPED': 4076, 'Surveys': 1916, 'Family': 773, 'TNTP': 767, 'Student': 770, 'KTC': 782, 'Big KIPPsters': 4263, 'HR': 3440, } #authorization for wordpress client = Client('https://kastle.kippla.org/xmlrpc.php', 'Jose Test', 'lakai219') #create wordpress page to be added page = WordPressPage() #load spreadsheet with dashboard information wb = load_workbook('Tableau Dashboards.xlsx') #load sheet in spreadsheet ws = wb['Tableau Dashboards'] #function to determine access level def getAccessLevel(x): accessLevels = None if (x == "All Members"): accessLevels = ["all users"] if (x == "SST & School Leaders" or x == "SST and School Leaders Only"): accessLevels = ["school leaders"] if (x == "SST Only" or x == "SST"): accessLevels = ["sst"]