File size: 1,758 Bytes
214d268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from decimal import Decimal
from utils import translate, sentiment_computation, get_db_connection
from datetime import datetime
import uuid

# User input for the article content
article_titleCN = input("Enter the title of the article: ")
article_contentCN = input("Paste the article content (CN version) here: ")
article_content = input("Paste the content of the article (EN version) here: ")
article_subtitle = input("Enter the subtitle of the article: ")
article_publish_date = input("Enter the publish date of the article (YYYY-MM-DD): ")
article_link = input("Enter the link to the article: ")
article_siteCN = input("Enter the site of the article: ")


# Compute sentiment of the translated content
sentiment_score, sentiment_label = sentiment_computation(article_contentCN)

# Construct the article dictionary for database insertion
article= {
    'id':  str(uuid.uuid5(uuid.NAMESPACE_OID, article_titleCN + article_publish_date)),
    'site': translate(article_siteCN),
    'title': translate(article_titleCN),
    'titleCN': article_titleCN,
    'contentCN': article_contentCN,
    'category': "Knowledge Center",
    'author': '',
    'content': article_content,
    'subtitle': article_subtitle,
    'publishDate': article_publish_date,
    'link': article_link,
    'attachment': '',
    # 'authorID': str(report['authorid']),
    # 'entityList': report['entitylist'],
    'sentimentScore': Decimal(str(sentiment_score)).quantize(Decimal('0.01')),
    'sentimentLabel': sentiment_label,
    'LastModifiedDate': datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
}

# Insert or update the article in the database
dynamodb = get_db_connection()
table = dynamodb.Table('article_test')
response = table.put_item(Item=article)
print(article)
print(response)