示例#1
0
def init_app_data():
    old_apps = App.objects.all()
    path = os.path.join(settings.BASE_DIR, 'utils', 'app.yaml')
    with open(path, 'r', encoding='utf-8') as f:
        apps = json.load(f)
        published = apps['published']
        for item in published:
            item = item['app']
            #生成唯一id
            src = item['category'] + item['application']
            appid = hashlib.md5(src.encoding('utf8')).hexdigest()

            if len(old_apps.filter(appid=appid)) == 1:
                print('already exist,appid:', appid)
                app = old_apps.get(appid=appid)
            else:
                print('not exist,creare appid:', appid)
                app = App()
            app.appid = appid
            app.category = item['category']
            app.application = item['application']
            app.name = item['name']
            app.publish_date = item['publish_date']
            app.url = item['url']
            app.desc = item['desc']
            app.save()
示例#2
0
def init_app_data():
    old_apps = App.objects.all()
    path = os.path.join(settings.BASE_DIR, 'app.yaml')
    with open(path, 'r', encoding='utf-8') as f:
        apps = yaml.load(f)
        published = apps.get('published')
        for item in published:
            item = item.get('app')
            # 生成唯一id
            src = item.get('category') + item.get('application')
            appid = hashlib.md5(src.encode('utf8')).hexdigest()
            # 存在更新 不存在新建
            if len(old_apps.filter(appid=appid)) == 1:
                print('already exist, appid:', appid)
                app = old_apps.filter(appid=appid)[0]
            else:
                app = App()
                print('not exist, appid:', appid)
            app.appid = appid
            app.name = item.get('name')
            app.application = item.get('application')
            app.url = item.get('url')
            app.publish_date = item.get('publish_date')
            app.category = item.get('category')
            app.desc = item.get('desc')
            app.save()