def update_authors_page(self): pages = self._client.call( posts.GetPosts({'post_type': 'page'}, results_class=wordpress_xmlrpc.WordPressPage)) authors_page = [page for page in pages if page.title == 'Authors'][0].id authors_count = {} for i in itertools.count(0, 10): some_posts = self._client.call( posts.GetPosts({ 'number': 10, 'offset': i })) if len(some_posts) == 0: break # no more posts returned for post in some_posts: for term in post.terms: if term.taxonomy == 'post_tag': author = term.name authors_count[author] = authors_count.get(author, 0) + 1 links = [ '<a href="https://mathematicaldeliberations.wordpress.com/tag/{}/">{} - {} posts</a>' .format(name.lower().replace(' ', '-'), name, count) for name, count in authors_count.items() ] rec = wordpress_xmlrpc.WordPressPage() rec.title = 'Authors' rec.content = '<div style="direction: ltr; text-align: left;"><ul>\n' + \ '\n'.join(['<li style="text-align: left;">{}</li>'.format(link) for link in links]) + \ '\n</ul></div>' self._client.call(posts.EditPost(authors_page, rec))
def GetPosts(count=100): """Return public wordpress posts.""" client = _Client() post_query = wp_posts.GetPosts({'post_status': 'publish', 'number': count}) public = client.call(post_query) post_query = wp_posts.GetPosts({'post_status': 'private', 'number': count}) private = client.call(post_query) return public + private
def get(utype): if utype == UploadType.POST: entries = wp_client.call(posts.GetPosts({'post_status':'publish', 'number':10000})) else: entries = wp_client.call(posts.GetPosts({'post_type': 'page', 'post_status':'publish', 'number':10000})) logging.info("parsing %d entries" % len(entries)) all_posts = {} for entry in entries: logging.info("found entry %s with title \"%s\"" % (entry.id, entry.title)) all_posts[entry.title] = { 'id': entry.id, 'content': entry.content } return all_posts
def filter_posts(): user = current_user client = check_login(user.wp_url, user.wp_username, login_session['pw']) if request.method == 'POST': custom_filter = request.form['filter'] max_show = request.form['number'] # show max if max is filled in, otherwise ignore it filtered_posts = client.call( posts.GetPosts({ 'post_type': custom_filter, 'number': max_show })) if max_show is not None else client.call( posts.GetPosts({'post_type': custom_filter})) return filtered_posts else: return render_template('posts/posts.html')
def list(self): pages = self.client.call( posts.GetPosts({'post_type': 'page'}, results_class=WordPressPage)) assert len(pages) > 0 self.assert_list_of_classes(pages, WordPressPage) for p in pages: print p.title, p.id
def getPostList(): postList = wp.call( posts.GetPosts({ 'post_type': 'download', 'number': 999999 })) return postList
def _load_current_movies(self): log.info( f"Fetching _movies from site {self.url} to avoid duplicates...") movies = [] offset = 0 increment = 100 while True: data = self.get_client().call( posts.GetPosts({ "post_type": "movies", "number": increment, "offset": offset })) if not data: break for post in data: title = post.title.strip().lower() year = None for term in post.terms: if term.taxonomy == "movie_year": year = term.name movies.append(WPMovie(title, year)) offset = offset + increment log.info(f"Fetching _movies for {self.url} is done.") self._movies = movies
def test_pages(user, password): from wordpress_xmlrpc import WordPressPage client = Client('http://www.weeklyosm.eu/xmlrpc.php', user, password) pages = client.call( posts.GetPosts({'post_type': 'page'}, results_class=WordPressPage)) p = pages[0] print(p.id) print(p.title)
def check_dublicate_post_name(client): posts_list = client.call(posts.GetPosts({'number': 100})) print(len(posts_list)) list_all_posts = [] for post in posts_list: list_all_posts.append(str(post)) print(len(list_all_posts))
def getAllPosts(self): ''' get all the posts ''' ps = self.wordpress.call(posts.GetPosts()) #for post in ps: #print "title: %s, id %s " % (post.title, post.id) return ps
def getContent(self): pages = self.client.call(posts.GetPosts({'post_type': 'page', 'id' : self.pageid})) for p in pages: # print p.title #print p.id if p.id == self.pageid: return p.content return None
def saveData(self): blog_list = self.wp.call(posts.GetPosts({'offset': 0, 'number': 663})) post_list = [] csv_title = ['漫画ID', '标题'] for blog in blog_list: post_list.append([blog.id, blog.title]) post_data = pd.DataFrame(columns=csv_title, data=post_list) post_data.to_csv('已发布的漫画列表.csv', encoding='UTF-8') # , mode='a', header=False
def load_drafts(configuration, draft_count): """Loads all draft posts from WordPress""" client = get_client(configuration) draft_posts = client.call( posts.GetPosts({ 'post_status': 'draft', 'number': str(draft_count) })) return draft_posts
def delete_all_post(client): allposts = client.call(posts.GetPosts({'number': 1765})) # add the number of total post on the web id_list = [] for post in allposts: id_list.append(post.id) for item in id_list: check = client.call(posts.DeletePost(item)) print(str(check))
def test(): client = Client('http://www.weeklyosm.eu/xmlrpc.php', 'alexandre', 'SENHA') posts = client.call(posts.GetPosts()) #for post in posts[:1]: #print(posts[1].id) #print(posts[1].title) #print(posts[1].link) print(posts[0].content)
def wp_truncate(): client = Client(os.getenv('SCRAPY_WP_RPCURL'), os.getenv('SCRAPY_WP_USERNAME'), os.getenv('SCRAPY_WP_PASSWORD')) while 1: posts_slice = client.call(posts.GetPosts()) if len(posts_slice): for p in posts_slice: client.call(posts.DeletePost(p.id)) else: break
def run(self): self.logger.info("[%s] running" % self.name) # 验证地址是否可用 try: wp = Client(self.xmlrpc, self.user, self.passwd) para = {'number': (self.offset + 1) * 50} self.__wordpressitems = wp.call(posts.GetPosts(para)) except Exception, x: self.logger.info("[%s] xmlrpc connection or getinfor error" % self.name) self.logger.error(str(x))
def updatePost(self): blog_list = self.wp.call( posts.GetPosts({ 'offset': 0, 'number': 661, 'post_status': 'publish' })) for blog in blog_list: post = WordPressPost() post.title = blog.title post.post_status = 'draft' print('当前编辑文章:', blog.title) self.wp.call(posts.EditPost(blog.id, post))
def mostrar_todas_las_entradas(): offset = 0 increment = 20 while True: limpiar_pantalla() print("Mostrando entradas desde {} hasta {}".format(offset + 1, increment)) entradas = cliente.call(posts.GetPosts({'number': increment, 'offset': offset})) if len(entradas) == 0: break # no more posts returned mostrar_tabla_posts(entradas) eleccion = input("¿Ver más? [S/N] ") if eleccion.lower() != "s": break offset = offset + increment imprimir_menu_opciones()
def order_posts(): user = current_user client = check_login(user.wp_url, user.wp_username, login_session['pw']) if request.method == 'POST': date = request.form['date'] title = request.form['title'] order = request.form['order'] ordered_posts = client.call( posts.GetPosts({ 'orderby': date, 'order': order })) return ordered_posts else: return render_template('posts/posts.html')
def getWordpressPostsLimit(): wpPost = [] try: wpClient = Client(app.config.get('BLOG_URL'), app.config.get('BLOG_USER'), app.config.get('BLOG_PASSWORD')) wpPost = wpClient.call( posts.GetPosts({ 'number': 4, 'post_status': 'publish' })) except (ServerConnectionError, InvalidCredentialsError) as e: logging.warn(e.message) finally: return wpPost
def _get_post_id_by_title(self) -> Dict[str, int]: """Get all post ids, by their title.""" post_id_by_title = {} page = 0 while True: posts_on_page = self._client.call( posts.GetPosts({"offset": page * GET_POST_PAGE_COUNT})) for post in posts_on_page: post_id_by_title[post.title] = post.id # we know we're done processing all posts if we # get fewer posts than the page would return max. if len(posts_on_page) < GET_POST_PAGE_COUNT: break page += 1 return post_id_by_title
def importNewUser(): BASE_DIR = os.path.dirname(os.path.abspath(__file__)) IMG_DIR = os.path.join(BASE_DIR, "images") site = Client('http://192.168.137.26/xmlrpc.php', '*****@*****.**', 'Bpl2 vF31 ePl6 Unoa rAcC kJGm') # This IP is dependent on the wordpress site being hosted on my laptop's hotspot. recently_modified = site.call(posts.GetPosts({'orderby': 'post_modified', 'number': 100})) # Get the most recent 100 posts (Would theoretically break if we did 100 random posts and then added a new user post, # can expand number if needed media_library = site.call(media.GetMediaLibrary([])) # Get media library of database new_users = [] added_new_user = False for post in recently_modified: terms = post.terms for term in terms: if 'New User' == term.name and post not in new_users: new_users.append(post) added_new_user = True # We are only interested in posts with the category "New User", so keep track of those # Should be deleting requests after each message # Or maybe add a tag that says "Processed" to keep history? That way it is ignored on a second call to this script post_id = new_users[0].id # In theory, we would only process 1 new user post at a time and then either delete the post or # add a tag that prevents future processing (i.e. the list will always have only 1 post in it) photo_links = re.findall("class=\"wp-image-([\d]+)\"", new_users[0].content) print(photo_links) # Get the media attachment ids for the post for m in media_library: if str(m.id)in photo_links: print(m) print(m.link) resp = requests.get(m.link, stream=True) local_name = "Temp_Pictures/get_image_test{}.jpeg".format(media_library.index(m)) local = open(local_name, "wb") resp.raw.decode_content = True shutil.copyfileobj(resp.raw, local) del resp # Using the attachment ids, get pictures from media library and use links to download pictures to a temporary folder # on the pi # Temp folder can be used by main.py to import the new images and create a new recognizer return added_new_user
def get_post(url): try: _url = "{}/{}".format(url.get('url'), "xmlrpc.php") user_name = url.get('userName') password = url.get('password') client = Client(_url, user_name, password) news = client.call(posts.GetPosts({ 'orderby': 'date', 'order': 'DESC' })) if news is None: return None else: return news[0] except Exception as e: print(e) return None
def get_posts(self, post_type=None): results = [] if not post_type: return results offset = 0 increment = 20 while True: post_filter = { 'post_type': post_type, 'number': increment, 'offset': offset } result = self.client.call(posts.GetPosts(post_filter)) if len(result) == 0: break # no more posts returned results.extend(result) offset = offset + increment return results
def uploadMedia(self, presenter, title, reference, date_str, media_fname, createPost=True,verbose=False): offset = 0 increment = 5 #20 print 'self.post_title = ', self.post_title, ' type(self.post_title) = ', type(self.post_title) while True: if verbose: print "GetPosts(number=", increment, "offset = ", offset, ")" pages = self.client.call(posts.GetPosts({'number': increment, 'offset': offset,'post_type': 'page'})) offset += increment if len(pages) == 0: print 'No more pages' break for p in pages: if verbose: print "Title = '", p.title, "' Id =", p.id, 'type(p.title)', type(p.title) if p.title == self.post_title: if verbose: print "calling self.uploadFile()" # upload the audio/video file media_url = self.uploadFile(date_str, media_fname, verbose) template = """<p align="left">{0} : {1} - {2} - {3} <a href="{4}">Play MP3</a></p>\n""" # strip out characters we don't understand - better than crashing! title = title.encode('ascii','ignore') line = template.format(date_str, presenter, title, reference, media_url) # put new content at the front. p.content = line + p.content p.post_status = 'publish' # magic : avoid 'Invalid attachment ID.' exception from EditPost p.thumbnail = None if verbose: print 'upload complete, url = ', media_url, 'adding line=', line print 'post = ', p try: self.client.call(posts.EditPost(p.id, p)) if verbose: print 'post.EditPost complete' except Exception as inst: print 'uploadMedia: posts.EditPost() failed', inst return None else: if createPost: return self.createMP3Post(presenter, title, reference, date_str, media_url, verbose) return None
def _load_current_episodes(self): log.info(f"Fetching tvshows from {self.url} to avoid duplicates...") tv_shows = [] offset = 0 increment = 100 while True: data = self.get_client().call( posts.GetPosts({ "post_type": "tvshows", "number": increment, "offset": offset })) if not data: break tv_shows.extend([post.title for post in data]) offset = offset + increment #TODO: check format of tv_shows to adjust according self._episodes which is of type helpers.Episode raise Exception self._episodes = tv_shows log.info(f"Fetching tvshows from {self.url} is done.")
def delete_post_from_one_category(client): allposts = client.call(posts.GetPosts({'number': 1274})) # add the number of total post on the web delete_list = [] for post in allposts: cat_list = [] for term in post.terms: cat_list.append(str(term)) if 'tourist site' in cat_list: delete_list.append(post.id) # print(cat_list) print(len(delete_list)) for item in delete_list: check = client.call(posts.DeletePost(item)) print(str(check))
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 getPosts( ): blog = Client(settings.wikityXmlRpc, settings.wikityUsername, settings.wikityPassword ) cards = [] cardBoxes = [] offset = 0 increment = 20 while True: print("Getting from %s to %s" % ( offset, offset+increment)) postList = blog.call(posts.GetPosts({'number': increment, 'offset': offset})) if len(postList) == 0: break # no more posts returned for post in postList: if post.title.startswith("CardBox::" ): cardBoxes.append(post) else: cards.append(post) offset = offset + increment return( cardBoxes, cards)