导入firebase云数据库案例

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import redis
import json
import time


# Use a service account
cred = credentials.Certificate('/home/shanghaimei/work/contents-9ab37-firebase-adminsdk-hopy8-318be1f4ab.json')
firebase_admin.initialize_app(cred)

r = redis.StrictRedis('localhost',6379,decode_responses=True)
key = r.keys()[1]
for value in r.sscan_iter('ICO'):
    startup_name = json.loads(value).get('startup_name')
    start_end_ico = json.loads(value).get('start_end_ico')
    hype_score = json.loads(value).get('hype_score')
    risk_score = json.loads(value).get('risk_score')
    raised= json.loads(value).get('raised')
    goal = json.loads(value).get('goal')
    # name = json.loads(value).get('name')
    share_link = json.loads(value).get('share_link')
    # ico_date = json.loads(value).get('ico_date')
    industry = json.loads(value).get('industry')
    description = json.loads(value).get('description')
    features = json.loads(value).get('features')
    # technical_details = json.loads(value).get('technical_details')
    product_type = json.loads(value).get('product_type')
    website = json.loads(value).get('website')
    db = firestore.client()
    time.sleep(2)

    doc_ref = db.collection(key).document(startup_name)
    doc_ref.set({
        u'startup_name': startup_name,#后面是for循环取出来的字段
        u'start_end_ico':start_end_ico,
        u'hype_score':hype_score,
        u'risk_score':risk_score,
        u'raised':raised,
        u'goal':goal,
        # u'name':name,
        u'share_link':share_link,
        # u'ico_date':ico_date,
        u'industry':industry,
        u'description':description,
        u'features':features,
        # u'technical_details':technical_details,
        u'product_type':product_type,
        u'website':website
    })

你可能感兴趣的:(导入firebase云数据库案例)