diff --git a/Aaditya/config b/Aaditya/config index 6d9cb06..537984b 100644 --- a/Aaditya/config +++ b/Aaditya/config @@ -1,2 +1,4 @@ likes=50000 num=1 +sdate=2022-02-01 +ldate=2022-02-18 diff --git a/Aaditya/main.py b/Aaditya/main.py index 204df2c..5b3fe65 100644 --- a/Aaditya/main.py +++ b/Aaditya/main.py @@ -2,6 +2,7 @@ from scrapper import Scraper from config import Config + class Client(discord.Client): async def on_ready(self): @@ -12,7 +13,7 @@ async def on_ready(self): 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}") @@ -21,15 +22,17 @@ async def on_message(self, message): await message.channel.send(f"Looking up twitter for {x}") try: - data = self.scraper.scrape(x, int(self.config.val('num')), self.config.val('likes')) + data = self.scraper.scrape(x, int(self.config.val('num')), self.config.val( + 'likes'), self.config.val('ldate'), self.config.val('sdate')) except: await message.channel.send(f"Couldn't find anything about {x} on twitter") return - + desc = "" for content, link in data.items(): - content = content[:30] + '...' if len(content) > 30 else content + content = content[:30] + \ + '...' if len(content) > 30 else content desc += f"- [{content}]({link})\n\n" await message.channel.send(embed=discord.Embed(color=discord.Colour.blurple(), title=x, description=desc)) @@ -51,16 +54,27 @@ async def on_message(self, message): except: await message.channel.send("Please enter an integer value") + elif message.content.startswith('!sdate'): + x = message.content.split()[1] + self.config.update('sdate', x) + await message.channel.send(f"Done! Only Tweets made after {x} will be shown") + + elif message.content.startswith('!ldate'): + x = message.content.split()[1] + self.config.update('ldate', x) + await message.channel.send(f"Done! Only Tweets made before {x} will be shown") + def main(): - #only works if command is invoked from the working directory itself - with open(".env", "r") as file: + # 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 + main() diff --git a/Aaditya/scrapper.py b/Aaditya/scrapper.py index 1946bfc..4212036 100644 --- a/Aaditya/scrapper.py +++ b/Aaditya/scrapper.py @@ -6,8 +6,8 @@ class Scraper: def __init__(self): pass - def scrape(self, text, num, likes): - fQuery=text+f' min_faves:{likes}' + def scrape(self, text, num, likes, ldate, sdate): + fQuery=fQuery="{} min_faves:{} until:{} since:{}".format(text, likes,ldate,sdate) data=sntwitter.TwitterSearchScraper(fQuery) tweets=[]