Exemple #1
0
    def test_term_parent_child(self):
        parent = WordPressTerm()
        parent.taxonomy = 'category'
        parent.name = 'Test Parent Term'

        parent_id = self.client.call(taxonomies.NewTerm(parent))
        self.assertTrue(parent_id)
        parent.id = parent_id

        child = WordPressTerm()
        child.taxonomy = parent.taxonomy
        child.name = 'Test Child Term'
        child.parent = parent.id

        child_id = self.client.call(taxonomies.NewTerm(child))
        self.assertTrue(child_id)
        child.id = child_id

        try:
            # re-fetch to verify
            child2 = self.client.call(taxonomies.GetTerm(child.taxonomy, child.id))
            self.assertEqual(child.parent, child2.parent)
        finally:
            # cleanup
            self.client.call(taxonomies.DeleteTerm(child.taxonomy, child.id))
            self.client.call(taxonomies.DeleteTerm(parent.taxonomy, parent.id))
Exemple #2
0
    def test_term_search(self):
        tag1 = WordPressTerm()
        tag1.taxonomy = 'post_tag'
        tag1.name = 'Test FoobarA'

        tag1_id = self.client.call(taxonomies.NewTerm(tag1))
        self.assertTrue(tag1_id)
        tag1.id = tag1_id

        tag2 = WordPressTerm()
        tag2.taxonomy = 'post_tag'
        tag2.name = 'Test FoobarB'

        tag2_id = self.client.call(taxonomies.NewTerm(tag2))
        self.assertTrue(tag2_id)
        tag2.id = tag2_id

        try:
            results = self.client.call(taxonomies.GetTerms('post_tag', {'search': 'foobarb'}))
            found_tag1 = False
            found_tag2 = False
            for tag in results:
                if tag.id == tag1_id:
                    found_tag1 = True
                elif tag.id == tag2_id:
                    found_tag2 = True
            self.assertFalse(found_tag1)
            self.assertTrue(found_tag2)
        finally:
            # cleanup
            self.client.call(taxonomies.DeleteTerm(tag1.taxonomy, tag1.id))
            self.client.call(taxonomies.DeleteTerm(tag2.taxonomy, tag2.id))
def create_city_suburb_categories(client):
    # open the cities files to DataFrame
    data_file = pd.read_csv('Output_files/new_Suburbs_final-2.csv')

    # get the cities with no duplication rows and convert it to list
    list_lga = data_file['Municipality'].unique().tolist()

    # loop throw the cities
    for lga in list_lga:

        # get the suburbs of each city
        suburbs = data_file[data_file['Municipality'] == lga]['Suburb'].tolist()

        # create city category as parent
        cat = WordPressTerm()
        cat.taxonomy = 'category'
        cat.name = lga
        cat.id = client.call(taxonomies.NewTerm(cat))
        print('==================================')
        print('Done City ' + lga)

        # create suburbs categories as child for each city
        for suburb in suburbs:
            child_cat = WordPressTerm()
            child_cat.taxonomy = 'category'
            child_cat.parent = cat.id
            child_cat.name = suburb
            client.call(taxonomies.NewTerm(child_cat))
            print('Done Suburb ' + suburb)
Exemple #4
0
    def test_term_lifecycle(self):
        term = WordPressTerm()
        term.name = 'Test Term'
        term.taxonomy = 'category'

        # create the term
        term_id = self.client.call(taxonomies.NewTerm(term))
        self.assertTrue(term_id)
        term.id = term_id

        # re-fetch to verify
        term2 = self.client.call(taxonomies.GetTerm(term.taxonomy, term.id))
        self.assertEqual(term.name, term2.name)

        # set a description and save
        term.description = "My test term"
        response = self.client.call(taxonomies.EditTerm(term.id, term))
        self.assertTrue(response)

        # re-fetch to verify
        term3 = self.client.call(taxonomies.GetTerm(term.taxonomy, term.id))
        self.assertEqual(term.description, term3.description)

        # delete the term
        response = self.client.call(taxonomies.DeleteTerm(term.taxonomy, term.id))
        self.assertTrue(response)
