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

Moving subreddits lists in .csv. Moving post limit in .env

parent 592c6398
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
.env .env
subreddits.csv
...@@ -3,6 +3,7 @@ import os ...@@ -3,6 +3,7 @@ import os
import praw import praw
import random import random
import re import re
import csv
from dotenv import load_dotenv from dotenv import load_dotenv
...@@ -13,6 +14,8 @@ SECRET = os.getenv('REDDIT_SECRET') ...@@ -13,6 +14,8 @@ SECRET = os.getenv('REDDIT_SECRET')
REDDIT_ID = os.getenv('REDDIT_ID') REDDIT_ID = os.getenv('REDDIT_ID')
REDDIT_AGENT = os.getenv('REDDIT_AGENT') REDDIT_AGENT = os.getenv('REDDIT_AGENT')
postLimit = int(os.getenv('POST_LIMIT'))
subreddits = dict() subreddits = dict()
class Entry: class Entry:
...@@ -28,11 +31,11 @@ class Entry: ...@@ -28,11 +31,11 @@ class Entry:
self.posturls = [] self.posturls = []
self.totalimgs = 0 self.totalimgs = 0
subreddits['kumiko'] = Entry('kumiko', 'rarekumikos')
#subreddits['araragi'] = Entry('araragi', 'araragi')
subreddits['hitagi'] = Entry('hitagi', 'Senjougahara')
with open('subreddits.csv', mode ='r') as file:
csvFile = csv.reader(file)
for lines in csvFile:
subreddits[lines[0]] = Entry(lines[0], lines[1])
def refresh_posts(entry): def refresh_posts(entry):
...@@ -42,11 +45,11 @@ def refresh_posts(entry): ...@@ -42,11 +45,11 @@ 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=50): for submission in entry.subreddit.hot(limit=postLimit):
#_ = os.system('clear') #_ = os.system('clear')
i = i + 1 i = i + 1
entry.totalimgs = entry.totalimgs + 1 entry.totalimgs = entry.totalimgs + 1
print('Getting submission number '+ str(i) +' / 500!') print('Getting submission number '+ str(i) + ' / ' + str(postLimit) + '!')
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))
...@@ -88,7 +91,7 @@ async def on_message(message): ...@@ -88,7 +91,7 @@ async def on_message(message):
mess += "```" mess += "```"
await message.channel.send(mess) await message.channel.send(mess)
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.content.lower()) name = re.search(r"show me an? ([\S]+)", message.content.lower())
if name == None: if name == None:
return return
else: else:
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter