summaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools/workers/worker_common.py
blob: 77ea2c1566477586a6a4caec482c966856e1cef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

import re
import sys
import csv
import json
import itertools
import fatcat_client
from pykafka import KafkaClient
from fatcat_client.rest import ApiException


class FatcatWorker:
    """
    Common code for for Kafka producers and consumers.
    """

    def __init__(self, kafka_hosts, produce_topic=None, consume_topic=None, api_host_url=None):
        if api_host_url:
            conf = fatcat_client.Configuration()
            conf.host = api_host_url
            self.api = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf))
        self.kafka = KafkaClient(hosts=kafka_hosts, broker_version="1.0.0")
        self.produce_topic = produce_topic
        self.consume_topic = consume_topic