Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit a3f0709

Browse files
committed
feat: response incrVo field from country api
1 parent 1dacac1 commit a3f0709

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ncovapi/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Meta:
4242
verbose_name = '统计数据'
4343
verbose_name_plural = '统计数据'
4444

45+
4546
class Notice(models.Model):
4647

4748
remarks = ListCharField(
@@ -58,6 +59,7 @@ class Meta:
5859
verbose_name = '注意信息'
5960
verbose_name_plural = '注意信息'
6061

62+
6163
class WHOArticle(models.Model):
6264

6365
title = models.CharField(max_length=100)
@@ -72,6 +74,7 @@ class Meta:
7274
verbose_name = 'WHO 文章'
7375
verbose_name_plural = 'WHO 文章'
7476

77+
7578
class Recommend(models.Model):
7679

7780
CONTENT_TYPES = [
@@ -108,6 +111,7 @@ class Meta:
108111
verbose_name = '防护知识'
109112
verbose_name_plural = '防护知识'
110113

114+
111115
class Timeline(models.Model):
112116

113117
pubDate = models.IntegerField()
@@ -125,6 +129,7 @@ class Meta:
125129
verbose_name = '时间线事件'
126130
verbose_name_plural = '时间线事件'
127131

132+
128133
class Wiki(models.Model):
129134

130135
title = models.CharField(max_length=100)
@@ -140,6 +145,7 @@ class Meta:
140145
verbose_name = 'Wiki'
141146
verbose_name_plural = 'Wiki'
142147

148+
143149
class GoodsGuide(models.Model):
144150

145151
title = models.CharField(max_length=100)
@@ -156,6 +162,7 @@ class Meta:
156162
verbose_name = '购物指南'
157163
verbose_name_plural = '购物指南'
158164

165+
159166
class Rumor(models.Model):
160167

161168
title = models.CharField(max_length=100)
@@ -174,6 +181,7 @@ class Meta:
174181
verbose_name = '辟谣与防护'
175182
verbose_name_plural = '辟谣与防护'
176183

184+
177185
class Province(models.Model):
178186

179187
locationId = models.IntegerField()

ncovapi/serializers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from .models import City, Province, Country
22
from rest_framework import serializers
33

4+
import json
5+
46

57
class StatisticsGroupSerializer(serializers.Serializer):
68

@@ -119,10 +121,18 @@ class Meta:
119121

120122
class CountrySerializer(serializers.HyperlinkedModelSerializer):
121123

124+
def to_representation(self, inst):
125+
data = super().to_representation(inst)
126+
incrVo = data.get('incrVo')
127+
print(incrVo)
128+
if incrVo:
129+
data['incrVo'] = json.loads(incrVo)
130+
return data
131+
122132
class Meta:
123133
model = Country
124134
fields = [
125135
'continents', 'countryShortCode', 'countryName',
126136
'countryFullName', 'currentConfirmedCount', 'confirmedCount',
127-
'suspectedCount', 'curedCount', 'deadCount'
137+
'suspectedCount', 'curedCount', 'deadCount', 'incrVo'
128138
]

spider/nCoV/spiders/dxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @Author: zhanglei3
33
# @Date: 2020-04-08 09:08:13
44
# @Last Modified by: leafcoder
5-
# @Last Modified time: 2020-04-27 21:05:52
5+
# @Last Modified time: 2020-04-29 13:51:25
66

77
"""丁香园数据源"""
88

@@ -71,6 +71,7 @@ def parse(self, response):
7171
country.pop('provinceId')
7272
country.pop('provinceName')
7373
country.pop('provinceShortName')
74+
country['incrVo'] = json.dumps(country['incrVo'])
7475
yield items.CountryItem(**country)
7576

7677
# 时间线事件,id=“getTimelineService2” 为英文内容

0 commit comments

Comments
 (0)