OxbridgeEconomics
commited on
Commit
·
6c8a470
1
Parent(s):
d05c91c
commit
Browse files
utils.py
CHANGED
@@ -183,7 +183,7 @@ def crawl(url, article):
|
|
183 |
article['attachment'] = ""
|
184 |
article['sentimentScore'], article['sentimentLabel'] = sentiment_computation(CONTENT_ENG.replace("\n",""))
|
185 |
article['id'] = uuid.uuid5(uuid.NAMESPACE_OID, article['titleCN']+article['publishDate'])
|
186 |
-
|
187 |
|
188 |
def upsert_content(report):
|
189 |
"""Upsert the content records"""
|
@@ -234,6 +234,38 @@ def delete_records(item):
|
|
234 |
)
|
235 |
|
236 |
def update_content(report):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
dynamodb = get_client_connection()
|
238 |
response = dynamodb.update_item(
|
239 |
TableName="article_test",
|
|
|
183 |
article['attachment'] = ""
|
184 |
article['sentimentScore'], article['sentimentLabel'] = sentiment_computation(CONTENT_ENG.replace("\n",""))
|
185 |
article['id'] = uuid.uuid5(uuid.NAMESPACE_OID, article['titleCN']+article['publishDate'])
|
186 |
+
update_content(article)
|
187 |
|
188 |
def upsert_content(report):
|
189 |
"""Upsert the content records"""
|
|
|
234 |
)
|
235 |
|
236 |
def update_content(report):
|
237 |
+
dynamodb = get_client_connection()
|
238 |
+
response = dynamodb.update_item(
|
239 |
+
TableName="article_test",
|
240 |
+
Key={
|
241 |
+
'id': {'S': report['id']},
|
242 |
+
'site': {'S': report['site']}
|
243 |
+
},
|
244 |
+
UpdateExpression='SET sentimentScore = :sentimentScore, sentimentLabel = :sentimentLabel',
|
245 |
+
ExpressionAttributeValues={
|
246 |
+
'title': report['title'],
|
247 |
+
'titleCN': report['titleCN'],
|
248 |
+
'site': report['site'],
|
249 |
+
'contentCN': report['contentCN'],
|
250 |
+
'category': report['category'],
|
251 |
+
'author': report['author'],
|
252 |
+
'content': report['content'],
|
253 |
+
'subtitle': report['subtitle'],
|
254 |
+
'publishDate': report['publishDate'],
|
255 |
+
'link': report['link'],
|
256 |
+
'attachment': report['attachment'],
|
257 |
+
# 'authorID': str(report['authorid']),
|
258 |
+
# 'entityList': report['entitylist'],
|
259 |
+
'sentimentScore': Decimal(str(report['sentimentScore'])).quantize(Decimal('0.01')),
|
260 |
+
'sentimentLabel': report['sentimentLabel'],
|
261 |
+
'LastModifiedDate': datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
|
262 |
+
# ':sentimentScore': {'N': str(Decimal(str(report['sentimentscore'])).quantize(Decimal('0.01')))},
|
263 |
+
# ':sentimentLabel': {'S': report['sentimentlabel']}
|
264 |
+
}
|
265 |
+
)
|
266 |
+
print(response)
|
267 |
+
|
268 |
+
def update_content_sentiment(report):
|
269 |
dynamodb = get_client_connection()
|
270 |
response = dynamodb.update_item(
|
271 |
TableName="article_test",
|