def get_tags(self): categories = self.client.call(taxonomies.GetTerms('category')) post_tags = self.client.call(taxonomies.GetTerms('post_tag')) tag_list = [tag.name for tag in post_tags] categories_list = [category.name for category in categories] tag_list.extend(categories_list) return tag_list
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'))
def __init__(self, site='http://domain.com', user='', passwd=''): self.wp = Client('{}/xmlrpc.php'.format(site), user, passwd) self.categories = Taxonomy( ) # self.wp.call(taxonomies.GetTerms('category')) self.tags = Taxonomy() # self.wp.call(taxonomies.GetTerms('post_tag')) _cat = self.wp.call(taxonomies.GetTerms('category')) _tag = self.wp.call(taxonomies.GetTerms('post_tag')) [self.categories.tax_list.append(i.name) for i in _cat] [self.tags.tax_list.append(i.name) for i in _tag] for i in _cat: self.categories.tax_dict.setdefault(i.name, i.taxonomy_id) for i in _tag: self.tags.tax_dict.setdefault(i.name, i.taxonomy_id)
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)
def check_dublicat_city_or_suburb(client): # load categories (city and suburb) taxes = client.call(taxonomies.GetTerms('category')) # clean the return data and add them to list list_all_cate = [] for taxe in taxes: list_all_cate.append(str(taxe)) # open the target file to check data_file = pd.read_csv('Output_files/dog_walking_zone.csv') # standardize the text into lower case data_file['Categories'] = data_file['Categories'].str.lower() # compare the one from the website and the target file for row in range(0, len(data_file)): city = ast.literal_eval(data_file['Categories'][row])[0] suburb = ast.literal_eval(data_file['Categories'][row])[1] if str(city) not in list_all_cate: print('new city=' + city +'|') if str(suburb) not in list_all_cate: print('new suburb = ' + suburb) print('Good Job')
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 delete_all_category(client): cats = client.call(taxonomies.GetTerms('category')) for cat in cats: # avoid deleting the default category if str(cat) != 'Default Category': client.call(taxonomies.DeleteTerm('category', cat.id)) print(str(cat) + ' deleted')
def load_tags(configuration): """ Loads already defined and used tags from WordPress. :param configuration: the configuration to enable a connection with WordPress. :return: the list of defined tags """ client = get_client(configuration) return [t.name for t in client.call(taxonomies.GetTerms('post_tag'))]
def load_categories(configuration): """ Loads already defined categories from WordPress. :param configuration: the configuration to enable a connection with WordPress. :return: the list of defined categories """ client = get_client(configuration) return [c.name for c in client.call(taxonomies.GetTerms('category'))]
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))
def __init__(self, site=SITE, user=SITE_USER, passwd=SITE_PASSWD): try: self.db=pymysql.connect(host=WP_HOST,port=WP_PORT,password=WP_PASSWD,user=WP_USER,database=WP_DB) self.cur=self.db.cursor() except Exception as e: print(e) sys.exit(0) self.wp = Client('{}/xmlrpc.php'.format(site), user, passwd) self.categories = Taxonomy() # self.wp.call(taxonomies.GetTerms('category')) self.tags = Taxonomy() # self.wp.call(taxonomies.GetTerms('post_tag')) _cat=self.wp.call(taxonomies.GetTerms('category')) _tag=self.wp.call(taxonomies.GetTerms('post_tag')) [self.categories.tax_list.append(i.name) for i in _cat] [self.tags.tax_list.append(i.name) for i in _tag] for i in _cat: self.categories.tax_dict.setdefault(i.name,i.taxonomy_id) for i in _tag: self.tags.tax_dict.setdefault(i.name,i.taxonomy_id)
def get_categories(site_id): ''' 获取site_id的所有category :param site_id: :return: ''' site = Site.objects.get(pk=site_id) client = Client(site.url + '/xmlrpc.php', site.username, site.password) categories = client.call(taxonomies.GetTerms('category')) return categories
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
def banUser(): recently_modified = site.call(posts.GetPosts({'orderby': 'post_modified', 'number': 10})) remove_users = [] for post in recently_modified: names = [term.name for term in post.terms] if 'Processed' in names: pass elif 'Remove User' in names and post not in remove_users: remove_users.append(post) proc_tag = [tag for tag in site.call(taxonomies.GetTerms('post_tag')) if tag.name == "Processed"] print(proc_tag) post.terms.append(proc_tag[0]) site.call(posts.EditPost(post.id, post)) break if len(remove_users) >= 1: username = remove_users[0].title if not os.path.exists("images/" + username): print("User not found") else: shutil.rmtree("images/" + username) _trainModel()
def uploadPost(postType, artist, album, song, artwork, connection): albumType, releaseDate = getInfo(artist, album) post = WordPressPost() post.post_type = 'download' if postType == 'bundle': post.title = album else: post.title = song post.content, keyword = getContent(artist, album, song) post.date = datetime.datetime.strptime(releaseDate, '%Y.%m.%d') post.terms = wp.call( taxonomies.GetTerms('download_artist', {'search': artist})) post.thumbnail = artwork post.custom_fields = [] post.post_status = 'publish' post.custom_fields.append({'key': 'year', 'value': releaseDate}) post.custom_fields.append({'key': 'music_type', 'value': postType}) post.id = wp.call(posts.NewPost(post)) with connection.cursor() as cursor: if postType == 'bundle': sql = 'INSERT INTO `upload_info` (`item_type`, `album_type`, `artist`, `album`, `post_title`, `release_date`, `thumbnail_id`, `post_id`, `published`, `updated_at`) VALUES (%s, %s, %s,%s,%s,%s,%s,%s,%s, now())' cursor.execute(sql, (postType, albumType, artist, album, post.title, post.date, post.thumbnail, post.id, '1')) else: sql1 = 'INSERT INTO `upload_info` (`item_type`, `album_type`, `artist`, `album`, `song`, `post_title`, `release_date`, `thumbnail_id`, `post_id`, `published`, `updated_at`) VALUES (%s, %s, %s,%s,%s,%s,%s,%s,%s,%s, now())' sql2 = 'INSERT INTO `wp9r_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES (%s, "_yoast_wpseo_focuskw_text_input", %s)' sql3 = 'INSERT INTO `wp9r_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES (%s, "_yoast_wpseo_focuskw", %s)' cursor.execute( sql1, (postType, albumType, artist, album, song, post.title, post.date, post.thumbnail, post.id, '1')) cursor.execute(sql2, (post.id, keyword)) cursor.execute(sql3, (post.id, keyword)) if postType == 'bundle': print('Upload Successful for album %s - %s. Post id = %s' % (artist, album, post.id)) else: print('Upload Successful for song %s - %s. Post id = %s' % (artist, song, post.id)) return post.id
def getNewUser(): recently_modified = site.call(posts.GetPosts({'orderby': 'post_modified', 'number': 10})) # Get the most recent 10 posts (Would theoretically break if we did 10 random posts and then added a new user post, can expand number if needed media_library = site.call(WordpressMedia.GetMediaLibrary([])) #Get media library of database new_users = [] for post in recently_modified: names = [term.name for term in post.terms] if 'Processed' in names: pass elif 'New User' in names and post not in new_users: new_users.append(post) proc_tag = [tag for tag in site.call(taxonomies.GetTerms('post_tag')) if tag.name == "Processed"] print(proc_tag) post.terms.append(proc_tag[0]) site.call(posts.EditPost(post.id, post)) break # We are only interested in posts with the catagory "New User", so keep track of those if len(new_users) >= 1: post_id = new_users[0].id #In theory, we would only process 1 new user post at a time; the most recent post photo_links = re.findall("class=\"wp-image-([\d]+)\"", new_users[0].content) # Get the media attachment ids for the post directory = "images/" + new_users[0].title os.makedirs(directory) for media in media_library: if str(media.id)in photo_links: resp = requests.get(media.link, stream=True) local_name = directory + "/{}.jpeg".format(media_library.index(media)) local = open(local_name, "wb") resp.raw.decode_content = True shutil.copyfileobj(resp.raw, local) del resp _trainModel()
def testTerm(client): categories = client.call(taxonomies.GetTerms('category')) #decode may have problem when chinese print categories
def get_taxonomies(self, name='category'): if not name in self._taxonomies: self._taxonomies[name] = self.client.call( taxonomies.GetTerms(name)) return self._taxonomies[name]
def index_taxonomies(self): for taxonomy in self.client.call(taxonomies.GetTaxonomies()): self.taxonomies.update({ taxonomy.name: self.client.call(taxonomies.GetTerms(taxonomy.name)) })
for i in range(len(items)): items[i] = items[i].firstChild.data """post_titles = list() post_contents = list() for post in all_posts: title = cleanhtml(post.title) content = cleanhtml(post.content) post_titles.append(title) post_contents.append(content)""" client = Client("https://www.evcilhayvanbakimi.com/xmlrpc.php", 'NorkQ', 'emsile2158') all_posts = client.call(GetPosts()) tags = client.call(taxonomies.GetTerms('post_tag')) for i in range(len(tags)): tags[i] = tags[i].name tags = tags titles = items titles.pop(0) print(tags) print(titles) class Post(): def __init__(self, title, descr, image, category, addres): self.title = title
def test_get_terms(self): terms = self.client.call(taxonomies.GetTerms('category')) self.assert_list_of_classes(terms, WordPressTerm)
from wordpress_xmlrpc.methods import taxonomies from datetime import datetime import json import os.path import re import sys import time import mimetypes client = Client(url="https://www.yourBlogUrl.com/xmlrpc.php", username="******", password="******") TAG_RE = re.compile(r'<[^>]+>') tags = client.call( taxonomies.GetTerms('post_tag', {'search': 'lessthan280chars'})) for date in index: try: year_str = '%04d' % date['year'] month_str = '%02d' % date['month'] data_filename = 'data/js/tweets/%s_%s.js' % (year_str, month_str) with open(data_filename) as data_file: data_str = data_file.read() # Remove the assignment to a variable that breaks JSON parsing, # but save for later since we have to recreate the file first_data_line = re.match(r'Grailbird.data.tweets_(.*) =', data_str).group(0) data_str = re.sub(first_data_line, '', data_str) #if (year_str == "2017"): data = json.loads(data_str) for tweet in data:
country = val['country'] rating = val['rating'] reviewsCount = val['reviewsCount'] jobsCount = val['jobsCount'] latestReview = val['latestReview'] logo = val['logo'] new_company = WordPressPost() new_company.title = name new_company.content = description new_company.post_type = 'company' new_company.post_status = 'publish' new_company.id = wp.call(posts.NewPost(new_company)) taxes = wp.call(taxonomies.GetTerms('company_category')) is_present = 0 post_category_id = 0 for val in taxes: if str(val) == str(industry): is_present = 1 post_category_id = val.id break if is_present == 0: tag = WordPressTerm() tag.taxonomy = 'company_category' tag.name = industry post_category_id = wp.call(taxonomies.NewTerm(tag))
for s in settings.findall('service'): if s.get("name") == "wordpress": wp = Client( s.find("server").text + '/xmlrpc.php', s.find("username").text, s.find("password").text) url = s.find("server").text taxes = wp.call(taxonomies.GetTaxonomies()) print("+ Taxonomies") for t in taxes: print("+- {}".format(t)) sCat = [] print("+ Categories") categories = wp.call(taxonomies.GetTerms('category')) for c in categories: print("+- [{}]".format(c)) sCat.append(str(c)) for c in sList: k = c.replace(" ", "%20") if c not in sCat: r = requests.get(url + '/add.php?category=' + k) print("+ Add {}".format(k)) # Add category # print("test") # parent_cat = wp.call(taxonomies.GetTerm('category', 3)) # for c in parent_cat : # print("+ {}".format(c))
adType = val['adType'] company = val['company'] logo = val['logo'] vacancies = val['vacancies'] external = val['external'] new_job = WordPressPost() new_job.title = title new_job.content = description new_job.post_type = 'job_listing' new_job.post_status = 'publish' new_job.id = wp.call(posts.NewPost(new_job)) 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))
def test_get_tags(self): tags = self.client.call(taxonomies.GetTerms('post_tag')) for tag in tags: self.assertTrue(isinstance(tag, WordPressTerm)) self.assertEquals(tag.taxonomy, 'post_tag')
def test_get_categories(self): cats = self.client.call(taxonomies.GetTerms('category')) for cat in cats: self.assertTrue(isinstance(cat, WordPressTerm)) self.assertEquals(cat.taxonomy, 'category')