Exemple #1
0
 def _new_term(self):
     if not self.args.query or len(self.args.query)<1:
         slog.error('Provide 1 arguments at least please.')
         return
     query = self.get_term_query()
     print('query:', query)
     term = self.get_terms_from_wp(query, force=True)
     print(term)
     if term:
         slog.error('The term "%s" has been in wordpress.'%self.args.query[0])
         return
     taxname = query[0]
     slug = self.args.query[0]
     name = self.args.query[1] if len(self.args.query)>1 else slug
     term = WordPressTerm()
     term.slug = slug
     term.name = name
     term.taxonomy = taxname
     if len(self.args.query)>2:
         term.description = self.args.query[2]
     termid = self.wpcall(NewTerm(term))
     if not termid:
         return
     term = self.wpcall(GetTerm(taxname, termid))
     if not term:
         return
     slog.info('The term %s(%s) has created.'%(name, termid))
     self.conf.save_term(term, taxname)
     self.conf.save_to_file()
     slog.info('The term %s has saved.'%name)
Exemple #2
0
  def __init__(self, *args, SetAttrFromTermD=False, TermArr=None, WP_Term=None,
                    **kwargs):
    #super().__init__(*args, **kwargs) #= super(xTp.BaseCls, self).method(arg)
    WordPressTerm.__init__(self)
    xTp.BaseCls.__init__(self, *args, **kwargs)

    if SetAttrFromTermD is True:
      TermD = WpC.WB.Wj.TermD
      if self.taxonomy in TermD and self.name in TermD[self.taxonomy]:
        for i,v in enumerate(TermD[self.taxonomy][self.name]):
          setattr(self, WpTermOpAttrs[i], v)
    elif isinstance(WP_Term, WcT.WP_Term):
      for k,v in WP_Term._obj.items():
        if k in TermDbCols:   # if k=='term_id': k='id' #Done in __setattr__
          setattr(self, k, v)
    elif isinstance(TermArr, array):
      for k,v in TermArr.items():
        if k in TermDbCols:   # if k=='term_id': k='id' #Done in __setattr__
          setattr(self, k, v)
    else:
      #try:    L.debug('WordpyTermC: {}', self.id)
      #except: pass
      if getattr(self, 'name', None) is not None:
        self.name = self.name.strip().lower()
      if getattr(self, 'slug', None) is None:
        self.slug = UC.WpySlugify(self.name)
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)
 def create_category(self, category_name, parent_category_id=None):
     category = WordPressTerm()
     category.taxonomy = 'category'
     if parent_category_id != None:
         category.parent = parent_category_id
     category.name = category_name
     category.id = self.client.call(taxonomies.NewTerm(category))
     return 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))
Exemple #6
0
 def get_term(self, taxname, slug):
     if not self[taxname]:
         return None
     if not self[taxname][slug]:
         return None
     termdict = self[taxname][slug]
     term = WordPressTerm()
     term.id = termdict['id']
     term.group = termdict['group']
     term.taxonomy = termdict['taxonomy']
     term.taxonomy_id = termdict['taxonomy_id']
     term.name = termdict['name']
     term.slug = termdict['slug']
     term.description = termdict['description']
     term.parent = termdict['parent']
     term.count = termdict['count']
     return term
def import_terms(taxonomy_name, terms=[]):
    """
    Imports a list of terms provided into a particular taxonomy.  If the term already exists, the import skips it.

    :param taxonomy_name: string of taxonomy name.
    :param terms: list of strings of terms
    :return:
    """
    taxonomy = API.call(GetTaxonomy(taxonomy_name))
    for item in terms:  # raises xmlrpc.client.Fault error if term exists
        try:
            term = WordPressTerm()
            term.taxonomy = taxonomy.name
            term.name = item
            API.call(NewTerm(term))
        except Fault as err:
            print("error inserting %s: %s" % (item, err))
