File size: 1,061 Bytes
9575051
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from model.headline import Headline, HeadlineResponse
from model.bulletpoint import BulletPoint
import json

class HeadlinesController:
    def __init__(self):
        headline = self.parseJsonOutput()
        self.headlines = [headline]

    def parseJsonOutput(self):
        with open('controller/output.json', 'r') as file:
            parsed_data = json.load(file)
        
        bulletpoints = []
        for i in range(len(parsed_data)):
            text = parsed_data[i]["text"]
            publishers = parsed_data[i]["publishers"]
            bulletpoint = BulletPoint(i, text, publishers)
            bulletpoints.append(bulletpoint)
        
        return Headline(1, "Sam Altman & OpenAI News", bulletpoints)

    
    def getHeadlines(self) -> HeadlineResponse:
        headlineResponse = HeadlineResponse(self.headlines)
        return headlineResponse
    
    def getHeadlineById(self, id) -> Headline:
        for headline in self.headlines:
            if int(headline.id) == int(id):
                return headline