-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdjango_json2mysql.py
52 lines (44 loc) · 1.78 KB
/
django_json2mysql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# coding:utf-8
import os
from tqdm import tqdm
import json
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SearchEngineEnd.settings")
# Django 版本大于等于1.7的时候,需要加上下面两句
import pandas as pd
import django
if django.VERSION >= (1, 7):#自动判断版本
django.setup()
from database_handled.data_clear import expert_name_clear
def main():
from app_api.models import paper_info
# f = open('./database_handled/get_expert_info.json')
# for line in f:
# data = json.loads(line)
# author_id = list(data.keys())[0]
# content = data[author_id]
# expert_basic_info.objects.create(author_id=author_id,
# expert_name=expert_name_clear(content['expert_name']),
# expert_web_url=content['expert_web_url'],
# expert_image_url=content['expert_image_url'],
# expert_org=content['expert_org'],
# expert_area_list=json.dumps(content['expert_area_list']))
# f.close()
#
# f = open('./database_handled/get_expert_tread_list.json')
# for line in f:
# data = json.loads(line)
# author_id = list(data.keys())[0]
# content = data[author_id]
# expert_trend.objects.create(author_id=author_id, year=json.dumps(content[0]), number=json.dumps(content[1]))
# f.close()
#
f = open('./data/get_paper_list.json')
for line in f:
data = json.loads(line)
author_id = list(data.keys())[0]
content = data[author_id]
paper_info.objects.create(author_id=author_id,paper_list_top10=json.dumps(content))
f.close()
if __name__ == "__main__":
main()
print('Done!')