Skip to content

Commit

Permalink
Merge pull request #5 from aadi-1024/main
Browse files Browse the repository at this point in the history
Sends an embed with 5 entries instead of the csv file itself.
  • Loading branch information
aadi-1024 authored Feb 1, 2023
2 parents 9a8fe21 + 2946311 commit 66c9569
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 11 additions & 2 deletions Aaditya/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ 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}")

elif message.content.startswith("!search"):
x = ' '.join(message.content.split()[1:])
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))

data = self.scraper.scrape(x, 5)
desc = ""

for content, link in data.items():
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))

def main():
#only works if command is invoked from the working directory itself
Expand Down
11 changes: 6 additions & 5 deletions Aaditya/scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
class Scraper:
def __init__(self):
pass
def scrape(self, text):
def scrape(self, text, num):
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:
if i>num:
break

fData=pd.DataFrame(tweets,columns='Link Username Content'.split())
csvFile=text+'.csv'
fData.to_csv(csvFile,index=False)
return csvFile
data = {}
for i in range(num):
data[fData.at[i, 'Content']] = fData.at[i, 'Link']
return data

0 comments on commit 66c9569

Please sign in to comment.