# Path: redditpoller/models.py
# class WatchedUser(models.Model):
#     user = models.ForeignKey(User)
#     watched_username = models.CharField(max_length=30)
#     submitted_date = models.DateTimeField(default=timezone.now)
#     last_checked_date = models.DateTimeField(default=timezone.now)
#     watch_interval = models.IntegerField(blank=True, null=True)
# 
#     def __str__(self):
#         return self.watched_username
# 
# class WatchedUserComment(models.Model):
#     parent_user = models.ForeignKey(WatchedUser, on_delete=models.CASCADE)
#     url = models.CharField(max_length=500)
#     text = models.CharField(max_length=10000)
# 
#     def __str__(self):
#         return self.url
# 
# class WatchedUserThread(models.Model):
#     parent_user = models.ForeignKey(WatchedUser, on_delete=models.CASCADE)
#     url = models.CharField(max_length=500)
#     title = models.CharField(max_length=500)
#     thread_date = models.CharField(max_length=50)
# 
#     def __str__(self):
#         return self.title
# 
# Path: redditpoller/poller.py
# def get_user_threads(username, fetch_amount):
#     threads = r.redditor(username).submissions.new(limit=fetch_amount)
#     return threads
# 
# def get_user_comments(username, fetch_amount):
#     comments = r.redditor(username).comments.new(limit=fetch_amount)
#     return comments
# 
# def notify_user(redditor, message):
#     r.redditor(redditor).message('Reddit Watcher', message)


from django.core.management import BaseCommand
from django.utils import timezone
from redditpoller.models import WatchedUser, WatchedUserComment, WatchedUserThread
from redditpoller.poller import get_user_threads, get_user_comments, notify_user
from datetime import timedelta
                    else:
                        c = WatchedUserComment(parent_user=user, url=comment.permalink(fast=True),
                                                text=comment.body)
                        c.save()
                        comment_list.append([comment.body, comment.permalink(fast=True)])
                        new_comment_count += 1
                if new_comment_count == 0 and  new_thread_count == 0:
                    pass
                else:
                    formatted_comments = ''
                    # only grab 3 comments as to not reach character limit
                    limit_comments = 3
                    for comment in comment_list:
                        if limit_comments > 0:
                            formatted_comments += '\n\n' + comment[0] + ' - [Link](https://reddit.com{})'.format(
                                comment[1])
                            limit_comments -= 1
                        else:
                            break
                    formatted_thread_titles = ''
                    limit_threads = 3
                    for thr in thread_list:
                        if limit_threads > 0:
                            formatted_thread_titles += '\n\n' + thr[0] + ' - [Link](https://reddit.com{})'.format(
                                thr[1])
                            limit_threads -= 1
                        else:
                            break
                    all_formatted = formatted_thread_titles + formatted_comments
                    username = str(user.user)

# Path: redditpoller/models.py
# class WatchedUser(models.Model):
#     user = models.ForeignKey(User)
#     watched_username = models.CharField(max_length=30)
#     submitted_date = models.DateTimeField(default=timezone.now)
#     last_checked_date = models.DateTimeField(default=timezone.now)
#     watch_interval = models.IntegerField(blank=True, null=True)
# 
#     def __str__(self):
#         return self.watched_username
# 
# class WatchedUserComment(models.Model):
#     parent_user = models.ForeignKey(WatchedUser, on_delete=models.CASCADE)
#     url = models.CharField(max_length=500)
#     text = models.CharField(max_length=10000)
# 
#     def __str__(self):
#         return self.url
# 
# class WatchedUserThread(models.Model):
#     parent_user = models.ForeignKey(WatchedUser, on_delete=models.CASCADE)
#     url = models.CharField(max_length=500)
#     title = models.CharField(max_length=500)
#     thread_date = models.CharField(max_length=50)
# 
#     def __str__(self):
#         return self.title
# 
# Path: redditpoller/poller.py
# def get_user_threads(username, fetch_amount):
#     threads = r.redditor(username).submissions.new(limit=fetch_amount)
#     return threads
# 
# def get_user_comments(username, fetch_amount):
#     comments = r.redditor(username).comments.new(limit=fetch_amount)
#     return comments
# 
# def notify_user(redditor, message):
#     r.redditor(redditor).message('Reddit Watcher', message)


# Path: redditpoller/management/commands/check_watched_users.py
from django.core.management import BaseCommand
from django.utils import timezone
from redditpoller.models import WatchedUser, WatchedUserComment, WatchedUserThread
from redditpoller.poller import get_user_threads, get_user_comments, notify_user
from datetime import timedelta

                    else:
                        c = WatchedUserComment(parent_user=user, url=comment.permalink(fast=True),
                                                text=comment.body)
                        c.save()
                        comment_list.append([comment.body, comment.permalink(fast=True)])
                        new_comment_count += 1
                if new_comment_count == 0 and  new_thread_count == 0:
                    pass
                else:
                    formatted_comments = ''
                    # only grab 3 comments as to not reach character limit
                    limit_comments = 3
                    for comment in comment_list:
                        if limit_comments > 0:
                            formatted_comments += '\n\n' + comment[0] + ' - [Link](https://reddit.com{})'.format(
                                comment[1])
                            limit_comments -= 1
                        else:
                            break
                    formatted_thread_titles = ''
                    limit_threads = 3
                    for thr in thread_list:
                        if limit_threads > 0:
                            formatted_thread_titles += '\n\n' + thr[0] + ' - [Link](https://reddit.com{})'.format(
                                thr[1])
                            limit_threads -= 1
                        else:
                            break
                    all_formatted = formatted_thread_titles + formatted_comments
                    username = str(user.user)

                    notify_user(username,