Exemple #1
0
def get_post(request, id):
    wordpress_settings = get_wordpress_meta()
    wp = Client(wordpress_settings["rpc"], wordpress_settings["username"],
                wordpress_settings["password"])
    post = wp.call(GetPost(id))
    serializer = PostSerializer(post)
    return Response(serializer.data)
Exemple #2
0
def wpsend(content, title, vido_info_kind):
    try:
        # 链接地址,登录用户名,密码
        wp = Client('http://192.168.190.145/xmlrpc.php', 'bruce', '12345678')
        # print(content)
        post = WordPressPost()
        # 设置标题内容
        post.title = str(title)
        # 文章正文内容
        post.content = " ''' " + content + " ''' "
        # 可见性,publish:全部可见;
        post.post_status = 'publish'
        # 设置标签,分类
        post.terms_names = {
            'post_tag': ['影视'],
            'category': ['影视', '链接资源', vido_info_kind]
        }
        # 验证是否有相同标题
        old_post = wp.call(GetPost(post.title))
        # old_post = GetPost(post.title)
        print(old_post)
        if post.title == old_post:
            wp.call(DeletePost(post.title))
            print('已经删除{}'.format(post.title))
        else:
            # 新建文章
            wp.call(NewPost(post))
            localtime = time.localtime(time.time())
            print('文档已上传 {}'.format(
                time.strftime("%Y-%m-%d %H:%M:%S", localtime)))
    except:
        print('没有上传成功')
Exemple #3
0
def publish_post(podcast_and_config, wp_details, wp, settings):
    '''copies the podcast object, updates it according to the supplied details dict and edits the one on the blog'''
    podcastcopy = copy.copy(podcast_and_config[0])
    podcastcopy.title = wp_details['title']
    podcastcopy.content = wp_details['content']
    podcastcopy.date = wp_details['date']
    podcastcopy.post_status = wp_details['post_status']
    if type(podcast_and_config[0].thumbnail) == types.DictType:
        podcastcopy.thumbnail = podcast_and_config[0].thumbnail[
            'attachment_id']
    fields_of_interest = [
        'audio_file', 'bible_passage', 'duration', 'episode_number',
        'filesize_raw', 'preacher', 'publish_now', 'date_recorded'
    ]
    for custom_fields in podcastcopy.custom_fields:
        if custom_fields['key'] in fields_of_interest and custom_fields[
                'key'] in wp_details:
            custom_fields['value'] = wp_details[custom_fields['key']]
            fields_of_interest.remove(custom_fields['key'])
    for custom_field in fields_of_interest:
        if custom_field in wp_details:
            podcastcopy.custom_fields.append({
                'key': custom_field,
                'value': wp_details[custom_field]
            })
    if 'tags' in wp_details and wp_details['tags'] != []:
        podcastcopy.terms.extend(wp_details['tags'])
    if wp.call(EditPost(podcastcopy.id, podcastcopy)):
        return wp.call(GetPost(podcastcopy.id))
    else:
        print('Could not update podcast ' + podcastcopy.id + ': ' +
              podcastcopy.title)
Exemple #4
0
    def createPost(self, title, description, size, tags, links, category):
        wp = Client(self.wp_url,
                    self.wp_username,
                    self.wp_password,
                    transport=SpecialTransport())
        post = WordPressPost()
        post.post_status = 'publish'
        title = title.replace('.', ' ')
        title = title.replace('_', ' ')
        post.title = title
        post.content = 'Size:<b> ' + size + '</b> <br /><br /><br />'
        post.content = post.content + description
        post.content = post.content + '<br /><div class=' "downLinks" '>Download Links:</div>'

        addLinks = '<textarea readonly>'
        for link in links:
            addLinks = addLinks + link + '&#13;&#10;'
        addLinks = addLinks + '</textarea>'

        post.content = post.content + addLinks

        post.terms_names = {'post_tag': tags, 'category': [category]}

        id = wp.call(NewPost(post))
        postLink = WordPressPost()
        postLink = wp.call(GetPost(id))
        return postLink.link
