record the topic data to the file
961178
def record(file_path, topic_names=[], host=jps.env.get_master_host(), sub_port=jps.DEFAULT_SUB_PORT):
    '''
    '''
    class TopicRecorder(object):

        def __init__(self, file_path, topic_names):
            self._topic_names = topic_names
            self._file_path = file_path
            self._output = open(self._file_path, 'w')
            signal.signal(signal.SIGINT, self._handle_signal)
            signal.signal(signal.SIGTERM, self._handle_signal)
            header = {}
            header['topic_names'] = topic_names
            header['start_date'] = str(datetime.datetime.today())
            header_string = json.dumps({'header': header})
            tail_removed_header = header_string[0:-1]
            self._output.write(tail_removed_header + ',\n')
            self._output.write(' "data": [\n')
            self._has_no_data = True

        def callback(self, msg, topic):
            if self._output.closed:
                return
            raw_msg = '{topic} {msg}'.format(topic=topic, msg=msg)
            if not self._topic_names or topic in self._topic_names:
                if not self._has_no_data:
                    self._output.write(',\n')
                else:
                    self._has_no_data = False
                self._output.write(json.dumps([time.time(), raw_msg]))

        def close(self):
            if not self._output.closed:
                self._output.write('\n]}')
                self._output.close()

        def _handle_signal(self, signum, frame):
            self.close()
            sys.exit(0)

    writer = TopicRecorder(file_path, topic_names)
    sub = jps.Subscriber('*', writer.callback, host=host, sub_port=sub_port)
    sub.spin()
    writer.close()
1001014
def topic(self, channel, topic=None):
        """"""
        if topic:
            channel += ' :' + topic
        self.send_line('TOPIC %s' % channel)
563630
def loadTopicPageFromFile(self, fname):
        
        assert os.path.exists(fname)
        f = open(fname, "r", encoding="utf-8")
        self.topicPage = json.load(f)
458414
def __write_record(self, record_type, data):
    """"""
    length = len(data)

    crc = crc32c.crc_update(crc32c.CRC_INIT, [record_type])
    crc = crc32c.crc_update(crc, data)
    crc = crc32c.crc_finalize(crc)

    self.__writer.write(
        struct.pack(_HEADER_FORMAT, _mask_crc(crc), length, record_type))
    self.__writer.write(data)
    self.__position += _HEADER_LENGTH + length
