Skip to content
Extraits de code Groupes Projets
Valider ee791cd2 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Debugging. Still need to find why it always send subreddit image

corresponding of first asked subreddit after launch
parent fd14fa4c
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -31,6 +31,12 @@ class Entry: ...@@ -31,6 +31,12 @@ class Entry:
client_secret=SECRET, \ client_secret=SECRET, \
user_agent=REDDIT_AGENT).subreddit(subName) user_agent=REDDIT_AGENT).subreddit(subName)
hot_subreddit = self.subreddit.hot(limit=500) hot_subreddit = self.subreddit.hot(limit=500)
self.name = name
self.subName = subName
subreddits['kumiko'] = Entry('kumiko', 'rarekumikos')
subreddits['araragi'] = Entry('araragi', 'araragi')
subreddits['hitagi'] = Entry('hitagi', 'Senjougahara')
...@@ -42,23 +48,23 @@ def refresh_posts(entry): ...@@ -42,23 +48,23 @@ def refresh_posts(entry):
entry.posturls.clear() entry.posturls.clear()
entry.totalimgs=0 entry.totalimgs=0
i=0 i=0
for submission in entry.subreddit.hot(limit=500): for submission in entry.subreddit.hot(limit=100):
#_ = os.system('clear') #_ = os.system('clear')
i = i + 1 i = i + 1
totalimgs = totalimgs + 1 entry.totalimgs = entry.totalimgs + 1
print('Getting submission number '+ str(i) +' / 500!') print('Getting submission number '+ str(i) +' / 500!')
if ".jpg" not in submission.url and ".png" not in submission.url: if ".jpg" not in submission.url and ".png" not in submission.url:
print('Post is not a jpg or png --------------------------') print('Post is not a jpg or png --------------------------')
print(str(submission.url)) print(str(submission.url))
totalimgs = totalimgs - 1 entry.totalimgs = entry.totalimgs - 1
continue continue
entry.posts.append(submission.url) entry.posts.append(submission.url)
entry.authors.append(submission.author) entry.authors.append(submission.author)
entry.posturls.append(submission.permalink) entry.posturls.append(submission.permalink)
print('Total amount of images: '+str(totalimgs)) print('Total amount of images: '+str(entry.totalimgs))
def refresh_all_posts(): def refresh_all_posts():
for entry in subreddits: for entry in subreddits.values():
refresh_posts(entry) refresh_posts(entry)
...@@ -82,17 +88,21 @@ async def on_message(message): ...@@ -82,17 +88,21 @@ async def on_message(message):
if message.author == client.user: if message.author == client.user:
return return
if "show me a" in message.content.lower(): if "show me a" in message.content.lower():
name = re.search(r"show me a ([\S]+)", message) name = re.search(r"show me a ([\S]+)", message.content.lower())
if name == None: if name == None:
return return
else: else:
name = name.group(1) name = name.group(1)
if name in subreddits: if name in subreddits.keys():
print('asking for the following entry:')
print(name)
print(subreddits[name].name)
print(subreddits[name].subName)
postnumber = random.randint(1,subreddits[name].totalimgs) postnumber = random.randint(1,subreddits[name].totalimgs)
await message.channel.send(embed = create_embed(subreddits[name].posts[postnumber], subreddits[name].authors[postnumber], subreddits[name].posturls[postnumber])) await message.channel.send(embed = create_embed(subreddits[name].posts[postnumber], subreddits[name].authors[postnumber], subreddits[name].posturls[postnumber]))
if "refresh the kumikos" in message.content.lower(): #if "refresh the kumikos" in message.content.lower():
refresh_all_posts() # refresh_all_posts()
client.run(TOKEN) client.run(TOKEN)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter