Browse Source

Add files via upload

master
Unbewohnte 4 years ago committed by GitHub
parent
commit
ea1972c41c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      authentication.py
  2. 48
      functions.py
  3. 57
      main.py

22
authentication.py

@ -0,0 +1,22 @@
import praw
##### REDDIT
reddit = praw.Reddit(client_id='YourId',
client_secret = 'YourSecret' ,
username ='YourUsername' ,
password = 'YourPassword',
user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36')
#Check the praw documentation if you have questions (You get these (exept user agent) when you create an app whithin a Reddit)
# reddit.com/prefs/apps/
#####
#####DISCORD
TOKEN = 'YOUR TOKEN'#You can find it when the bot application created here: discord.com/developers/applications
#####

48
functions.py

@ -0,0 +1,48 @@
import praw
import urllib
from urllib import request,parse
url_opn_list = []
headers = {}
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36'
def reddit_parse_hot(reddit, sub , many):
loop = 0
what_to_parse = reddit.subreddit(sub)
hot_posts = what_to_parse.hot(limit = many)
for post in hot_posts:
post_url = post.url
print(post_url)
req = request.Request(post_url, headers = headers)
url_opn = request.urlopen(req)
url_opn_list.append(post_url)
loop += 1
return url_opn_list
def reddit_parse_time(reddit, sub, many):
loop = 0
what_to_parse = reddit.subreddit(sub)
time_posts = what_to_parse.new(limit = many)
for post in time_posts:
post_url = post.url
print(post_url)
req = request.Request(post_url, headers = headers)
url_opn = request.urlopen(req)
url_opn_list.append(post_url)
loop += 1
return url_opn_list
def random_subreddit(reddit,many):
loop = 0
what_to_parse = reddit.subreddit('random')
hot_posts = what_to_parse.hot(limit = many)
for post in hot_posts:
post_url = post.url
print(post_url)
req = request.Request(post_url, headers = headers)
url_opn = request.urlopen(req)
url_opn_list.append(post_url)
loop += 1
return url_opn_list, what_to_parse

57
main.py

@ -0,0 +1,57 @@
from authentication import TOKEN, reddit
import discord
from discord.ext import commands
from functions import *
client = commands.Bot(command_prefix = '#')
@client.event
async def on_ready():
print('=======================================================')
print(' READY ')
print('=======================================================')
await client.change_presence(activity = discord.Game('game'))
#You can delete this ↑↑↑ line if you don`t want your bot to have an activity showing
@client.command()
async def parse_hot(ctx, subreddit , how_many = 5):
await ctx.send('Okay, the subreddit is : r/{}; I`ll show you {} posts in hot'.format(str(subreddit), str(how_many)))
url_opn_list.clear()
try:
reddit_parse_hot(reddit,str(subreddit),int(how_many))
for url in url_opn_list:
await ctx.send(url)
except Exception as error:
await ctx.send('Error : '+ str(error)+ '\n')
@client.command()
async def parse_time(ctx, subreddit, how_many = 5):
await ctx.send('Okay, the subreddit is : r/{}; I`ll show you {} posts based on time'.format(str(subreddit), str(how_many)))
url_opn_list.clear()
try:
reddit_parse_time(reddit,str(subreddit),int(how_many))
for url in url_opn_list:
await ctx.send(url)
except Exception as error:
await ctx.send('Error : '+ str(error)+ '\n')
@client.command()
async def check(ctx):
await ctx.send(' ```css' +'\n'+ '[Online]' + '\n'+ '```')
@client.command()
async def random(ctx,how_many = 5):
url_opn_list.clear()
try:
what_to_parse = random_subreddit(reddit,int(how_many))[1]
await ctx.send('Aaaand... The subreddit is: r/{}. I`ll show you {} posts in hot'.format(str(what_to_parse),str(how_many)))
for url in url_opn_list:
await ctx.send(url)
except Exception as error:
await ctx.send('Error : '+ str(error)+ '\n')
client.run(TOKEN)
Loading…
Cancel
Save