-
Notifications
You must be signed in to change notification settings - Fork 1
/
vbox7videogetter.py
49 lines (40 loc) · 1.68 KB
/
vbox7videogetter.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
import discord
from discord.ext import commands, tasks
import requests as rq
import os
#from bs4 import BeautifulSoup
bot = commands.Bot(command_prefix='fyou',intents=discord.Intents.all())
DISCORD_TOKEN = "bot_token"
VBOX7_USERNAME = "kris22bg"
CHANNEL_ID =
videos = dict()
@tasks.loop(seconds=10)
async def post_new_videos():
await bot.wait_until_ready()
channel = bot.get_channel(CHANNEL_ID)
if channel:
global videos
if os.path.exists(VBOX7_USERNAME+".txt"):
os.remove(VBOX7_USERNAME+".txt")
html_text = rq.get(f'https://www.vbox7.com/user:{VBOX7_USERNAME}').text
with open(VBOX7_USERNAME+".txt", 'wt') as f:
f.write(html_text)
f.close()
lines = [l for l in open(VBOX7_USERNAME+".txt", 'rt')]
for ind, line in enumerate(lines):
if "card video-cell " in line:
filtered = lines[ind+1].split('"')
video_title = filtered[3]
video_link = "https://www.vbox7.com"+filtered[1]
if video_title not in videos.keys():
videos[video_title] = video_link
emb = discord.Embed(colour=discord.Colour.gold())
emb.set_author(name=VBOX7_USERNAME+" has new video!")
emb.add_field(name=video_title, value=video_link)
emb.set_footer(text='Vbox7 '+VBOX7_USERNAME+' videos!')
await channel.send(embed=emb)
@bot.event
async def on_ready():
post_new_videos.start()
print(f'Logged in as {bot.user.name}')
bot.run(DISCORD_TOKEN)