Exemple #8
0
 def _new_term(self):
     if not self.args.query or len(self.args.query) < 1:
         slog.error('Provide 1 arguments at least please.')
         return
     query = self.get_term_query()
     print('query:', query)
     term = self.get_terms_from_wp(query, force=True)
     print(term)
     if term:
         slog.error('The term "%s" has been in wordpress.' %
                    self.args.query[0])
         return
     taxname = query[0]
     slug = self.args.query[0]
     name = self.args.query[1] if len(self.args.query) > 1 else slug
     term = WordPressTerm()
     term.slug = slug
     term.name = name
     term.taxonomy = taxname
     if len(self.args.query) > 2:
         term.description = self.args.query[2]
     termid = self.wpcall(NewTerm(term))
     if not termid:
         return
     term = self.wpcall(GetTerm(taxname, termid))
     if not term:
         return
     slog.info('The term %s(%s) has created.' % (name, termid))
     self.conf.save_term(term, taxname)
     self.conf.save_to_file()
     slog.info('The term %s has saved.' % name)
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 check_rtc_term(self, wp, category):
        from wordpress_xmlrpc.methods.taxonomies import GetTerms        
        categories = wp.call(GetTerms('category'))
        for c in categories:
            if c.name == category:
                sys.stdout.write('## Category %s matches.\n' % category)
                return c
        sys.stdout.write('## Category %s does not match.\n' % category)

        id = 0
        for c in categories:
            if c.name == 'RTComponents':
                id = c.id

        from wordpress_xmlrpc.methods.taxonomies import NewTerm
        from wordpress_xmlrpc import WordPressTerm
        term = WordPressTerm()
        term.name = category
        term.taxonomy = 'category'
        term.parent = id
        
        cat = wp.call(NewTerm(term))

        return cat
Exemple #11
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 #13
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
def testPost(term, poem, numOccur, partSpeech, definition, tags):
    # def testPost(term, poem, numOccur, context, partSpeech, officialDef, tags, etymology, webster1907Def, oedDef, loyUsage, categories):
    from wordpress_xmlrpc import Client
    from wordpress_xmlrpc.methods import posts
    # , taxonomies

    client = Client('http://EXAMPLESITE.com/xmlrpc.php', 'EXAMPLE',
                    ('EXAMPE_PASSWORD'))  #, blog_id=0,transport=None)
    # postList = client.call(posts.GetPosts())
    # print(postList) # == [WordPressPost, WordPressPost, ...]

    from wordpress_xmlrpc import WordPressPost, WordPressTerm

    # tagList = client.call(taxonomies.GetTerms('post_tag'))

    # print("Taglist:", tagList)
    # print()
    # print("TSV Tags:", tags)

    for item in tags:
        # if (item not in tagList):
        tag = WordPressTerm()
        tag.taxonomy = 'post_tag'
        tag.name = ('%a', item)
        # tag.id = client.call(taxonomies.NewTerm(tag))
        # else:
        #     pass

    if (term.lower() in wordFreq):
        numOccur = wordFreq[term.lower()][0]
        # print (numOccur)
    # print(term, poem, numOccur, partSpeech, definition,tags)
    if (not partSpeech):
        pass
    else:
        partSpeech = '(' + partSpeech + ')'

    post = WordPressPost()
    post.title = ('{}'.format(term))
    post.content = ((
        '<strong><span style="color: #993300;">Appears in: </span> </strong>{}<br>'
        .format(poem)
    ) + '<br>' + (
        ' <span style="color: #993300;"><strong>Frequency: </strong></span>{}<br>'
        .format(numOccur)
    ) + '<br>' + (
        ' <strong><span style="color: #993300;">Definition: </span> </strong> <br>{} {}<br>'
        .format(partSpeech, definition))
                    # .format(poem, numOccur, partSpeech, definition)
                    )

    # post.content = (('<h3>Poem:</h3> %a <h3>Number of Occurrences:</h3> %a',
    #     # ' [expand title="Etymology" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand]',
    #     ' [expand title="Definition" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand]')
    #     # ' [expand title="Webster(1907)" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand]',
    #     # ' [expand title="Oxford English Dictionary" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand]',
    #     # ' [expand title="Loy Usage" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand]',
    #      %(poem, numOccur, definition))
    # # [expand title="Merriam-Webster Dictionary (1907)" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand] [expand title="Proposed Definition" rel="entry-highlander" tag="h3" trigclass="noarrow"]%a[/expand] &nbsp;' %(a,b,c,d)
    #                 # )

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

    post.id = client.call(posts.NewPost(post))

    post.post_status = 'publish'
    client.call(posts.EditPost(post.id, post))
Exemple #15
0
 def get_term(self, taxname, slug):
     if not self[taxname]:
         return None
     if not self[taxname][slug]:
         return None
     termdict = self[taxname][slug]
     term = WordPressTerm()
     term.id = termdict['id']
     term.group = termdict['group']
     term.taxonomy = termdict['taxonomy']
     term.taxonomy_id = termdict['taxonomy_id']
     term.name = termdict['name']
     term.slug = termdict['slug']
     term.description = termdict['description']
     term.parent = termdict['parent']
     term.count = termdict['count']
     return term
