Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 10dec00

Browse files
author
PokestarFan
committed
New file naming system
1 parent d726198 commit 10dec00

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

duplicate.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import datetime
1+
from datetime import datetime as time
22
import logging
33
import praw
44
import prawcore
55
import sys
66
from login import reddit
77

88

9-
file_handler = logging.FileHandler(filename='duplicates.log')
9+
file_handler = logging.FileHandler(filename='duplicates_{}.log'.format(time.now().strftime('%m_%d_%y')))
1010
stdout_handler = logging.StreamHandler(sys.stdout)
1111
handlers = [file_handler, stdout_handler]
1212

1313
logging.basicConfig(
14-
level=logging.DEBUG,
14+
level=logging.INFO,
1515
format='[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s',
1616
handlers=handlers
1717
)
@@ -37,22 +37,27 @@ def action():
3737
dup_sub = praw.models.Submission(reddit, id = duplicate)
3838
if 'ImagesOf' not in str(dup_sub.subreddit) and 'auto' not in str(dup_sub.subreddit):
3939
time = dup_sub.created
40-
time = str(datetime.datetime.fromtimestamp(time))
40+
time = str(time.fromtimestamp(time))
4141
author = str(dup_sub.author)
4242
if str(submission.author) == author:
4343
author = author + '[author of both threads]'
44-
duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author})
44+
duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author, 'karma': str(dup_sub.score)})
4545
if len(duplicates) > 0:
4646
message = 'Here is a list of threads in other subreddits about the same content:\n'
4747
for dup in duplicates:
48-
message = str(message + '\n * [{}]({}) on /r/{} (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['time'], dup['author'])
48+
message = str(message + '\n * [{}]({}) on /r/{} with {} karma (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['karma'],dup['time'], dup['author'])
4949
message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)'
5050
try:
5151
submission.reply(message)
5252
logger.info('Message posted on {}'.format(sub_id))
53+
logger.debug('Message: {}'.format(message))
5354
message = ''
54-
except(praw.exceptions.APIException, UnboundLocalError):
55+
except(praw.exceptions.APIException, UnboundLocalError)as e:
5556
logger.info('Submission {} has been skipped due to missing text'.format(sub_id))
57+
try:
58+
logger.debug('Message: {}'.format(message))
59+
except:
60+
logger.debug('Message output for exception ')
5661
message = ''
5762
except(prawcore.exceptions.Forbidden):
5863
logger.info('You are blocked on /r/{}'.format(str(submission.subreddit)))

0 commit comments

Comments
 (0)