コード例 #1
0
def _deploy(article_id, zendesk_url, cloudfront_url, username, password):
    path = "site/" + article_id + "/index.html"
    locale = "en-us"

    # Check if the article_id is valid.
    if not os.path.exists("posts/" + article_id):
        print(Fore.RED + "The article_id you entered is invalid." + Fore.RESET)
        sys.exit(1)

    title = open("posts/" + article_id + "/title.html").readline()

    if not title:
        print(Fore.RED + "Add a title to posts/" + article_id +
              "/title.html before deploying the article." + Fore.RESET)
        sys.exit(1)

    # Prepare files for being pushed to Zendesk.
    renderer.render_zendesk_deployment(cloudfront_url, article_id)

    # Push the images to CloudFront.
    cloudfront_images.push_to_cloudfront(article_id)

    # Delete extra images on CloudFront.
    cloudfront_images.delete_from_cloudfront(article_id)

    # Build connection to Zendesk.
    zendesk = Zendesk(zendesk_url, username, password)

    if not compare_repos.compare_article_contents(article_id, zendesk):
        return

    # Packages the data in a dictionary matching the expected JSON.
    update_article = {
        "translation": {
            "title": title,
            "body": open(path, mode='rb').read()
        }
    }

    response = zendesk.help_center_article_translation_update(
        article_id, locale, update_article)

    # Check if article is in Draft mode.
    check_draft = response["translation"]["draft"]
    if check_draft:
        print(Fore.YELLOW + "Reminder that article " + article_id +
              " is still in draft mode." + Fore.RESET)

    print "Article " + article_id + " has been updated at: " + zendesk_url + "/" + article_id
コード例 #2
0
def _deploy(article_id, zendesk_url, cloudfront_url, username, password):
    path = "site/" + article_id + "/index.html"
    locale = "en-us"

    # Check if the article_id is valid.
    if not os.path.exists("posts/" + article_id):
        print (Fore.RED + "The article_id you entered is invalid." + Fore.RESET)
        sys.exit(1)

    title = open("posts/" + article_id + "/title.html").readline()

    if not title:
        print (Fore.RED + "Add a title to posts/" + article_id + "/title.html before deploying the article." + Fore.RESET)
        sys.exit(1)

    # Prepare files for being pushed to Zendesk.
    renderer.render_zendesk_deployment(cloudfront_url, article_id)

    # Push the images to CloudFront.
    cloudfront_images.push_to_cloudfront(article_id)

    # Delete extra images on CloudFront.
    cloudfront_images.delete_from_cloudfront(article_id)

    # Build connection to Zendesk.
    zendesk = Zendesk(zendesk_url, username, password)

    if not compare_repos.compare_article_contents(article_id, zendesk):
        return

    # Packages the data in a dictionary matching the expected JSON.
    update_article = {"translation": {"title": title, "body": open(path, mode = 'rb').read()}}

    response = zendesk.help_center_article_translation_update(article_id, locale, update_article)

    # Check if article is in Draft mode.
    check_draft = response["translation"]["draft"]
    if check_draft:
        print (Fore.YELLOW + "Reminder that article " + article_id + " is still in draft mode." + Fore.RESET)

    print "Article " + article_id + " has been updated at: " + zendesk_url + "/" + article_id
コード例 #3
0
        translations = zendesk.help_center_article_translations(
            article_id=article['id'], locales=args.locale)
        for translation in translations['translations']:
            for i in range(0, len(args.old)):
                if translation['body'] is None or args.old[
                        i] not in translation['body']:
                    continue

                print('=' * 200)
                print(translation['body'])

                translation['body'] = translation['body'].replace(
                    args.old[i], args.new[i])

                print('=' * 200)
                print(translation['body'])

                if args.ask and not query_yes_no('> Apply this change?'):
                    if not args.dry_run:
                        zendesk.help_center_article_translation_update(
                            article_id=article['id'],
                            locale=args.locale,
                            data=translation)

    if (articles['next_page'] is None):
        break
    page += 1
    articles = zendesk.help_center_articles_list(per_page=100, page=page)

sys.exit(0)