Skip to content

Commit

Permalink
Config system works now
Browse files Browse the repository at this point in the history
  • Loading branch information
aadi-1024 committed Feb 10, 2023
1 parent 03706b8 commit aa05b1d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
5 changes: 2 additions & 3 deletions Aaditya/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
likes=6000
true=false
hotel=trivago
likes=50000
num=1
4 changes: 2 additions & 2 deletions Aaditya/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def update(self, key, value):
for i, j in self.config.items():
file.write(f'{i}={j}\n')

def show(self):
print(self.config)
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 aa05b1d

Please sign in to comment.