Exemplo n.º 1
0
def _restore(smartapis):
    if indices.exists():
        logging.error("Cannot write to an existing index.")
        return
    indices.reset()
    for smartapi in smartapis:
        logging.info(smartapi["url"])
        _smartapi = SmartAPI(smartapi["url"])
        _smartapi.username = smartapi["username"]
        _smartapi.slug = smartapi["slug"]
        _smartapi.date_created = datetime.fromisoformat(
            smartapi["date_created"])
        _smartapi.last_updated = datetime.fromisoformat(
            smartapi["last_updated"])
        _smartapi.raw = smartapi["raw"].encode()  # to bytes
        _smartapi.save()
Exemplo n.º 2
0
def migrate():

    for doc in scan(Elasticsearch(ES_ORIGIN),
                    query={"query": {
                        "match_all": {}
                    }},
                    index="smartapi_oas3",
                    doc_type="api"):
        print(doc["_id"])
        if not doc['_source']['_meta'].get('_archived'):
            url = doc['_source']['_meta']['url']
            raw = decoder.decompress(
                base64.urlsafe_b64decode(doc['_source']['~raw']))

            smartapi = SmartAPI(url)
            smartapi.raw = raw
            smartapi.date_created = parser.parse(
                doc['_source']['_meta']['timestamp']).replace(
                    tzinfo=timezone.utc)
            smartapi.username = doc['_source']['_meta']['github_username']
            smartapi.slug = doc['_source']['_meta'].get('slug')
            smartapi.save()
    print()