You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ponymail.apache.org by GitBox <gi...@apache.org> on 2018/05/09 09:48:42 UTC

[GitHub] dimidd commented on issue #447: Import from a local json file

dimidd commented on issue #447: Import from a local json file
URL: https://github.com/apache/incubator-ponymail/issues/447#issuecomment-387685478
 
 
   I've thought about something like this, but not sure how to set the list id.
   
   ```import sys
   import os
   import configparser
   import argparse
   import json
   from elasticsearch import Elasticsearch, helpers
   
   
   # Fetch config
   path = os.path.dirname(os.path.realpath(__file__))
   config = configparser.RawConfigParser()
   config.read("%s/ponymail.cfg" % path)
   auth = None
   if config.has_option('elasticsearch', 'user'):
       auth = (config.get('elasticsearch','user'), config.get('elasticsearch','password'))
   dbname = config.get("elasticsearch", "dbname")
   ssl = config.get("elasticsearch", "ssl", fallback = "False").lower() == 'true'
   uri = config.get("elasticsearch", "uri", fallback = "")
   
   es = Elasticsearch(
           [{
               'host': config.get("elasticsearch", "hostname"),
               'port': int(config.get("elasticsearch", "port")),
               'use_ssl': ssl,
               'url_prefix': uri,
               'http_auth': auth
            }],
           max_retries=5,
           retry_on_timeout=True
       )
   json_path = sys.argv[1]
   with open(json_path, "r") as json_file:
       json = json.load(json_file)
       helpers.bulk(es, json)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services