From e76c94db9c94fd494c223da025967f2031c54305 Mon Sep 17 00:00:00 2001 From: Aaditya Thakur Date: Wed, 1 Feb 2023 23:26:56 +0530 Subject: [PATCH] Progess on bot with python --- .gitignore | 5 ++++- Aaditya/main.py | 28 ++++++++++++++++++++++++++++ Aaditya/scrapper.py | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Aaditya/main.py create mode 100644 Aaditya/scrapper.py diff --git a/.gitignore b/.gitignore index 2eea525..8839965 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.env \ No newline at end of file +.env +node_modules/ +.vscode/ +Aaditya/.env \ No newline at end of file diff --git a/Aaditya/main.py b/Aaditya/main.py new file mode 100644 index 0000000..6c49754 --- /dev/null +++ b/Aaditya/main.py @@ -0,0 +1,28 @@ +import discord + +class Client(discord.Client): + async def on_ready(self): + print("Bot is online!") + + async def on_message(self, message): + if message.author == self.user: + return + if message.content.startswith("!hi"): + await message.channel.send(f"Hi! {message.author.mention}") + elif message.content.startswith("!search"): + x = ' '.join(message.content.split()[1:]) + print(x) #TODO + +def main(): + #only works if command is invoked from the working directory itself + with open(".env", "r") as file: + token = file.readline() + + intent = discord.Intents.default() + intent.message_content = True + + client = Client(intents=intent) + client.run(token) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Aaditya/scrapper.py b/Aaditya/scrapper.py new file mode 100644 index 0000000..aab2d3f --- /dev/null +++ b/Aaditya/scrapper.py @@ -0,0 +1,21 @@ +#adjusting code from ./Adamay/TwitterScrapper_boi.ipynb to use with the bot + +import snscrape.modules.twitter as sntwitter +import pandas as pd + +class Scraper: + def __init__(self): + pass + def scrape(text): + fQuery=text+' min_faves:4000' + data=sntwitter.TwitterSearchScraper(fQuery) + tweets=[] + + for i,tweet in enumerate(data.get_items()): + data1=[tweet.url,tweet.user.username,tweet.rawContent] + tweets.append(data1) + if i>50: + break + + fData=pd.DataFrame(tweets,columns='Link Username Content'.split()) + #TODO \ No newline at end of file