Skip to content

Commit

Permalink
Merge pull request #9 from aadi-1024/main
Browse files Browse the repository at this point in the history
Added dates to config
  • Loading branch information
aadi-1024 authored Feb 19, 2023
2 parents f8ed28a + d10bbec commit 336d12a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Aaditya/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
likes=50000
num=1
sdate=2022-02-01
ldate=2022-02-18
32 changes: 23 additions & 9 deletions Aaditya/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from scrapper import Scraper
from config import Config


class Client(discord.Client):

async def on_ready(self):
Expand All @@ -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}")

Expand All @@ -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))
Expand All @@ -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()
main()
4 changes: 2 additions & 2 deletions Aaditya/scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[]

Expand Down

0 comments on commit 336d12a

Please sign in to comment.