Example #1
0
def posttoWP():
    request = urllib2.Request(url)
    request.add_header('Authorization', credentialBing)
    requestOpener = urllib2.build_opener()
    response = requestOpener.open(request) 

    results = json.load(response)
    image = results['d']['results'][0]['Thumbnail']['MediaUrl']
    response = requests.get(image, stream=True)
    with open('testimage'+h+m+s+'.jpg', 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
    del response
    print image

    url = "http://www.easyinjury.com/xmlrpc.php"
    ##URL: www.easyinjury.com
    ##username: James
    ##pwd: mUFmNPvaXefAlgVTaTE#B2ku

    wp = wordpresslib.WordPressClient(url, 'James', 'mUFmNPvaXefAlgVTaTE#B2ku')
    wp.selectBlog(0)
    imageSrc = wp.newMediaObject('testimage'+h+m+s+'.jpg') #Used this format so that if i post images with the same name its unlikely they will override eachother

    img = '/wp-content/uploads/'+yr+'/'+mo+'/testimage'+h+m+s+'.jpg'

    post = wordpresslib.WordPressPost()

    post.title = 'Title'
    post.description = '<img src="'+img+'"/>' + 'Content'
    post.tags = ["wordpress", "lib", "python"]

    # Set to False to save as a draft
    idPost = wp.newPost(post, True)
Example #2
0
 def __init__(self, server_url, username, password, options):
     # options contains the command-line options attributes.
     self.options = options
     # Server-side blog parameters.
     self.url = None
     self.id = None
     self.title = None
     self.status = None  # Publication status ('published','unpublished').
     self.post_type = None  # 'post' or 'page'.
     self.doctype = None  # 'article','book','manpage' or 'html'.
     self.created_at = None  # Seconds since epoch in UTC.
     self.updated_at = None  # Seconds since epoch in UTC.
     self.media = {}  # Contains Media objects keyed by document src path.
     self.categories = []  # List of category names.
     # Client-side blog data.
     self.blog_file = None
     self.checksum = None  # self.blog_file MD5 checksum.
     self.cache_file = None  # Cache file containing persistant blog data.
     self.media_dir = None
     self.content = None  # File-like object containing blog content.
     self.parameters = {}  # AsciiDoc attribute parameter values.
     # XML-RPC server.
     self.server = None  # wordpresslib.WordPressClient.
     self.server_url = server_url  # WordPress XML-RPC server URL.
     self.username = username  # WordPress account user name.
     self.password = password  # WordPress account password.
     verbose('wordpress server: %s:%s@%s' %
             (self.username, self.password, self.server_url))
     self.server = wordpresslib.WordPressClient(self.server_url,
                                                self.username,
                                                self.password,
                                                self.options.proxy)
     self.server.selectBlog(0)
Example #3
0
def postarEmtodos(blog,
                  titulo,
                  descricao,
                  link,
                  foto="",
                  categorias=["Tecnologia da Informação"],
                  tags=["Tecnologia da Informação"],
                  perc=0.8):

    for x in range(0, len(blogs)):
        if random.random() > perc:
            print blogs[x] + ".wordpress.com"

            url = 'https://' + blogs[x] + '.wordpress.com/xmlrpc.php'
            wp = wordpresslib.WordPressClient(
                url, 'pessoal' + str(x + 1) + '@egonkirchof.com.br',
                'pessoal123')
            wp.selectBlog(0)

            # VER NUMERO DA IMAGEM
            if foto != "":
                arquivo = foto  #'blogimg3.jpg'
                imageSrc = wp.newMediaObject('c:\\users\\egon\\downloads\\' +
                                             arquivo)
                #VER ANO E MES
                img = 'http://' + blogs[
                    x] + '.files.wordpress.com/2016/05/' + arquivo

            while True:  # escolhe parceiro
                idx = random.randint(0, len(blogs) - 1)
                if idx != x:
                    break

            parceiro = "https://" + blogs[idx] + ".wordpress.com"
            nome = nomes[idx]

            post = wordpresslib.WordPressPost()
            post.title = titulo
            desc = descricao
            if foto != "":
                desc = desc + "<br><p><img src='" + img + "'/>"

            txt = saibamais[random.randint(0, len(saibamais) - 1)]
            desc = desc + "<br><p>" + txt + "<a href='" + link + "'> clicando aqui</a>"
            txt = visite[random.randint(0, len(visite) - 1)]
            desc = desc + "<br><p>" + txt + "<a href='" + parceiro + "'>" + nome + "</a>"
            post.description = desc

            post.tags = tags
            post.categories = categorias
            #idp = wp.newPost(post,True)
            # print "(pausa)"
            time.sleep(1)

    print "...fim"
Example #4
0
def novopost(nroblog, titulo, descricao, link, foto, categorias, tags):

    blog = infoblogs.blogs[nroblog]
    # print blog+".wordpress.com"
    url = 'https://' + blog + '.wordpress.com/xmlrpc.php'
    wp = wordpresslib.WordPressClient(url, blog, 'pessoal123')
    #'pessoal'+str(nroblog+1)+'@egonkirchof.com.br','pessoal123')
    wp.selectBlog(0)

    if foto != "":
        arquivo = foto
        caminho = 'c:\\users\\egon\\downloads\\imagens blog\\' + arquivo
        if not os.path.isfile(caminho):
            print "foto nao encontrada: " + foto
            foto = ""
        else:
            imageSrc = wp.newMediaObject(caminho)
            #VER ANO E MES
            img = 'http://' + blog + '.files.wordpress.com/2017/02/' + arquivo

    while True:  # escolhe parceiro
        idx = random.randint(0, len(infoblogs.blogs) - 1)
        if idx != nroblog:
            break

    parceiro = "https://" + infoblogs.blogs[idx] + ".wordpress.com"
    nome = infoblogs.nomes[idx]

    post = wordpresslib.WordPressPost()
    post.title = titulo
    txt = infoblogs.antes[random.randint(0, len(infoblogs.antes) - 1)]
    desc = txt + "<br><p><p>" + descricao

    if foto != "":
        desc = desc + "<br><p><img src='" + img + "'/>"

    #add link
    if link != "":
        txt = infoblogs.saibamais[random.randint(0,
                                                 len(infoblogs.saibamais) - 1)]
        desc = desc + "<br><p>" + txt + "<a href='" + link + "'> clicando aqui</a>"

    txt = infoblogs.visite[random.randint(0, len(infoblogs.visite) - 1)]
    desc = desc + "<br><p>" + txt + "<a href='" + parceiro + "'>" + nome + "</a>"
    txt = infoblogs.depois[random.randint(0, len(infoblogs.depois) - 1)]
    desc = desc + "<br><p><p>" + txt

    post.description = desc

    post.tags = tags
    post.categories = categorias
    try:
        idp = wp.newPost(post, True)
    except WordPressException as e:
        print "*** Erro ao postar: " + e.message
Example #5
0
 def test_up_images(self):
     # A typical eLyXer image tag : ELYXER_ENGINER = True
     # A typical LyXHTML image tag : ELYXER_ENGINE = False
     dict = {
         '<img class="embedded" src="test_files/images/table.jpg" />': True,
         "<img src='test_files/images/table.jpg' />": False
     }
     wp = wordpresslib.WordPressClient(
         'http://blogtest.twomorelines.com/xmlrpc.php', 'test', 'test')
     for html, ELYXER_ENGINE in dict.iteritems():
         pr3('\n\n***   Testing the upload of a single image   ***')
         up_images(html, wp, ELYXER_ENGINE, in_DIR_OFFSET='')
Example #6
0
 def _post(title, tags, body, category, hostinfo):
     url = 'http://' + hostinfo[2] + "/xmlrpc.php"
     wpc = wordpresslib.WordPressClient(url, hostinfo[0], hostinfo[1])
     wpc.selectBlog(0)
     post = wordpresslib.WordPressPost()
     post.title = title
     post.description = body
     post.tags = tags
     post.categories.append(category)
     try:
         idPost = wpc.newPost(post, True)
     except:
         print "Error"
         return False
     return True
Example #7
0
    def create_client(self, url, username, password):
        wp = wordpresslib.WordPressClient(url, username, password)
        config = self.config

        if not config.has_option('account', 'blog_id') or config.get(
                'account', 'blog_id') == '':
            blogs = list(wp.get_users_blogs())
            blog = blogs[0]
            print "Arbitrarily picking first blog: %s at %s" % (blog.name,
                                                                blog.url)
            wp.selectBlog(blog.id)
        else:
            blog_id = config.get_int('account', 'blog_id')
            print "Using blog id %s from config" % (blog_id, )
            wp.selectBlog(blog_id)

        return wp
Example #8
0
def postToWP(title, article, url_bing):
    request = urllib2.Request(url_bing)
    request.add_header('Authorization', credentialBing)
    requestOpener = urllib2.build_opener()
    response = requestOpener.open(request)

    results = json.load(response)
    l = len(results['d']['results'])
    image = results['d']['results'][random.randint(0, l -
                                                   1)]['Thumbnail']['MediaUrl']
    response = requests.get(image, stream=True)
    with open('testimage' + h + m + s + '.jpg', 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
    del response

    url = "http://www.cloudhostingcom.com/xmlrpc.php"
    ##username: James
    ##pwd: mUFmNPvaXefAlgVTaTE#B2ku

    wp = wordpresslib.WordPressClient(url, 'admin', 'wIn$j5vG$#NryzJGGlBMd20J')
    wp.selectBlog(0)
    imageSrc = wp.newMediaObject(
        'testimage' + h + m + s + '.jpg'
    )  #Used this format so that if i post images with the same name its unlikely they will override eachother

    img = '/wp-content/uploads/' + yr + '/' + mo + '/testimage' + h + m + s + '.jpg'

    post = wordpresslib.WordPressPost()

    post.title = title
    post.description = '<img src="' + img + '"/> \n' + article
    #post.tags = ["wordpress", "lib", "python"]

    # Set to False to save as a draft
    idPost = wp.newPost(post, True)
    print "Article Posted"
    return True
Example #9
0
 def test_get_post_id(self):
     # prepare client object
     in_wp_obj = wordpresslib.WordPressClient(
         'http://blogtest.twomorelines.com/xmlrpc.php', 'test', 'test')
     id = get_post_id(in_wp_obj)
Example #10
0
    def run(self, id, activity=None):
        #Show user something is happening
        msg = _("Posting to Wordpress blog")
        md = Gtk.MessageDialog(self.pytrainer_main.windowmain.window1,
                               Gtk.DialogFlags.DESTROY_WITH_PARENT,
                               Gtk.MessageType.INFO, Gtk.ButtonsType.NONE, msg)
        md.set_title(_("Wordpress Extension Processing"))
        md.set_modal(True)
        md.show()
        while Gtk.events_pending():  # This allows the GUI to update
            Gtk.main_iteration()  # before completion of this entire action
        logging.debug("before request posting")
        options = self.options
        self.wordpressurl = options["wordpressurl"]
        self.user = options["wordpressuser"]
        self.password = options["wordpresspass"]
        self.gpxfile = "%s/gpx/%s.gpx" % (self.conf_dir, id)
        self.googlekey = options["googlekey"]
        self.idrecord = id
        self.activity = activity
        self.wordpresscategory = options["wordpresscategory"]
        debug_msg = "%s, %s, %s, %s, %s, %s" % (
            self.wordpressurl, self.user, self.gpxfile, self.googlekey,
            self.idrecord, self.wordpresscategory)
        logging.debug(debug_msg)
        try:
            self.wp = wordpresslib.WordPressClient(
                self.wordpressurl, self.user,
                self.password)  #TODO remove need for wordpresslib??
            self.error = False
        except Exception as e:
            self.error = True
            self.log = "Url, user or pass are incorrect. Please, check your configuration"
        self.loadRecordInfo()
        if self.title is None or self.title == "":
            self.title = "Untitled Activity"
        blog_table = self.createTable()
        blog_route = self.createRoute()
        blog_body = self.createBody()

        blog_figureHR = self.createFigureHR()
        blog_figureStage = self.createFigureStage()
        blog_foot = self.createFoot()

        self.description = "<![CDATA[" + blog_body + blog_table + blog_route + blog_figureHR + blog_figureStage + blog_foot + "]]>"
        xmlstuff = '''<methodCall>
<methodName>metaWeblog.newPost</methodName>
<params>
<param>
<value>
<string>MyBlog</string>
</value>
</param>
<param>
<value>%s</value>
</param>
<param>
<value>
<string>%s</string>
</value>
</param>
<param>
<struct>
<member>
<name>categories</name>
<value>
<array>
<data>
<value>%s</value>
</data>
</array>
</value>
</member>
<member>
<name>description</name>
<value>%s</value>
</member>
<member>
<name>title</name>
<value>%s</value>
</member>
</struct>
</param>
<param>
 <value>
  <boolean>1</boolean>
 </value>
</param>
</params>
</methodCall>
''' % (self.user, self.password, self.wordpresscategory, self.description,
        self.title)

        #POST request to Wordpress blog
        h = httplib2.Http()
        res, content = h.request(self.wordpressurl, 'POST', body=xmlstuff)
        logging.debug("after request posting")
        logging.debug("Got response status: %s, reason: %s, content: %s" %
                      (res.status, res.reason, content))
        if res.reason == 'OK':
            res_msg = "Successfully posted to Wordpress."
        else:
            res_msg = "Some error occured\nGot a status %s, reason %s\nContent was: %s" % (
                res.status, res.reason, content)
        #Close 'Please wait' dialog
        md.destroy()
        #Show the user the result
        md = Gtk.MessageDialog(self.pytrainer_main.windowmain.window1,
                               Gtk.DialogFlags.DESTROY_WITH_PARENT,
                               Gtk.MessageType.INFO, Gtk.ButtonsType.OK,
                               res_msg)
        md.set_title(_("Wordpress Extension Upload Complete"))
        md.set_modal(False)
        md.run()
        md.destroy()
import wordpresslib
url = 'https://aprendatecnologiablog.wordpress.com/xmlrpc.php'
wp = wordpresslib.WordPressClient(url, '*****@*****.**',
                                  'pessoal123')
wp.selectBlog(0)

arquivo = 'blog2.jpg'
imageSrc = wp.newMediaObject('c:\\users\\egon\\downloads\\' + arquivo)
img = 'http://aprendatecnologiablog.files.wordpress.com/2016/05/' + arquivo

post = wordpresslib.WordPressPost()
post.title = "3Cansado de procurar?"
post.description = "Achou!<br>" + '<img src="' + img + '"/>'
idp = wp.newPost(post, True)
Example #12
0
 def setUp(self):
     self.wp = wordpresslib.WordPressClient(
         'http://www.hottestporn4u.com/xmlrpc.php', 'pornmaster',
         'pornmasterpiece')
     self.wp.selectBlog(0)
     self.recentPosts = 10
Example #13
0
"""
	Small example script that publish post with JPEG image
"""

# import library
import wordpresslib

print 'Example of posting.'
print

url = raw_input('Wordpress URL (xmlrpc.php will be added):')
user = raw_input('Username:'******'Password:'******'python.jpg')

# FIXME if imageSrc:

# create post object
post = wordpresslib.WordPressPost()
post.title = 'Test post'
post.description = '''
Python is the best programming language in the earth !
Example #14
0
    "Maravilhas da Tecnologia", "O Diario de um Nerd 2016",
    "Amantes da Tecnologia - TI", "Zero Bits Informática",
    "TI em Doses Homeopáticas", "Gotas de TI", "Tecno Mundo Novo",
    "O Zen TIsmo", "Atualidades TI", "Tecno Feras", "Fique Por Dentro da TI",
    "TI de Cabo a Rabo", "Liderança em TI", "100% Tecnologia da Informação",
    "24/7 Pensando em TI", "Viciados em Tecnologia 2016",
    "CTRL+ALT+DEL Informática", "Ctrl+Z Tecnologia", "Sem Pânico! na TI",
    "Somente os Ners São Felizes", "S.O.S. Não tem Internet", "Anjos da TI"
]

for x in range(0, len(blogs)):
    if random.random() > 0.8:
        print blogs[x] + ".wordpress.com"

        url = 'https://' + blogs[x] + '.wordpress.com/xmlrpc.php'
        wp = wordpresslib.WordPressClient(
            url, 'pessoal' + str(x + 1) + '@egonkirchof.com.br', 'pessoal123')
        wp.selectBlog(0)

        # VER NUMERO DA IMAGEM
        arquivo = 'blogimg3.jpg'
        imageSrc = wp.newMediaObject('c:\\users\\egon\\downloads\\' + arquivo)
        #VER ANO E MES
        img = 'http://' + blogs[x] + '.files.wordpress.com/2016/05/' + arquivo

        while True:
            idx = random.randint(0, len(blogs) - 1)
            if idx != x:
                break

        parceiro = "https://" + blogs[idx] + ".wordpress.com"
        nome = nomes[idx]
"""

# import library
import wordpresslib
import xmlrpclib
import datetime

print 'Example of posting.'

url = "http://localhost/wordpress/xmlrpc.php"
#url = "http://www.hottestporn4u.com/"
user = "******"
password = "******"

# prepare client object
wp = wordpresslib.WordPressClient(url, user, password)

# select blog id
wp.selectBlog(0)

# upload image for post
# imageSrc = wp.newMediaObject('python.jpg')

# FIXME if imageSrc:
# create post object
post = wordpresslib.WordPressPost()
post.title = 'yui misaki 4 fd1965 mejicano'
post.description = '<div class="hreview-aggregate"><div class="item vcard"><div itemscope itemtype="http://schema.org/VideoObject"><h2 class="fn"><meta itemprop="embedURL" content="http://xhamster.com/xembed.php?video=1265168" /><iframe width="510" height="400" src="http://xhamster.com/xembed.php?video=1265168" frameborder="0" scrolling="no"></iframe><p><span itemprop="name">yui misaki 4 fd1965</span></h2><meta itemprop="duration" content="T10M31S" /><h3>(10m31s)</h3><meta itemprop="thumbnailUrl" content="http://et4.xhamster.com/t/024/1_1264024.jpg" /><p><span itemprop="description">This video is called yui misaki 4 fd1965</span></div></div><span class="rating"><span class="average">8.52</span> out of <span class="best"> 10 </span>based on <span class="votes">3736 </span>votes</span><p><img src="http://et4.xhamster.com/t/024/1_1264024.jpg" alt="yui misaki 4 fd1965"><br></div>'
post.categories = ['latest updates', 'sex', 'f*****g']
post.tags = ['p**n', 'yui', 'misaki', '4', 'fd1965']
post.date_created = '20120610T00:56:00'
Example #16
0
 def setUp(self):
     self.wp = wordpresslib.WordPressClient(
         'http://www.site.com/wordpress/xmlrpc.php', 'username', 'password')
     self.wp.selectBlog(0)
     self.recentPosts = 10
response = requestOpener.open(request)

results = json.load(response)
image = results['d']['results'][0]['Thumbnail']['MediaUrl']
response = requests.get(image, stream=True)
with open('testimage' + h + m + s + '.jpg', 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response
print image

url = "http://www.easyinjury.com/xmlrpc.php"
##URL: www.easyinjury.com
##username: James
##pwd: mUFmNPvaXefAlgVTaTE#B2ku

wp = wordpresslib.WordPressClient(url, 'James', 'mUFmNPvaXefAlgVTaTE#B2ku')

wp.selectBlog(0)
imageSrc = wp.newMediaObject(
    'testimage' + h + m + s + '.jpg'
)  #Used this format so that if i post images with the same name its unlikely they will override eachother

img = '/wp-content/uploads/' + yr + '/' + mo + '/testimage' + h + m + s + '.jpg'

post = wordpresslib.WordPressPost()

post.title = 'Title'
post.description = '<img src="' + img + '"/>' + 'Content'
post.tags = ["wordpress", "lib", "python"]

# Set to False to save as a draft
Example #18
0
html_version = """\
<b>What is it ?</b><br />
<ul>%s</ul>

<b>What's changed ?</b><br />
<ul>%s</ul>

<i>Translations:</i><br />
<ul>%s</ul>

<b>Where can I get it ?</b><br />
<ul>%s</ul>""" % (text_list([description], 'html'), text_list(
    changes, 'html'), text_list([translations],
                                'html'), text_list(text_links, 'html'))

cp = ConfigParser.ConfigParser()
cp.read(os.environ['HOME'] + '/.config/metacity/tools.ini')

wp = wordpresslib.WordPressClient(cp.get('release-wrangler', 'blogurl'),
                                  cp.get('release-wrangler', 'bloguser'),
                                  cp.get('release-wrangler', 'blogpass'))
wp.selectBlog(cp.getint('release-wrangler', 'blognumber'))
post = wordpresslib.WordPressPost()
post.title = '%s %s released' % (program_name, version)
post.description = html_version
# appears to have been turned off-- ask jdub
#idPost = wp.newPost(post, False)

print html_version
Example #19
0
def main():
    error_msg = ''
    input_file = sys.argv[1]  # Incoming file name
    # DIR_OFFSET is where the file being called is relative to where your shell is open to
    DIR_OFFSET = ''  # Empty until defined otherwise

    # Open LyXBlogger in a separate terminal
    term_open(input_file)

    pr3('LYXBLOGGER')
    pr3('Copyright 2010 - 2012 Jack Desert')
    pr3('Please send any comments, suggestions, or bug reports')
    pr3('to [email protected]')
    pr3('License: GNU GPL3. See <http://www.gnu.org/licenses>')
    pr3('Documentation at http://lyxblogger.nongnu.org\n')
    config = run_init_config()
    time.sleep(config.getfloat('DEFAULT', 'delay'))

    DIR_OFFSET = get_dir_offset(input_file)

    html, blog_title, ELYXER_ENGINE = get_html(
        input_file, config.get('DEFAULT', 'cut_flag'))

    keys = get_credentials(config)

    wordpress_url = keys.url
    user = keys.user
    password = keys.password

    # prepare client object
    wp = wordpresslib.WordPressClient(wordpress_url, user, password)

    # select blog id
    pr3('\nNEW OR EXISTING')
    while (1):
        pr3('Create New post or overwrite Existing? (N) E')
        cat_response = sys.stdin.readline().replace('\n', '')
        if cat_response == 'E' or cat_response == 'e':
            post_id = get_post_id(wp)
            break
        elif cat_response == 'N' or cat_response == 'n' or cat_response == '':
            post_id = 0
            pr3('Publishing new post')
            break
        else:
            pr3("Response Not Understood.\n")
    try:
        wp.selectBlog(post_id)
    except (gaierror, WordPressException):
        handle_gaierror()

    # create post object
    post = wordpresslib.WordPressPost()
    post.title = blog_title

    cat_id = get_cat_id(wp)
    # I have no idea why this takes a tuple (something, )
    post.categories = cat_id  #(cat_id,)
    # publish images
    html = up_images(html, wp, ELYXER_ENGINE, DIR_OFFSET)
    post.description = html
    # publish post
    pr3("\nWORDS\nLet's upload your thoughts")

    filesize = str(os.path.getsize(input_file) / 1024) + ' kB'
    pr3("Uploading xhtml: " + input_file + '.  Size: ' + filesize)
    try:
        if (post_id == 0):
            wp.newPost(post, True)
        else:
            wp.editPost(post_id, post, True)
    except (gaierror, WordPressException):
        handle_gaierror()

    pr3('\nSUCCESS!')
    pr3('You just published your document to ' + wordpress_url[7:-11])
    pr3('Thank you for using LyXBlogger.\n\n')
    wait_for_consumer()
Example #20
0
 def __init__(self):
     self.rpc = wordpresslib.WordPressClient(settings['WORDPRESS_API'],
                                             settings['WORDPRESS_USER'],
                                             settings['WORDPRESS_PASSWORD'])
Example #21
0
 def _get_categories(hostinfo):
     url = 'http://' + hostinfo[2] + "/xmlrpc.php"
     wpc = wordpresslib.WordPressClient(url, hostinfo[0], hostinfo[1])
     wpc.selectBlog(0)
     return wpc.getCategoryList()
Example #22
0
 def __set_connection(self):
     self.__connection = wordpresslib.WordPressClient(
         self.__account.get_full_url(), self.__account.get_username(),
         self.__account.get_password())