Exemple #5
0
    def test_category_post(self):
        # create a test post
        post = WordPressPost()
        post.title = 'Test Post'
        post.slug = 'test-post'
        post.user = self.userid
        post.id = self.client.call(posts.NewPost(post))

        # create a test category
        cat = WordPressTerm()
        cat.name = 'Test Category'
        cat.taxonomy = 'category'
        cat.id = self.client.call(taxonomies.NewTerm(cat))

        # set category on post
        try:
            post.terms = [cat]
            response = self.client.call(posts.EditPost(post.id, post))
            self.assertTrue(response)

            # fetch categories for the post to verify
            post2 = self.client.call(posts.GetPost(post.id, ['terms']))
            post_cats = post2.terms
            self.assert_list_of_classes(post_cats, WordPressTerm)
            self.assertEqual(post_cats[0].id, cat.id)
        finally:
            # cleanup
            self.client.call(taxonomies.DeleteTerm(cat.taxonomy, cat.id))
            self.client.call(posts.DeletePost(post.id))
Exemple #6
0
    def test_category_lifecycle(self):
        # Create category object
        cat = WordPressTerm()
        cat.name = 'Test Category'
        cat.taxonomy = 'category'

        # Create the category in WordPress
        cat_id = self.client.call(taxonomies.NewTerm(cat))
        self.assertTrue(cat_id)
        cat.id = cat_id

        try:
            # Check that the new category shows in category suggestions
            suggestions = self.client.call(
                taxonomies.GetTerms('category', {'search': 'test'}))
            self.assertTrue(isinstance(suggestions, list))
            found = False
            for suggestion in suggestions:
                if suggestion.id == cat_id:
                    found = True
                    break
            self.assertTrue(found)
        finally:
            # Delete the category
            response = self.client.call(
                taxonomies.DeleteTerm(cat.taxonomy, cat.id))
            self.assertTrue(response)
Exemple #7
0
def NewTerm(WpTerm=None):
  Bj = WpC.WB.Bj
  L.info("\nNew WpTerm= {} {} {}", WpTerm.name, WpTerm.slug , WpTerm)
  L.info("\nNew WpTerm, WpCli={}, XmlCli={}", Bj.WpCli, Cli.XmlCli)
  WpTerm.id = int(Bj.WpCli.call(taxonomies.NewTerm( WpTerm )))
  L.info("\nNew WpTerm.id= {}", WpTerm.id )
  return WpTerm.id
Exemple #8
0
 def create_taxonomy(self, parent_cat_id, name, taxonomy='category'):
     child_cat = WordPressTerm()
     child_cat.taxonomy = taxonomy
     if parent_cat_id:
         child_cat.parent = parent_cat_id
     child_cat.name = name
     child_cat.id = self.client.call(taxonomies.NewTerm(child_cat))
     return child_cat
Exemple #9
0
    def new_term(self, taxonomy, name, parent_id):
        term = WordPressTerm()

        term.taxonomy = taxonomy
        term.name = name
        term.parent = parent_id

        term.id = self.client.call(taxonomies.NewTerm(term))
def create_new_post(client, post_list):

    # get all categories
    cats = client.call(taxonomies.GetTerms('category'))

    # Store categories in a list
    list_all_cate = []
    s_cat_id = ''
    sports_cat_id = 7377
    worship_cat_id = 7376

    for cat in cats:

        # store the special category id
        if str(cat) == 'special_cat':
            s_cat_id = cat.id
            print('the special_cat id is : ' + cat.id)

        list_all_cate.append(str(cat))



    # work with each post
    for post in post_list:

        # if the sub-category under the special category (special_cat) does not exit create it
        if post[2][-2] == 'sports':

            if str(post[2][-1]) not in list_all_cate:

                print('does not exist: ' + str(post[2][-1]))
                child_cat = WordPressTerm()
                child_cat.taxonomy = 'category'
                child_cat.parent = sports_cat_id
                # get the last element in the category list
                child_cat.name = str(post[2][-1])
                client.call(taxonomies.NewTerm(child_cat))
                # Add the new category to the list
                list_all_cate.append(str(post[2][-1]))
            else:
                print('looking good')

        # create the post
        newPost = WordPressPost()
        newPost.title = post[1]
        newPost.content = post[0]
        newPost.post_status = 'publish'

        # check if the suburb exist in other cities
        # -- something something --

        newPost.terms_names = {
            'post_tag': post[3],
            'category': post[2]
        }
        # newPost.thumbnail = post[3]

        client.call(posts.NewPost(newPost))
Exemple #11
0
 def checkCategorys(self):
     self.categorys = self.rpcClient.call(taxonomies.GetTerms('category'))
     if len(self.categorys) < 2:
         for category in all_categorys:
             cat = WordPressTerm()
             cat.name = category
             cat.taxonomy = 'category'
             cat.id = self.rpcClient.call(taxonomies.NewTerm(cat))
         self.categorys = self.rpcClient.call(
             taxonomies.GetTerms('category'))
Exemple #12
0
 def _insert(self, name, slug=None, type='category', parentid=None):
     cat = WordPressTerm()
     cat.taxonomy = type
     cat.name = name  # 分类名称
     cat.parent = parentid  # 父分类
     cat.slug = slug  # 分类别名,可以忽略
     taxid = self.wp.call(taxonomies.NewTerm(cat))  # 新建分类返回的id
     if type == 'category':
         self.categories.tax_list.append(name)
         self.categories.tax_dict.setdefault(name, taxid)
     else:
         self.tags.tax_list.append(name)
         self.tags.tax_dict.setdefault(name, taxid)
    def insert_category(self, category_joomla, ref_cat):
        client = self.get_client()

        idx = random.randint(0, 80)

        cat = WordPressTerm()
        cat.taxonomy = 'category'

        if category_joomla.get_parent() != 0:
            # id da categoria pai
            cat.parent = ref_cat.get(category_joomla.get_parent())

        cat.name = category_joomla.get_name()
        cat.slug = str(idx) + str(cat.name)
        cat.id = client.call(taxonomies.NewTerm(cat))

        return cat.id
Exemple #14
0
def add_child_category(cat_set, title):
    wp = Client(hiddenInfo.wp_URL, hiddenInfo.wp_author, hiddenInfo.wp_pass)
    categories = wp.call(taxonomies.GetTerms('category'))
    for category_count in range(len(categories)):
        str_category = str(categories[category_count])
        if (str_category == title):
            # print("カテゴリは既にあります")
            return 0
    for category_count in range(len(categories)):
        str_category = str(categories[category_count])
        if (str_category == cat_set):
            try:
                # print(categories[category_count])
                child_cat = WordPressTerm()
                child_cat.taxonomy = 'category'
                child_cat.parent = categories[category_count].id
                child_cat.name = title
                child_cat.id = wp.call(taxonomies.NewTerm(child_cat))
                # print("子カテゴリを作ります")
            except:
                pass
            taxes = wp.call(taxonomies.GetTerms('job_listing_type'))
            is_present = 0
            post_category_id = 0

            for val in taxes:
                if str(val) == str(type):
                    is_present = 1
                    post_category_id = val.id
                    break

            if is_present == 0:
                tag = WordPressTerm()
                tag.taxonomy = 'job_listing_type'
                tag.name = type
                post_category_id = wp.call(taxonomies.NewTerm(tag))

            category = wp.call(
                taxonomies.GetTerm('job_listing_type', post_category_id))
            post = wp.call(posts.GetPost(new_job.id))

            post.terms.append(category)
            wp.call(posts.EditPost(post.id, post))

            attachment_id = 0

            if logo:

                print "https://www.mustakbil.com" + str(logo)

                img_data = requests.get("https://www.mustakbil.com" +
Exemple #16
0
data = json.loads(text)
tags = data['db'][0]['data']['tags']
all_posts = data['db'][0]['data']['posts']
posts_tags = data['db'][0]['data']['posts_tags']

# Go through all existing tags and create them
# in Wordpress with the same name, slug and id
for t in tags:
    slug = t.get('slug', None)
    name = t.get('name', None)

    tag = WordPressTerm()
    tag.taxonomy = 'post_tag'
    tag.name = name
    tag.slug = slug
    tag.id = client.call(taxonomies.NewTerm(tag))

# Go through all existing posts
for p in all_posts:
    # If the post is really a 'post' and not a 'page'
    if p['page'] == 0:
        # If we do not have a published_at date, we use the created_at value
        date = p['published_at']
        if date is None:
            date = p['created_at']

        # Take the post_id from the post export, go through the post/tag map and
        # find all tag ids associated with the post. For every tag id we find
        # associated with the post, we loop through the tags and find the name
        # of the tag and add it to the t_tags list for later use
        t_tags = []