-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
124 lines (87 loc) · 3.68 KB
/
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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import requests
from newsapi import NewsApiClient
from random import choice,sample
import discord
from discord.ext import tasks,commands
def news_tech():
query_params = {"source": "the-verge",
"sortBy": "top",
"apiKey": "INSERT UR API KEY" #goto newsapi website for more info
}
main_url = " https://newsapi.org/v1/articles"
res = requests.get(main_url, params=query_params)
open_page = res.json()
# getting all articles in a string article
article = open_page["articles"]
# empty list which will
# contain all trending news
results = []
tech_news=[]
for ar in article:
results.append('__By: '+str(ar['author'])+'__'+'\n'+'**'+str(ar["title"])+'**'+'\n'+'_'+str(ar['description'])+'_'+'\n'+str(ar['url']))
for i in range(len(results)):
tech_news.append(results[i])
return choice(tech_news)
def news_bbc():
query_params = {"source": "bbc-news",
"sortBy": "top",
"apiKey": "INSERT UR API KEY"
}
main_url = " https://newsapi.org/v1/articles"
res = requests.get(main_url, params=query_params)
open_page = res.json()
# getting all articles in a string article
article = open_page["articles"]
# empty list which will
# contain all trending news
results = []
bbc_news=[]
for ar in article:
results.append('__By: '+str(ar['author'])+'__'+'\n'+'**'+str(ar["title"])+'**'+'\n'+'_'+str(ar['description'])+'_'+'\n'+str(ar['url']))
for i in range(len(results)):
bbc_news.append(results[i])
return choice(bbc_news)
def news_ign():
query_params = {"source": "ign",
"sortBy": "top",
"apiKey": "INSERT UR API KEY"
}
main_url = " https://newsapi.org/v1/articles"
res = requests.get(main_url, params=query_params)
open_page = res.json()
# getting all articles in a string article
article = open_page["articles"]
# empty list which will
# contain all trending news
results = []
an_news=[]
for ar in article:
results.append('__By: '+str(ar['author'])+'__'+'\n'+'**'+str(ar["title"])+'**'+'\n'+'_'+str(ar['description'])+'_'+'\n'+str(ar['url']))
for i in range(len(results)):
an_news.append(results[i])
return choice(an_news)
client=discord.Client()
@client.event
async def on_ready():
print('Loaded')
activity = discord.Game(name="@news-bot", type=3)
await client.change_presence(status=discord.Status.idle, activity=activity)
key1=r'\news-tech'
key2=r'\news-bbc'
key3=r'\news-ign'
@client.event
async def on_message(message):
if message.content==key1:
await message.channel.send(news_tech())
if message.content==key2:
await message.channel.send(news_bbc())
if message.content==key3:
await message.channel.send(news_ign())
if client.user.mentioned_in(message):
a=r'\news-tech'
b=r'\news-bbc'
c=r'\news-ign'
embedVar = discord.Embed(title=f"Thanks for using News-Bot\n--------------------------------\nThis Bot is currently under-development.\nBot Commands: \n{a}\n{b}\n{c}", color=0x00ff00)
embedVar.set_footer(text='Please Support us.')
await message.channel.send(embed=embedVar)
client.run(ADD YOUR DISCORD BOT TOKEN HERE) #goto discord dev applications to initialize a bot