Beispiel #1
0
    async def m_remove_sub(self, data):
        antispam(self.getip(), "remove_sub", 50)

        if not self.logged_in():
            self.send_data({
                "key": "form_remove_sub",
                "success": False,
                "errors": ["not logged in"]
            })
            return

        sub = data['sub']

        results = SubscribtionModel.select().join(UserModel).where(
            UserModel.id == SubscribtionModel.user_id).where(
                UserModel.username == self.session['username']).where(
                    SubscribtionModel.subreddit == sub).select()

        if len(results) > 0:
            result = results[0]
            SubscribtionModel.delete().where(
                SubscribtionModel.id == result.id).execute()
            self.send_data({"key": "form_remove_sub", "success": True})
        else:
            self.send_data({
                "key": "form_remove_sub",
                "success": False,
                "errors": ["You've already got this one added"]
            })

        await self.send_subs()  # update
Beispiel #2
0
def process_nonpremiums():
    log_info("Process non-premiums")
    database = get_db()
    now = datetime.now()
    #last_valid_date = datetime.now() - timedelta(hours = 24)
    #select = SubscribtionModel.select().join(UserModel).where(UserModel.id == SubscribtionModel.user_id).where(UserModel.activated == True).where(UserModel.last_sent < last_valid_date).where(UserModel.last_hi + timedelta(days=14) < now)

    today_4_00 = get_datetime_today_4_00()
    if now < today_4_00:
        return  # not 4 yet ..

    compare_against = today_4_00 - timedelta(
        hours=22
    )  # so if user received a kindler at 3.59am? dont send another one 2 hours later..
    last_hi_verif = now - timedelta(days=14)
    select = SubscribtionModel.select().join(UserModel).where(
        UserModel.id == SubscribtionModel.user_id).where(
            UserModel.is_recurrent == True).where(
                UserModel.activated == True).where(
                    UserModel.last_sent < compare_against).where(
                        UserModel.last_hi > last_hi_verif).select()

    #print(select)
    #print(list(select))

    process(select)
Beispiel #3
0
    async def m_unsubscribe(self, data):
        antispam(self.getip(), "unsubscribe", 20)

        if not self.logged_in():
            self.send_data({
                "key": "form_unsubscribe",
                "success": False,
                "errors": ["not logged in"]
            })
            return

        kindle_email = data['kindle_email']

        user = UserModel.select().where(UserModel.kindle_email == kindle_email)
        SubscribtionModel.delete().where(
            SubscribtionModel.user == user).execute()

        self.send_data({"key": "form_unsubscribe", "success": True})
Beispiel #4
0
 async def send_subs(
     self
 ):  # this is quite common.. goes for each update when changing the list. so i am gonna increase it from 30 to 100
     antispam(self.getip(), "send_subs", 100)
     if not self.logged_in():
         return
     subs = SubscribtionModel.select().join(UserModel).where(
         UserModel.id == SubscribtionModel.user_id).where(
             UserModel.username == self.session['username'])
     all_subs = []
     for subscribtion in subs.select():
         all_subs += [subscribtion.subreddit]
     self.send_data({"key": "subs_list", "subs": all_subs})
Beispiel #5
0
def process_manuals():
    log_info("Process manuals")
    database = get_db()
    now = datetime.now()

    compare_against = now - timedelta(hours=23, minutes=59)
    last_hi_verif = now - timedelta(days=14)
    select = SubscribtionModel.select().join(UserModel).where(
        UserModel.id == SubscribtionModel.user_id).where(
            UserModel.is_recurrent == False).where(
                UserModel.has_requested == True).where(
                    UserModel.activated == True).where(
                        UserModel.last_sent < compare_against).where(
                            UserModel.last_hi > last_hi_verif).select()

    #print(select)
    #print(list(select))

    process(select)
Beispiel #6
0
    async def m_add_sub(self, data):
        global r

        antispam(self.getip(), "add_subs", 50)

        if not self.logged_in():
            self.send_data({
                "key": "form_add_sub",
                "success": False,
                "errors": ["not logged in"]
            })
            return
        if not await self.enabled():
            self.send_data({
                "key": "form_add_sub",
                "success": False,
                "errors": ["Account not enabled. Go to settings"]
            })
            return
        if not await self.activated():
            self.send_data({
                "key":
                "form_add_sub",
                "success":
                False,
                "errors": ["Account not activated. Go to your email"]
            })
            return

        sub = data['sub']

        if not reddit_exists(r, sub):
            self.send_data({
                "key":
                "form_add_sub",
                "success":
                False,
                "errors": ["Couldnt find subreddit, or it's marked as nsfw"]
            })

        count = await self.count_subs()
        if count > 1:
            self.send_data({
                "key": "form_add_sub",
                "success": False,
                "errors": ["Exceeded your limit of 2 subreddits."]
            })
            return

        results = SubscribtionModel.select().join(UserModel).where(
            UserModel.id == SubscribtionModel.user_id).where(
                UserModel.username == self.session['username']).where(
                    SubscribtionModel.subreddit == sub).select()

        if len(results) == 0:  # doesnt already exist.
            await objects.create(SubscribtionModel,
                                 user=self.session['user'],
                                 subreddit=sub,
                                 per_email=10)
            await self.send_subs()  # update
            self.send_data({"key": "form_add_sub", "success": True})
        else:
            self.send_data({
                "key": "form_add_sub",
                "success": False,
                "errors": ["You've already got this sub added"]
            })
Beispiel #7
0
    async def count_subs(self):
        subs = SubscribtionModel.select().join(UserModel).where(
            UserModel.id == SubscribtionModel.user_id).where(
                UserModel.username == self.session['username'])

        return len(subs.select())