def new_post(account, post):
    wp = Client(account['xmlrpc_url'], account['username'],
                account['password'])
    post.id = wp.call(NewPost(post))
    tmp = wp.call(GetPost(post.id))
    detail = "GetPost: %s - %s - %s" % (tmp.id, tmp.title, tmp.link)
    print(detail)
    result(detail)
def wpArticle(format_string):
    '''
    Simple tag to pull the contents of a Wordpress Article inside a Django
    template. Best used with caching.
    '''
    wp = wpClient()
    post = wp.call(GetPost(format_string))
    return linebreaks(wpCaption(post.description))
Exemple #7
0
def requests_digest():

    c = conn.cursor()
    
    c.execute('select id, name, obit_headline, obit_url, requested_at from requests where request_blogged_at is null')
    unblogged = c.fetchall()

    post = WordPressPost()
    today = datetime.strftime(datetime.today(),'%B %-d, %Y')
    post.title = 'New requests for FBI files, ' + today    

    post.terms_names = {
        'category':['Requests'],
        'post_tag':[]
    }

    post.content = """We've recently requested the FBI files of the following individuals:

    <ul>"""
    

    for entry in unblogged:        
        name = entry[1]
        obit_headline = entry[2]
        obit_url = entry[3]
        
        post.content += "\n<li>{name} (<a href=\"{obit_url}\">New York Times obit</a>)</li>".format(**locals())
        post.terms_names['post_tag'].append(name.lower())

    post.post_status = 'publish'
    
    post_id = wp.call(NewPost(post))
    
    post_url = wp.call(GetPost(post_id)).link.replace('http','https')
    post_date = str(wp.call(GetPost(post_id)).date)
    post_title = wp.call(GetPost(post_id)).title

    for entry in unblogged:
        entry_id = entry[0]
        c.execute('update requests set request_blogged_at = ?, request_blog_url = ? where id = ?',(post_date,post_url,entry_id))

    conn.commit()
    conn.close()

    ftd_tweets.tweet_digest_post(post_title,post_url)
Exemple #8
0
    def _show_post(self):
        field = {}
        field['number'] = self.args.number
        field['orderby'] = self.args.orderby
        field['order'] = self.args.order

        if self.args.query:
            return GetPost(self.get_postid())
        return GetPosts(field)
Exemple #9
0
    def _show_page(self):
        field = {'post_type': 'page'}
        field['number'] = self.args.number
        field['orderby'] = self.args.orderby
        field['order'] = self.args.order

        if self.args.query:
            return GetPost(self.get_postid(), result_class=WordPressPage)
        return GetPosts(field, result_class=WordPressPage)
Exemple #10
0
def getPostList( idList ):
    blog = Client(settings.wikityXmlRpc, settings.wikityUsername, 
                 settings.wikityPassword )

    posts = []

    for id in idList: 
        post = blog.call(GetPost(id))
        posts.append(post)

    return posts
Exemple #11
0
 def trashPost(self, postIDs):
     for postID in postIDs:
         post = WordPressPost()
         #根据ID查看文章
         try:
             plot = self.wp.call(GetPost(postID))
             # print('删除文章:',plot,type(plot),plot.title)
             post.title = plot.title
             post.post_status = 'trash'
             self.wp.call(EditPost(postID, post))
             print('已删除文章[ID]:[%s],[标题]:%s' % (postID, plot.title))
         except:
             print('文章[ID]:[%s],已经被删除,请不要重复删' % postID)
Exemple #12
0
 def newPost(self, title, content, category=None):
     try:
         post = WordPressPost()
         post.title = title
         post.content = content
         post.date = datetime.datetime.now()
         post.post_status = 'publish'
         if category is not None:
             post.terms_names = {'category': category}
         postID = self.client.call(NewPost(post))
         wpPost = self.client.call(GetPost(postID))
         return self.baseURL + "/" + wpPost.slug
     except Exception as e:
         print(e)
         print("Unable to post!")
Exemple #13
0
    def _show_page(self):
        field = {'post_type':'page'}
        field['number'] = self.args.number
        field['orderby'] = self.args.orderby
        field['order'] = self.args.order

        method = None
        if self.args.query:
            method = GetPost(_get_postid(), result_class=WordPressPage)
        else:
            method =  GetPosts(field, result_class=WordPressPage)
        results = self.wpcall(method)
        if results:
            self.print_results(results)
        else:
            slog.warning('No results for showing.')