1308078
def record(self):
        # type: () -> bytes
        '''
        
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Section Header not yet initialized')

        outlist = [struct.pack(self.FMT, self.header_indicator,
                               self.platform_id, self.num_section_entries,
                               self.id_string)]

        for entry in self.section_entries:
            outlist.append(entry.record())

        return b''.join(outlist)
819050
def fh_to_record(self, f):
        """"""

        fn_path = self.file_name
        fr = self.record
        fr.path = fn_path

        fr.update_contents(f.read(), 'text/plain')

        fr.source_hash = self.fs_hash
        fr.synced_fs = self.fs_modtime
        fr.modified = self.fs_modtime
1218924
def _dump(self):
        
        return {
            "topic": self.topic,
            "headers": self._headers,
            "id": self.id,
            "body": self.body,
            "queue": self.queue,
        }
682809
def save_to_file(self, data, stamp):
        
        self.datafile.append(self.current_dataset_name, data)
        # save stimulu info
        info = dict(self._stimulus.componentDoc().items() + self._stimulus.testDoc().items())
        print 'saving doc', info
        info['time_stamps'] = [stamp]
        info['samplerate_ad'] = self.player.aifs
        self.datafile.append_trace_info(self.current_dataset_name, info)
267081
def write_screen_name_to_topics(filepath, user_label_matrix, node_to_id, id_to_name, label_to_lemma, lemma_to_keyword, separator=","):
    
    user_label_matrix = spsp.coo_matrix(user_label_matrix)

    shape = user_label_matrix.shape
    nnz = user_label_matrix.getnnz()

    row = user_label_matrix.row
    col = user_label_matrix.col
    data = user_label_matrix.data

    name_to_topic_set = defaultdict(set)

    for edge in range(row.size):
        node = row[edge]
        user_twitter_id = node_to_id[node]
        name = id_to_name[user_twitter_id]

        label = col[edge]
        lemma = label_to_lemma[label]
        # topic = lemma_to_keyword[lemma]

        name_to_topic_set[name].add(lemma)

    with open(filepath, "w") as f:
        # Write metadata.
        file_row = "n_rows:" + separator + str(shape[0]) + separator +\
                   "nnz:" + separator + str(nnz) + separator +\
                   "\n"
        f.write(file_row)

        for name, topic_set in name_to_topic_set.items():
            file_row = list()
            file_row.append(name)
            file_row.extend(topic_set)
            file_row = separator.join(file_row) + "\n"
            f.write(file_row)
765782
def tombstone_topic(self, topic, node):
        """"""
        nsq.assert_valid_topic_name(topic)
        return self._request('POST', '/topic/tombstone',
                             fields={'topic': topic, 'node': node})
14013
function serializeTopics(topics) {
    return topics.map(function (topic) {
        if (typeof (topic) === 'string') {
            return topic;
        }
        else if (Array.isArray(topic)) {
            topic.forEach(function (topic) {
                if (topic !== null && bytes_1.hexDataLength(topic) !== 32) {
                    errors.throwError('invalid topic', errors.INVALID_ARGUMENT, { argument: 'topic', value: topic });
                }
            });
            return topic.join(',');
        }
        else if (topic === null) {
            return '';
        }
        return errors.throwError('invalid topic value', errors.INVALID_ARGUMENT, { argument: 'topic', value: topic });
    }).join('&');
}
965325
def save_to_file(self,
                     file_path,
                     labels=None,
                     predict_proba=True,
                     show_predicted_value=True,
                     **kwargs):
        
        file_ = open(file_path, 'w', encoding='utf8')
        file_.write(self.as_html(labels=labels,
                                 predict_proba=predict_proba,
                                 show_predicted_value=show_predicted_value,
                                 **kwargs))
        file_.close()
804960
private void generateStumpTopic(final Element topicref) {
        final URI result = getResultFile(topicref);
        final URI temp = tempFileNameScheme.generateTempFileName(result);
        final URI absTemp = job.tempDir.toURI().resolve(temp);

        final String name = getBaseName(new File(result).getName());
        String navtitle = getChildElementValueOfTopicmeta(topicref, TOPIC_NAVTITLE);
        if (navtitle == null) {
            navtitle = getValue(topicref, ATTRIBUTE_NAME_NAVTITLE);
        }
        final String shortDesc = getChildElementValueOfTopicmeta(topicref, MAP_SHORTDESC);

        writeChunk(absTemp, name, navtitle, shortDesc);

        // update current element's @href value
        final URI relativePath = getRelativePath(currentFile.resolve(FILE_NAME_STUB_DITAMAP), absTemp);
        topicref.setAttribute(ATTRIBUTE_NAME_HREF, relativePath.toString());
        if (MAPGROUP_D_TOPICGROUP.matches(topicref)) {
            topicref.setAttribute(ATTRIBUTE_NAME_CLASS, MAP_TOPICREF.toString());
        }

        final URI relativeToBase = getRelativePath(job.tempDirURI.resolve("dummy"), absTemp);
        final FileInfo fi = new FileInfo.Builder()
                .uri(temp)
                .result(result)
                .format(ATTR_FORMAT_VALUE_DITA)
                .build();
        job.add(fi);
    }
816088
def save(filename)
      speech = bytes_wav
      res = IO.popen(lame_command(filename, command_options), 'r+') do |process|
        process.write(speech)
        process.close_write
        process.read
      end
      res.to_s
    end
1336188
def save_history(self):
        """"""
        open(self.LOG_PATH, 'w').write("\n".join( \
                [to_text_string(self.pydocbrowser.url_combo.itemText(index))
                 for index in range(self.pydocbrowser.url_combo.count())]))
1063457
def write_record(self, record, now):
        """"""
        self.write_name(record.name)
        self.write_short(record.type)
        if record.unique and self.multicast:
            self.write_short(record.clazz | _CLASS_UNIQUE)
        else:
            self.write_short(record.clazz)
        if now == 0:
            self.write_int(record.ttl)
        else:
            self.write_int(record.get_remaining_ttl(now))
        index = len(self.data)
        # Adjust size for the short we will write before this record
        #
        self.size += 2
        record.write(self)
        self.size -= 2

        length = len(b''.join(self.data[index:]))
        self.insert_short(index, length)
1312529
public <K, V> void produce(String topic, KafkaProducer<K, V> producer, Map<K, V> data) {
        data.forEach((k, v) -> producer.send(new ProducerRecord<>(topic, k, v)));
        producer.flush();
    }