Esempio n. 1
0
def main():
    if len(argv) != 2:
        print("Invalid arguments.")
        exit(1)
    elif argv[1] == "publish":
        pub = Publisher()
        pub.start()
    elif argv[1] == "listen":
        lis = Listener()
        lis.start()
    else:
        print("Invalid argument.")
Esempio n. 2
0
    def publish():
        # get all available collections and tiles from the database
        df_collections = db_connection.select_from_collections()
        df_tiles = db_connection.select_from_tiles()

        # `dict(request.args)`` returns the query string as a dict
        publisher_app = Publisher(PR_BASE_DIR,
                                  df_collections,
                                  df_tiles,
                                  query=dict(request.args))
        # execute main method
        publisher_app.main()
        return '/publish has been executed'
 def __init__(self, settings, client_id, timeout, auto_commit, logger):
     self._settings = settings
     self._logger = logger
     self._consumer = ConsumerHandler(self._settings, client_id, timeout,
                                      auto_commit)
     self._database_handler = MessageHandler(self._settings, self._logger)
     self._publisher = Publisher(self._settings)
Esempio n. 4
0
 def __init__(self, bootstrap_servers, group_id, client_id, timeout,
              auto_commit, org_name, config):
     self._config = config
     self._user_utils = UserUtils(self._config)
     self._org = Organization(org_name, self._user_utils)
     self._consumer = ConsumerHandler(bootstrap_servers, group_id,
                                      client_id, timeout, auto_commit,
                                      config)
     self._database_handler = DataBaseHandler(
         self._config.DATABASE_LOCATION, self._org, self._user_utils,
         self._config)
     self._publisher = Publisher(self._config.CONNECTOR_PUBLISH_API_URL)
import logging
import os
from publisher.publisher import Publisher

if __name__ == "__main__":
    for handler in logging.root.handlers[:]:
        logging.root.removeHandler(handler)

    logging.basicConfig(
        level=logging.INFO,
        filename=os.path.join(os.getcwd(), 'logs', 'publisher.log'),
        filemode='w',
        format='%(asctime)s - %(module)s - %(lineno)d - %(levelname)s - %(message)s')

    publisher = Publisher()
    publisher.purge(all_sensors=True)

    result = publisher.get_all()  # list of tuples i.e. (sensors name, list of dictionaries)
    result.sort(key=lambda x: len(x[1]), reverse=True)  # sensor with least number of posts comes 1st

    balanced_list = []
    pos, step = 0, 1
    for tup in result:
        for p in tup[1]:  # list of dictionaries newest 1st
            balanced_list.insert(pos, (tup[0], p))
            pos += step
        pos, step = step, step + 1

    for tup in balanced_list[::-1]:
        publisher.publish(tup[0], **tup[1])
Esempio n. 6
0
from handlers.files import FilesHandler
from publisher.publisher import Publisher

# Set logging level for Tornado Server
tornado.log.access_log.setLevel(DEBUG)

# Define default variables and objects
DATA_PATH = Path("data")
FILES_HANDLER = FilesHandler()
RABBIT_MQ_HOST = environ.get("RABBITMQ_HOST") or "localhost"

print(f"Use {RABBIT_MQ_HOST} as RabbitMQ host")

# Create Publisher connection
try:
    PUBLISHER = Publisher(host=RABBIT_MQ_HOST)
    print(f"Connected to RabbitMQ")
except:
    print("RabbitMQ currently unavailable, {action}".format(
        action="exit" if RABBIT_MQ_HOST ==
        "localhost" else "trying to reconnect..."))
    exit(1)
# Also create Database manager connection
try:
    DB_MANAGER = DbManager()
    print(f"Connected to Postgres")
except:
    print("Postgres currently unavailable, {action}".format(
        action="exit" if RABBIT_MQ_HOST ==
        "localhost" else "trying to reconnect..."))
    exit(1)
Esempio n. 7
0
def test_happy_path():
    rds_client = boto3.client('rds')
    error_detail = Publisher('tests/config_files/happy.ini',
                             rds_client).publish()
    assert error_detail
import logging
import os
from publisher.publisher import Publisher

if __name__ == "__main__":
    for handler in logging.root.handlers[:]:
        logging.root.removeHandler(handler)

    logging.basicConfig(
        level=logging.INFO,
        filename=os.path.join(os.getcwd(), 'logs', 'publisher.log'),
        filemode='w',
        format=
        '%(asctime)s - %(module)s - %(lineno)d - %(levelname)s - %(message)s')

    publisher = Publisher()
    publisher.purge(all_sensors=True)

    result = publisher.get_all(
    )  # list of tuples i.e. (sensors name, list of dictionaries)
    result.sort(key=lambda x: len(x[1]),
                reverse=True)  # sensor with least number of posts comes 1st

    balanced_list = []
    pos, step = 0, 1
    for tup in result:
        for p in tup[1]:  # list of dictionaries newest 1st
            balanced_list.insert(pos, (tup[0], p))
            pos += step
        pos, step = step, step + 1
Esempio n. 9
0
#!/usr/bin/env python3

from publisher.publisher import Publisher

if __name__ == "__main__":
    url_list = [
        "http://www.tsu.ru/upload/medialibrary/22d/pobeda75.jpg",
        "http://www.tsu.ru/upload/resize_cache/iblock/4e7/320_213_2/0m8a8521_drugtsu_cam520.jpg",
    ]
    publisher = Publisher()
    for _ in range(10):
        print(publisher.publish_task(url_list))