Exemple #14
0
    def _show_post(self):
        field = {}
        field['number'] = self.args.number
        field['orderby'] = self.args.orderby
        field['order'] = self.args.order

        method = None
        if self.args.query:
            method = GetPost(_get_postid())
        else:
            method = GetPosts(field)
        results = self.wpcall(method)
        if results:
            self.print_results(results)
        else:
            slog.warning('No results for showing.')
Exemple #15
0
    def _update_an_article(self, postid):
        afile, aname = self.conf.get_article(postid, self.args.type)

        # 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
        resultclass = WordPressPost
        if self.args.type == 'page':
            postid = meta.postid
            resultclass = WordPressPage

        post = self.wpcall(GetPost(postid, result_class=resultclass))
        if not post:
            slog.warning('No post "%s"!'%postid)
            return
        slog.info('Old article:')
        self.print_results(post)
        post.title = meta.title
        post.user = meta.author
        post.slug = meta.nicename
        post.date = meta.date
        post.content = html
        post.post_status = meta.poststatus
        if meta.modified:
            post.date_modified = meta.modified

        terms = self.cache.get_terms_from_meta(meta.category, meta.tags)
        if terms:
            post.terms = terms
        elif self.args.type == 'post':
            slog.warning('Please provide some terms.')
            return

        succ = self.wpcall(EditPost(postid, post))
        if succ == None:
            return
        if succ:
            slog.info('Update %s successfully!'%postid)
        else:
            slog.info('Update %s fail!'%postid)
Exemple #16
0
text = ' '.join(parse_google(key))
parse_image(key)
image_path = f"images\\{listdir('images')[0]}"

post = WordPressPost()
post.title = f'Dz29 Vertinskyi Post For Key: {key}'
post.content = text

post.terms_names = {'post_tag': ['dz29', key], 'category': ['vertinskyi', key]}

new_post = wp_client.call(NewPost(post))

post.post_status = 'publish'
wp_client.call(EditPost(new_post, post))

data = {
    'name': image_path,
    'type': 'image/jpeg',
}

with open(image_path, 'rb') as img:
    data['bits'] = xmlrpc_client.Binary(img.read())

response = wp_client.call(media.UploadFile(data))

my_post = wp_client.call(GetPost(new_post))

my_post.thumbnail = response['id']

result = wp_client.call(EditPost(my_post.id, my_post))
Exemple #17
0
 def getPostContent(self, post_id):
     post = self.wp.call(GetPost(post_id))
     return post.content
Exemple #18
0
 def publishPost(self, post_id):
     post = self.wp.call(GetPost(post_id))
     post.post_status = 'publish'
     self.wp.call(EditPost(post_id, post))
     return post_id
Exemple #19
0
 def get_post(self, blog, post_id):
     """
     Fetch a post object.
     """
     xmlrpc = self.get_xmlrpc(blog)
     return xmlrpc.call(GetPost(post_id))
Exemple #20
0
 def get_post_by_estate(self, estate):
     post_id = int(self.client.call(GetPostID(self.META_KEY, estate.id)))
     if post_id:
         return self.client.call(GetPost(post_id))
                'username', 'password')
all_posts = client.call(
    GetPosts({
        'number': 80,
        'post_status': 'publish'
    },
             results_class=WordPressPost))

print(all_posts[0])

titles = []  #all_posts[0] etc
content = []  #one_post.content etc
post_id = 0
for i, post in enumerate(all_posts):
    post_id = all_posts[i].id
    one_post = client.call(GetPost(post_id))
    one_post.content = re.sub(r'<[^<]+?>', '', one_post.content)
    one_post.content = re.sub(r"\[.*?\]", '', one_post.content)

    titles.append(all_posts[i])
    one_post.content = one_post.content.encode('ascii',
                                               'ignore').decode('ascii')
    content.append(one_post.content)

print(titles, len(content))

df = pd.DataFrame()
df["Titles"] = titles
df["content"] = content

df.to_csv("blog_content and titles.csv", index=None)