-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewsfeed.py
60 lines (49 loc) · 1.92 KB
/
newsfeed.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
53
54
55
56
57
58
59
60
# Filename: newfeed.py
# import into another file by using "from newfeed import NewsFeed"
from datetime import datetime
import pandas as pd
from source import Source
from dateutil.parser import *
#=============================================
#= News Feed Class =
#=============================================
class NewsFeed():
#===================================================
#= Variables =
#===================================================
__sourcesList = None
__lastUpdated = None
#==========================================================
#= Public Functions =
#==========================================================
# Constructor
def __init__(self):
self.initSources()
def initSources(self):
self.__sourcesList = []
sourcesDF = pd.read_csv("sources.csv") # Replace With Path to CSV file
for index, row in sourcesDF.iterrows():
csvSource = Source(
row["Name"],
row["Type"],
row["URL"]
)
self.__sourcesList.append(csvSource)
# Updates the source list
def updateSources(self):
for source in self.__sourcesList:
source.updateStories()
# Returns an array of strings that the bot can iterate through to post
def postNews(self):
self.updateSources()
stories = []
date = []
for source in self.__sourcesList:
for story in source.getStoryList():
if self.__lastUpdated == None or parse(story.getDate()) > self.__lastUpdated:
storyString = '\n'.join(story.getAll())
stories.append(storyString)
date.append(parse(story.getDate()))
if len(date) != 0:
self.__lastUpdated = max(date)
return stories