Skip to content

Commit

Permalink
Merge pull request #8 from aadi-1024/config
Browse files Browse the repository at this point in the history
Config
  • Loading branch information
aadi-1024 authored Feb 10, 2023
2 parents ea064d1 + aa05b1d commit f8ed28a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Aaditya/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
likes=50000
num=1
17 changes: 17 additions & 0 deletions Aaditya/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Config:
def __init__(self, filename):
self.configpath = filename
self.config = {}
with open(self.configpath, "r") as file:
for i in file.readlines():
i = i.split("=")
self.config[i[0]] = i[1].strip()

def update(self, key, value):
self.config[key] = value
with open(self.configpath, 'w') as file:
for i, j in self.config.items():
file.write(f'{i}={j}\n')

def val(self, key):
return self.config[key]
21 changes: 20 additions & 1 deletion Aaditya/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import discord
from scrapper import Scraper
from config import Config

class Client(discord.Client):

async def on_ready(self):
print("Bot is online!")
self.scraper = Scraper()
self.config = Config('config')

async def on_message(self, message):
if message.author == self.user:
Expand All @@ -19,7 +21,7 @@ async def on_message(self, message):
await message.channel.send(f"Looking up twitter for {x}")

try:
data = self.scraper.scrape(x, 5)
data = self.scraper.scrape(x, int(self.config.val('num')), self.config.val('likes'))
except:
await message.channel.send(f"Couldn't find anything about {x} on twitter")
return
Expand All @@ -32,6 +34,23 @@ async def on_message(self, message):

await message.channel.send(embed=discord.Embed(color=discord.Colour.blurple(), title=x, description=desc))

elif message.content.startswith('!setlikes'):
try:
x = int(message.content.split()[1])
self.config.update('likes', x)
await message.channel.send(f"Done! Minimum likes set to {x}")
except:
await message.channel.send("Please enter an integer value")

elif message.content.startswith('!setnum'):
try:

x = int(message.content.split()[1])
self.config.update('num', x)
await message.channel.send(f"Done! Number of entries set to {x}")
except:
await message.channel.send("Please enter an integer value")

def main():
#only works if command is invoked from the working directory itself
with open(".env", "r") as file:
Expand Down
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):
fQuery=text+' min_faves:4000'
def scrape(self, text, num, likes):
fQuery=text+f' min_faves:{likes}'
data=sntwitter.TwitterSearchScraper(fQuery)
tweets=[]

Expand Down

0 comments on commit f8ed28a

Please sign in to comment.