Exemple #16
0
def main():
    # look for command line arguments
    args = sys.argv[1:]

    if '-h' in args or '--help' in args or '-?' in args:
        helptext()
        sys.exit(0)

    if '-l' in args:
        logging = True
        logfilename = args[args.index('-l') + 1]
        trimlogfile(logfilename)
        logfile = open(logfilename, 'a')
        oldstdout = sys.stdout
        oldstderr = sys.stderr
        logsplit = LogFileSplitter(sys.stdout, logfile)
        sys.stdout = logsplit
        sys.stderr = logsplit
        print('Logging started.')

    if '-c' in args:
        configfile = args[args.index('-c') + 1]
        if not os.path.isfile(configfile):
            print(configfile + ' does not exist, create it? (Y/N):')
            if not raw_input().lower() == 'y':
                print('OK, config file will not be created')
                if logging == True:
                    sys.stdout = oldstdout
                    sys.stderr = oldstderr
                    logfile.close()
                sys.exit(0)
    else:
        configfile = '/etc/ssp_sermon_podcast.xml'

    if ('--config' in args) or not os.path.isfile(configfile):
        edit_config_file(configfile)
        print('Config file created and will be used on next run.')
        if logging:
            sys.stdout = oldstdout
            sys.stderr = oldstderr
            logfile.close()
        sys.exit(0)

    #load the config file
    if os.path.isfile(configfile):
        try:
            configET = ET.parse(configfile)
        except:
            print('Can\'t parse config file ' + configfile)
            sys.exit(1)
        config = configET.getroot()
        if not ((config.tag == 'config') and
                (config.attrib['description']
                 == 'Seriously Simple Podcasting Sermon Podcast settings')):
            print(configfile + ' is not a SSP Sermon Podcast config file.')
            if logging:
                sys.stdout = oldstdout
                sys.stderr = oldstderr
                logfile.close()
            sys.exit(1)

    #get the settings from the config
    settings = config.find('settings')

    #open the wordpress object
    wordpress_url = settings.find('wordpress_url').text
    if wordpress_url.endswith('/'):
        xmlrpc_url = wordpress_url + 'xmlrpc.php'
    else:
        xmlrpc_url = wordpress_url + '/xmlrpc.php'

    wp = Client(xmlrpc_url,
                settings.find('wordpress_user').text,
                decryptpassword(settings.find('wordpress_pass').text))

    #get a list of podcast objects
    allpodcasts = []
    interval = 20
    offset = 0
    while True:
        podcastbatch = wp.call(
            GetPosts({
                'post_type': 'podcast',
                'number': interval,
                'offset': offset
            }))
        if len(podcastbatch) == 0:
            break
        allpodcasts.extend(podcastbatch)
        offset += interval

    print('Retrieved ' + str(len(allpodcasts)) +
          ' podcasts from WordPress site.')

    #get the series settings from the config and find out which series will be podcast
    allseriesconfigs = config.findall('series_config')
    termids_to_podcast = []
    for seriesconfig in allseriesconfigs:
        termids_to_podcast.append(seriesconfig.attrib['term_id'])

    #get a list of series from the blog
    listofseriesterms = []
    interval = 20
    offset = 0
    while True:
        termsbatch = wp.call(
            GetTerms('series', {
                'number': interval,
                'offset': offset
            }))
        if len(termsbatch) == 0:
            break
        listofseriesterms.extend(termsbatch)
        offset += interval

    print('Found ' + str(len(listofseriesterms)) +
          ' podcast series on the WordPress site.')

    #find out the hierarchy of the series so we can do the lowest children first
    termpriority = {}
    term_parents = {}

    for term in listofseriesterms:
        term_parents[term.id] = term.parent
        order = 0
        parentid = term.parent
        while parentid != '0':
            order += 1
            for parentterm in listofseriesterms:
                if parentid == parentterm.id:
                    parentid = parentterm.parent
                    break
        termpriority[term.id] = order

    #so the order to approach term.ids is
    termid_order = []

    for termid, order in sorted(termpriority.iteritems(),
                                key=lambda x: x[1],
                                reverse=True):
        termid_order.append(termid)

    print('This is the order the series terms will be published:')
    print(', '.join(termid_order))

    #find which series config the posts should be published with (if any)
    podcasts_to_do = {}
    extension = extension_dot(settings.findtext('source_audio_type'))
    for termid in termid_order:
        if termid in termids_to_podcast:
            for podcast in allpodcasts:
                #check whether the podcast is flagged to be published and has a date:
                date_recorded = get_post_custom_field(podcast, 'date_recorded')
                if get_post_custom_field(podcast,
                                         'publish_now') and date_recorded:
                    podcast_termids = ['0']
                    for podcastterm in podcast.terms:
                        podcast_termids.append(podcastterm.id)
                    for podcast_termid in podcast_termids:
                        if podcast_termid in term_parents:
                            podcast_termids.append(
                                term_parents[podcast_termid])
                    if termid in podcast_termids and not podcast.id in podcasts_to_do:
                        #work out what the start of the source file name will be:
                        termid_seriesconfig = seriescfg_from_term_id(
                            allseriesconfigs, termid)
                        source_date_format = termid_seriesconfig.find(
                            'source_date_format').text
                        date_recorded_format = settings.find(
                            'date_recorded_format').text
                        sourcefile_name_start = getdatetime(
                            date_recorded, user_format=date_recorded_format
                        ).strftime(
                            source_date_format) + termid_seriesconfig.findtext(
                                'source_file_code', default='')
                        sourcepath = termid_seriesconfig.findtext(
                            'source_path')
                        #and does it exist?
                        directorylist = []
                        if os.path.exists(sourcepath):
                            #this seems to timeout sometimes, so will loop if need be:
                            retrycount = 3
                            while retrycount:
                                try:
                                    directorylist = os.listdir(sourcepath)
                                    retrycount = 0
                                except OSError as errmsg:
                                    print(errmsg)
                                    retrycount -= 1
                                    if retrycount:
                                        print('Retrying directory list...')
                        for filename in directorylist:
                            if filename[:len(sourcefile_name_start
                                             )] == sourcefile_name_start:
                                if extension:
                                    extposn = -len(extension)
                                if filename[
                                        extposn:] == extension or extension == None:
                                    ordered_podcast_termids = []
                                    for termid_again in termid_order:
                                        if termid_again in podcast_termids:
                                            ordered_podcast_termids.append(
                                                termid_again)
                                    ordered_podcast_termids.append('0')
                                    podcasts_to_do[podcast.id] = [
                                        podcast, termid_seriesconfig,
                                        os.path.abspath(
                                            os.path.join(sourcepath,
                                                         filename)),
                                        ordered_podcast_termids
                                    ]

    print('There are ' + str(len(podcasts_to_do)) +
          ' podcasts to process in this pass.')

    if len(podcasts_to_do) != 0:
        listofposttags = []
        interval = 20
        offset = 0
        while True:
            termsbatch = wp.call(
                GetTerms('post_tag', {
                    'number': interval,
                    'offset': offset
                }))
            if len(termsbatch) == 0:
                break
            listofposttags.extend(termsbatch)
            offset += interval
        posttagsdict = {}
        for posttag in listofposttags:
            posttagsdict[posttag.name.lower()] = posttag
        print('Retrieved ' + str(len(posttagsdict)) +
              ' post tags from WordPress site.')

    #iterate over the podcasts
    for podcast_id, podcast_and_config in podcasts_to_do.iteritems():
        #open the audio file
        print('\n')
        print('Now processing file ' + podcast_and_config[2])
        backuppodcast = copy.deepcopy(podcast_and_config[0])
        try:
            sourceaudio = audiotools.open(podcast_and_config[2])
            sourcepcm = sourceaudio.to_pcm()

            #calculate its loudness
            loudness = audiotools.calculate_replay_gain([sourceaudio])
            for loudnesstuple in loudness:
                gain = loudnesstuple[1]
                peak = loudnesstuple[2]
            if peak == 0:
                print('This audio file is silent, ignoring it.')
                continue

            #mix it to the specified number of channels
            gaincorrection = 0
            if settings.findtext('audiochannels') == '1':
                print('Converting to mono.')
                sourcepcm_mixed = audiotools.pcmconverter.Averager(sourcepcm)
            elif settings.findtext('audiochannels') == '2':
                print('Converting to stereo.')
                sourcepcm_mixed = audiotools.pcmconverter.Downmixer(sourcepcm)
                if sourceaudio.channels() == 1:
                    gaincorrection = 6.0
            else:
                sourcepcm_mixed = sourcepcm

            #adjust the gain to the users' preference instead of replaygain's target -20
            target_loudness = float(
                settings.findtext('target_loudness', default='-24'))
            newgain = gain + (target_loudness + 20.0) + gaincorrection
            newpeak = 1.0 / (10.0**(newgain / 20.0))
            if (peak / (10.0**(gaincorrection / 20.0))) > newpeak:
                newpeak = peak / (10.0**(gaincorrection / 20.0))
            print(
                'Normalising for gain: ' + str(round(newgain, 2)) +
                'dB, peak = ' + str(
                    round(
                        (20.0 * log10(peak /
                                      (10.0**(gaincorrection / 20.0)))), 2)) +
                'dBFS.')
            #normalise the audio to the target loudness
            sourcepcm_normalised = audiotools.replaygain.ReplayGainReader(
                sourcepcm_mixed, newgain, newpeak)

            try:
                bitspersample = int(settings.findtext('bitspersample'))
            except:
                bitspersample = None
            if bitspersample:
                print('Quantising to ' + str(bitspersample) + '-bit.')
                sourcepcm_resampled = audiotools.pcmconverter.BPSConverter(
                    sourcepcm_normalised, bitspersample)

            #make some tempfiles:
            process_tempfile = tempfile.mkstemp(
                suffix='.wav', prefix='sermon_process_tempfile')
            processed_tempfile = tempfile.mkstemp(
                suffix='.wav', prefix='sermon_processed_tempfile')
            encoded_tempfile = tempfile.mkstemp(
                suffix=extension_dot(settings.findtext('encoded_audio_type')),
                prefix='sermon_encoded_tempfile')
            print('tempfiles: ' + process_tempfile[1] + ', ' +
                  processed_tempfile[1] + ', ' + encoded_tempfile[1])

            #write the audio back out to a wave file for processing
            audiotools.WaveAudio.from_pcm(process_tempfile[1],
                                          sourcepcm_resampled)

            sourcepcm_normalised.close()
            sourcepcm_mixed.close()
            sourcepcm.close()
            sourceaudio = None

            audioparams = getaudioparams(sourcepcm_resampled)
            sourcepcm_resampled.close()
            subprocess_args = [settings.findtext('processing_utility')]
            for argsubelement in settings.findall('processing_utility_arg'):
                subprocess_args.append(
                    Template(argsubelement.text).substitute(audioparams))
            tempstring = settings.findtext('processing_utility_infile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(process_tempfile[1])
            tempstring = settings.findtext('processing_utility_outfile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(processed_tempfile[1])

            print('Now processing audio ...')

            print(
                subprocess.Popen(subprocess_args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 universal_newlines=True).communicate()[0])
            os.remove(process_tempfile[1])

            processedfile = audiotools.open(processed_tempfile[1])
            audioparams = getaudioparams(processedfile.to_pcm())
            subprocess_args = [settings.findtext('encoding_utility')]
            for argsubelement in settings.findall('encoding_utility_arg'):
                subprocess_args.append(
                    Template(argsubelement.text).substitute(audioparams))
            tempstring = settings.findtext('encoding_utility_infile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(processed_tempfile[1])
            tempstring = settings.findtext('encoding_utility_outfile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(encoded_tempfile[1])

            print('Now encoding audio ...')

            print(
                subprocess.Popen(subprocess_args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 universal_newlines=True).communicate()[0])
            os.remove(processed_tempfile[1])

            wp_details = make_podcast_dict(podcast_and_config, wp, settings)

            wp_details['post_status'] = 'publish'
            wp_details['publish_now'] = ''

            updated_podcast = publish_post(podcast_and_config, wp_details, wp,
                                           settings)
            podcast_and_config[0] = updated_podcast
            updated_details = make_podcast_dict(podcast_and_config,
                                                wp,
                                                settings,
                                                final_pass=True)

            try:
                imageurl = urllib2.urlopen(updated_details['image'])
                podcastimage = imageurl.read()
            except:
                podcastimage = False
            try:
                audioimage = [
                    audiotools.Image.new(podcastimage, u'Artwork', 0)
                ]
            except:
                audioimage = []
            outputmetadata = audiotools.MetaData(
                track_name=updated_details['title'],
                track_number=int(updated_details['episode_number']),
                album_name=updated_details['series'],
                artist_name=updated_details['preacher'],
                copyright=updated_details['copyright'],
                publisher=updated_details['publisher'],
                year=updated_details['date'].strftime('%Y'),
                date=updated_details['date_recorded'],
                comment=updated_details['content'],
                images=audioimage)
            outputfile = audiotools.open(encoded_tempfile[1])
            outputfile.set_metadata(outputmetadata)
            outputfile_seconds = int(outputfile.seconds_length())

            outputfile_name = updated_details[
                'output_file_template'] + extension_dot(
                    settings.findtext('encoded_audio_type'))

            outputfile_size = ftp_encodedfile(encoded_tempfile[1],
                                              outputfile_name,
                                              podcast_and_config[1])
            if outputfile_size == None:
                raise Exception('FTP appears not to have worked.')

            print('\n')
            print('Output file size = ' + str(outputfile_size))
            print('Output file duration = ' + str(outputfile_seconds))
            print('\n')

            os.remove(encoded_tempfile[1])

            urlpath = podcast_and_config[1].findtext('download_path')
            if not urlpath[-1] == '/':
                urlpath = urlpath + '/'
            updated_details['audio_file'] = urlpath + outputfile_name
            updated_details['filesize_raw'] = str(outputfile_size)
            mins = str(outputfile_seconds / 60)
            secs = str(outputfile_seconds % 60)
            if len(secs) == 1:
                secs = '0' + secs
            updated_details['duration'] = mins + ':' + secs

            #put the preacher in as a tag:
            updated_details['tags'] = []
            if updated_details['preacher'].lower() in posttagsdict:
                updated_details['tags'].append(
                    posttagsdict[updated_details['preacher'].lower()])
            else:
                tag = WordPressTerm()
                tag.taxonomy = 'post_tag'
                tag.name = updated_details['preacher']
                tag.id = wp.call(NewTerm(tag))
                updated_details['tags'].append(tag)
                posttagsdict[tag.name.lower()] = tag

            #put the book(s) of the bible in as tags:
            #This bit is really messy and I should try to write my own scripture regular expressions, but in the interest of speed:
            listofpassages = scriptures.extract(
                updated_details['bible_passage'])
            if 'song of songs' in updated_details['bible_passage'].lower():
                listofpassages.append(('Song of Songs', 1, 1, 1, 1))
            for passage in listofpassages:
                book = passage[0]
                if book[:4] == 'III ':
                    bookname = '3 ' + book[4:]
                elif book[:3] == 'II ':
                    bookname = '2 ' + book[3:]
                elif book[:2] == 'I ':
                    bookname = '1 ' + book[2:]
                elif book == 'Song of Solomon':
                    bookname = 'Song of Songs'
                else:
                    bookname = book
                if bookname.lower() in posttagsdict:
                    updated_details['tags'].append(
                        posttagsdict[bookname.lower()])
                else:
                    tag = WordPressTerm()
                    tag.taxonomy = 'post_tag'
                    tag.name = bookname
                    tag.id = wp.call(NewTerm(tag))
                    updated_details['tags'].append(tag)
                    posttagsdict[tag.name.lower()] = tag

            finalpost = publish_post(podcast_and_config, updated_details, wp,
                                     settings)

            print('Final Post details are as follows:\n')

            for field, contents in finalpost.struct.iteritems():
                try:
                    if type(contents) == types.StringType:
                        print(field + ' : ' + contents)
                    elif type(contents) == types.ListType:
                        for subcontents in contents:
                            print(field + ' : ' + str(subcontents))
                    elif type(contents) == types.DictType:
                        for subfield, subcontents in contents.iteritems():
                            print(field + ' : ' + subfield + ' : ' +
                                  str(subcontents))
                    elif type(contents) == types.UnicodeType:
                        print(field + ' : ' +
                              contents.encode('ascii', 'ignore'))
                    else:
                        print(field + ' : ' + str(contents))
                except:
                    print('Can\'t print field')
        except Exception as message:
            print('ERROR: Exception raised while processing that podcast:')
            print(message)
            print(
                'Attempting to restore original post prior to modification...')
            try:
                if wp.call(EditPost(backuppodcast.id, backuppodcast)):
                    print('Post restored.')
                else:
                    print('Unable to restore original post.')
            except Exception as message:
                print('Unable to restore original post: ')
                print(message)
            try:
                os.remove(encoded_tempfile[1])
            except:
                pass
            try:
                os.remove(processed_tempfile[1])
            except:
                pass
            try:
                os.remove(process_tempfile[1])
            except:
                pass

    logsplit.write('Completed with normal exit\n\n\n')
    if logging:
        sys.stdout = oldstdout
        sys.stderr = oldstderr
        logfile.close()
Exemple #17
0
			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))

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

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

			attachment_id = 0
			
			if logo:
			
				print "https://www.mustakbil.com"+str(logo)
Exemple #18
0
with open(filename) as f:
    text = f.read()

# Reading all posts, all tags and the post to tag mapping
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
Exemple #19
0
def new_category(name):
  wp = Client('http://127.0.0.1/xmlrpc.php', 'root', '123456')
  tag = WordPressTerm()
  tag.taxonomy = 'category'  # 这里为category的话插入的是category,为post_tag的话插入的是tag
  tag.name = name
  tag.id = wp.call(taxonomies.NewTerm(tag))
            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))

            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:
