From d9877a93be97c4d250215b382c43382b12c780c4 Mon Sep 17 00:00:00 2001 From: Aaditya Thakur Date: Thu, 2 Feb 2023 01:10:41 +0530 Subject: [PATCH] WIP implementation --- .gitignore | 3 ++- Aaditya/main.py | 7 ++++++- Aaditya/scrapper.py | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8839965..74796db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env node_modules/ .vscode/ -Aaditya/.env \ No newline at end of file +Aaditya/.env +*/__pycache__ \ No newline at end of file diff --git a/Aaditya/main.py b/Aaditya/main.py index 6c49754..8a55d48 100644 --- a/Aaditya/main.py +++ b/Aaditya/main.py @@ -1,8 +1,11 @@ import discord +from scrapper import Scraper class Client(discord.Client): + async def on_ready(self): print("Bot is online!") + self.scraper = Scraper() async def on_message(self, message): if message.author == self.user: @@ -11,7 +14,9 @@ async def on_message(self, message): await message.channel.send(f"Hi! {message.author.mention}") elif message.content.startswith("!search"): x = ' '.join(message.content.split()[1:]) - print(x) #TODO + await message.channel.send(f"Looking up twitter for {x}") + file = self.scraper.scrape(x) + await message.channel.send(file=discord.File(fp=file, spoiler=False)) def main(): #only works if command is invoked from the working directory itself diff --git a/Aaditya/scrapper.py b/Aaditya/scrapper.py index aab2d3f..2a4267d 100644 --- a/Aaditya/scrapper.py +++ b/Aaditya/scrapper.py @@ -6,7 +6,7 @@ class Scraper: def __init__(self): pass - def scrape(text): + def scrape(self, text): fQuery=text+' min_faves:4000' data=sntwitter.TwitterSearchScraper(fQuery) tweets=[] @@ -18,4 +18,6 @@ def scrape(text): break fData=pd.DataFrame(tweets,columns='Link Username Content'.split()) - #TODO \ No newline at end of file + csvFile=text+'.csv' + fData.to_csv(csvFile,index=False) + return csvFile