-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (27 loc) · 891 Bytes
/
main.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
import util.NewsScraper as NS
import util.ChatGPTService as GPT
import util.TwitterService as TS
##GLOBALS##
newsURL = 'https://www.cnn.com/'
maxSummaryLength = 700
maxTweetLength = 280
def main ():
#scrape news site for top article body
url,headline = NS.getBreakingNewsArticle(newsURL)
summary = NS.getArticleSummary(url)
#keep string length short enough
if(len(summary)>maxSummaryLength):
summary = summary[:700]
#create joke with article body using chatgpt
joke = GPT.getChatGPTResponse(summary)
print (joke)
##handle length issues since chatgpt is unpredictable
if len(joke) > maxTweetLength:
print('joke is too long!!')
joke1= joke[:maxTweetLength]
joke2 = joke[maxTweetLength:]
TS.postTweet(joke2)
TS.postTweet(joke1)
else:
TS.postTweet(joke)
main()