Exemple #21
0
def main():
    args = sys.argv[1:]
    if len(args) != 2:
        print(
            'Usage: ./ssp_se_load_roster.py <Wordpress xmlrpc url> <csvfile>')
        sys.exit(1)

    xmlrpc = args[0]
    csvfile_name = args[1]

    if not os.path.isfile(csvfile_name):
        print('I can\'t find the file: ' + csvfile_name)
        sys.exit(1)

    username = raw_input('Enter your WordPress user name: ')
    password = getpass()

    wp = Client(xmlrpc, username, password)

    listofseriesterms = wp.call(GetTerms('series'))

    print('To which series are you going to add all these posts? (id, name)')
    series = {}
    for seriesterm in listofseriesterms:
        print(seriesterm.id + ', ' + seriesterm.name)
        series[seriesterm.id] = seriesterm.name
    main_series_termid = raw_input('Please enter the id: ')

    if not main_series_termid in series:
        print('That series id does not exist')
        sys.exit(1)
    else:
        print(series[main_series_termid] + ' series selected.')

    child_series = {}
    for seriesterm in listofseriesterms:
        if seriesterm.parent == main_series_termid:
            child_series[seriesterm.name.lower()] = seriesterm.id

    print('child_series')
    print(child_series)

    existing_posts = wp.call(GetPosts({
        'post_type': 'podcast',
        'number': 9999
    }))
    existing_series_posts = {}
    child_series_existing_episode_numbers = {}
    for post in existing_posts:
        post_terms = []
        for term in post.terms:
            if term.id in child_series.values(
            ) or term.id == main_series_termid:
                post_terms.append(term.id)
        if post_terms:
            for customfield in post.custom_fields:
                if customfield['key'] == 'date_recorded' and customfield[
                        'value']:
                    date_recorded_string = customfield['value']
                elif customfield['key'] == 'episode_number' and customfield[
                        'value']:
                    for post_term_id in post_terms:
                        if post_term_id in child_series_existing_episode_numbers:
                            child_series_existing_episode_numbers[
                                post_term_id].append(int(customfield['value']))
                        else:
                            child_series_existing_episode_numbers[
                                post_term_id] = [int(customfield['value'])]
            date_recorded = getdatetime(date_recorded_string)
            existing_series_posts[date_recorded] = (post.id, post_terms)

    #open and parse the csv
    replace_all = False
    replace_none = False

    fieldname_translation = {
        'date': 'date_recorded',
        'title': 'title',
        'series': 'series',
        'track': 'episode_number',
        'passage': 'bible_passage',
        'preacher': 'preacher',
        'comments': 'content',
        'time': 'time'
    }

    list_from_csv = {}
    with open(csvfile_name, 'r') as csvfile:
        reader = csv.DictReader(csvfile)
        for messyentry in reader:
            entry = {}
            for entrykey, entryval in messyentry.iteritems():
                entry[fieldname_translation[entrykey.lower()]] = entryval
            if not (('date_recorded' in entry) or ('preacher' in entry)):
                continue
            if entry['date_recorded'] == '' or entry['preacher'] == '':
                continue
            csvdate = getdatetime(entry['date_recorded'])
            if csvdate == None:
                continue
            entry['date_recorded'] = csvdate.strftime('%d-%m-%Y')
            try:
                int(entry['episode_number'])
            except (ValueError, KeyError):
                entry['episode_number'] = ''
            for fieldname in fieldname_translation.values():
                if not fieldname in entry:
                    entry[fieldname] = ''
            if not entry['series']:
                entry['series'] = 'one-off'
            if (csvdate in existing_series_posts):
                if not (replace_none or replace_all):
                    confirmation_raw_in = raw_input(
                        'There is already a podcast in this series with date '
                        + csvdate.strftime('%d %b %Y') +
                        ', replace it? \n(Y/N/All/None)\n').lower()
                elif replace_none:
                    continue
                if confirmation_raw_in == 'none':
                    replace_none = True
                if not confirmation_raw_in in ['y', 'all']:
                    continue
                if confirmation_raw_in == 'all':
                    replace_all = True
                if wp.call(DeletePost(existing_series_posts[csvdate][0])):
                    print('Deleted old post for ' +
                          csvdate.strftime('%d %b %Y') + '.')
            entry['bible_passage'] = cleanUpScripture(entry['bible_passage'])
            list_from_csv[csvdate] = entry

    template_settings = {
        'ep_title_template': 'title',
        'service_time': 'time',
        'comments_template': 'content'
    }

    #work out series and episode_numbers:
    for seriestermid in child_series_existing_episode_numbers:
        try:
            child_series_existing_episode_numbers[seriestermid] = sorted(
                child_series_existing_episode_numbers[seriestermid],
                reverse=True)[0]
        except IndexError as e:
            print(e)
            try:
                child_series_existing_episode_numbers[seriestermid] = int(
                    series[seriestermid].count)
            except:
                child_series_existing_episode_numbers[seriestermid] = 0

    prefix = 'ss_podcasting_data_'
    termidlist = ['0', main_series_termid]
    optionslist = []
    templates_per_series = {}
    for child_series_termid in child_series.values():
        termidlist.append(child_series_termid)
    for termid_item in termidlist:
        templates_per_series[termid_item] = {}
        if termid_item == '0':
            suffix = ''
        else:
            suffix = '_' + termid_item
        for eachsetting in template_settings:
            optionslist.append(prefix + eachsetting + suffix)
    list_of_WPOptions = wp.call(GetOptions(optionslist))
    for wp_Option in list_of_WPOptions:
        if wp_Option.name[len(prefix):] in template_settings:
            templates_per_series['0'][
                wp_Option.name[len(prefix):]] = wp_Option.value
        else:
            for termid_item in termidlist:
                suffix = '_' + termid_item
                if wp_Option.name[-len(suffix):] == suffix:
                    templates_per_series[termid_item][wp_Option.name[
                        len(prefix):-len(suffix)]] = wp_Option.value

    timezone = get_localzone()

    for entry, details in sorted(list_from_csv.iteritems()):
        if not details['series'].lower() in child_series:
            wpseries = WordPressTerm()
            wpseries.taxonomy = 'series'
            wpseries.name = details['series']
            wpseries.parent = main_series_termid
            wpseries.id = wp.call(NewTerm(wpseries))
            child_series[details['series']] = wpseries.id
            listofseriesterms.append(wpseries)
            series[wpseries.id] = wpseries.name
            child_series[wpseries.name.lower()] = wpseries.id
            if details['episode_number'] == '':
                details['episode_number'] = '1'
                child_series_existing_episode_numbers[wpseries.id] = 1
            else:
                child_series_existing_episode_numbers[wpseries.id] = int(
                    details['episode_number'])
            details['seriesid'] = wpseries.id
        else:
            try:
                child_series_existing_episode_numbers[child_series[
                    details['series'].lower()]]
            except KeyError:
                for seriesterm in listofseriesterms:
                    if seriesterm.id == child_series[
                            details['series'].lower()]:
                        child_series_existing_episode_numbers[child_series[
                            details['series'].lower()]] = seriesterm.count
                    else:
                        child_series_existing_episode_numbers[child_series[
                            details['series'].lower()]] = 0
            if details['episode_number'] == '':
                child_series_existing_episode_numbers[child_series[
                    details['series'].lower()]] += 1
                details['episode_number'] = str(
                    child_series_existing_episode_numbers[child_series[
                        details['series'].lower()]])
            else:
                child_series_existing_episode_numbers[child_series[
                    details['series'].lower()]] = int(
                        details['episode_number'])
            details['seriesid'] = child_series[details['series'].lower()]
        for template_setting, detail in template_settings.iteritems():
            list = [details['seriesid'], main_series_termid, '0']
            while details[detail] == '':
                try:
                    details[detail] = templates_per_series[list.pop(
                        0)][template_setting]
                except KeyError:
                    continue
        publishtime = gettime(details['time'])
        if publishtime:
            local_datetime = timezone.localize(
                datetime.combine(entry, publishtime.time()))
            details['post_date_gmt'] = local_datetime.astimezone(pytz.utc)
        newpost = WordPressPost()
        newpost.post_type = 'podcast'
        newpost.title = details['title']
        newpost.date = details['post_date_gmt']
        newpost.post_status = 'draft'
        newpost.content = details['content']
        newpost.terms = [wp.call(GetTerm('series', main_series_termid))]
        if details['seriesid']:
            newpost.terms.append(
                wp.call(GetTerm('series', details['seriesid'])))
        newpost.custom_fields = [{
            'key': 'preacher',
            'value': details['preacher']
        }, {
            'key': 'date_recorded',
            'value': details['date_recorded']
        }, {
            'key': 'bible_passage',
            'value': details['bible_passage']
        }, {
            'key': 'episode_number',
            'value': details['episode_number']
        }, {
            'key': 'publish_now',
            'value': 'on'
        }]
        newpost.id = wp.call(NewPost(newpost))
        if newpost.id:
            print('Created Post ID ' + str(newpost.id) + ' for date: ' +
                  details['date_recorded'])