Exemple #1
0
    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))
Exemple #2
0
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))
Exemple #3
0
    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)

        # If output is provided, write the html to a file and abort.
        if self.args.output:
            self._write_html_file(afile)
            return

        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.cache.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
        post.comment_status = "open"
        post.ping_status = "open"
        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)
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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))
Exemple #7
0
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)
Exemple #8
0
    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))
Exemple #9
0
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))
Exemple #10
0
    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()
    '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))
Exemple #13
0
                ) + "</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)